print_job_worker_owner.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__
  5. #define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__
  6. #include <memory>
  7. #include "base/location.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "printing/printing_context.h"
  10. namespace base {
  11. class MessageLoop;
  12. class SequencedTaskRunner;
  13. } // namespace base
  14. namespace printing {
  15. class PrintJobWorker;
  16. class PrintSettings;
  17. class PrintJobWorkerOwner
  18. : public base::RefCountedThreadSafe<PrintJobWorkerOwner> {
  19. public:
  20. PrintJobWorkerOwner();
  21. // Finishes the initialization began by PrintJobWorker::GetSettings().
  22. // Creates a new PrintedDocument if necessary. Solely meant to be called by
  23. // PrintJobWorker.
  24. virtual void GetSettingsDone(const PrintSettings& new_settings,
  25. PrintingContext::Result result) = 0;
  26. // Detach the PrintJobWorker associated to this object.
  27. virtual std::unique_ptr<PrintJobWorker> DetachWorker(
  28. PrintJobWorkerOwner* new_owner) = 0;
  29. // Access the current settings.
  30. virtual const PrintSettings& settings() const = 0;
  31. // Cookie uniquely identifying the PrintedDocument and/or loaded settings.
  32. virtual int cookie() const = 0;
  33. // Returns true if the current thread is a thread on which a task
  34. // may be run, and false if no task will be run on the current
  35. // thread.
  36. bool RunsTasksInCurrentSequence() const;
  37. // Posts the given task to be run.
  38. bool PostTask(const base::Location& from_here, const base::Closure& task);
  39. protected:
  40. friend class base::RefCountedThreadSafe<PrintJobWorkerOwner>;
  41. virtual ~PrintJobWorkerOwner();
  42. // Task runner reference. Used to send notifications in the right
  43. // thread.
  44. scoped_refptr<base::SequencedTaskRunner> task_runner_;
  45. };
  46. } // namespace printing
  47. #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__