Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / printing / print_job_manager.h
blob22c72bb06b4f6574c4121f94b7352cbcca56f80d
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_
8 #include <set>
9 #include <vector>
11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
19 namespace printing {
21 class JobEventDetails;
22 class PrintJob;
23 class PrinterQuery;
25 class PrintQueriesQueue : public base::RefCountedThreadSafe<PrintQueriesQueue> {
26 public:
27 PrintQueriesQueue();
29 // Queues a semi-initialized worker thread. Can be called from any thread.
30 // Current use case is queuing from the I/O thread.
31 // TODO(maruel): Have them vanish after a timeout (~5 minutes?)
32 void QueuePrinterQuery(PrinterQuery* job);
34 // Pops a queued PrintJobWorkerOwner object that was previously queued or
35 // create new one. Can be called from any thread.
36 scoped_refptr<PrinterQuery> PopPrinterQuery(int document_cookie);
38 // Creates new query.
39 scoped_refptr<PrinterQuery> CreatePrinterQuery(int render_process_id,
40 int render_view_id);
42 void Shutdown();
44 private:
45 friend class base::RefCountedThreadSafe<PrintQueriesQueue>;
46 typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries;
48 virtual ~PrintQueriesQueue();
50 // Used to serialize access to queued_workers_.
51 base::Lock lock_;
53 PrinterQueries queued_queries_;
55 DISALLOW_COPY_AND_ASSIGN(PrintQueriesQueue);
58 class PrintJobManager : public content::NotificationObserver {
59 public:
60 PrintJobManager();
61 ~PrintJobManager() override;
63 // On browser quit, we should wait to have the print job finished.
64 void Shutdown();
66 // content::NotificationObserver
67 void Observe(int type,
68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) override;
71 // Returns queries queue. Never returns NULL. Must be called on Browser UI
72 // Thread. Reference could be stored and used from any thread.
73 scoped_refptr<PrintQueriesQueue> queue();
75 private:
76 typedef std::set<scoped_refptr<PrintJob> > PrintJobs;
78 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
79 void OnPrintJobEvent(PrintJob* print_job,
80 const JobEventDetails& event_details);
82 // Stops all printing jobs. If wait_for_finish is true, tries to give jobs
83 // a chance to complete before stopping them.
84 void StopJobs(bool wait_for_finish);
86 content::NotificationRegistrar registrar_;
88 // Current print jobs that are active.
89 PrintJobs current_jobs_;
91 scoped_refptr<PrintQueriesQueue> queue_;
93 bool is_shutdown_;
95 DISALLOW_COPY_AND_ASSIGN(PrintJobManager);
98 } // namespace printing
100 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_