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_
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"
21 class JobEventDetails
;
25 class PrintQueriesQueue
: public base::RefCountedThreadSafe
<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
);
39 scoped_refptr
<PrinterQuery
> CreatePrinterQuery(int render_process_id
,
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_.
53 PrinterQueries queued_queries_
;
55 DISALLOW_COPY_AND_ASSIGN(PrintQueriesQueue
);
58 class PrintJobManager
: public content::NotificationObserver
{
61 ~PrintJobManager() override
;
63 // On browser quit, we should wait to have the print job finished.
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();
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_
;
95 DISALLOW_COPY_AND_ASSIGN(PrintJobManager
);
98 } // namespace printing
100 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_