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/synchronization/lock.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "printing/print_destination_interface.h"
21 class JobEventDetails
;
25 class PrintQueriesQueue
: public base::RefCountedThreadSafe
<PrintQueriesQueue
> {
29 // Sets the print destination to be set on the next print job.
30 void SetDestination(PrintDestinationInterface
* destination
);
32 // Queues a semi-initialized worker thread. Can be called from any thread.
33 // Current use case is queuing from the I/O thread.
34 // TODO(maruel): Have them vanish after a timeout (~5 minutes?)
35 void QueuePrinterQuery(PrinterQuery
* job
);
37 // Pops a queued PrintJobWorkerOwner object that was previously queued or
38 // create new one. Can be called from any thread.
39 scoped_refptr
<PrinterQuery
> PopPrinterQuery(int document_cookie
);
42 scoped_refptr
<PrinterQuery
> CreatePrinterQuery();
47 friend class base::RefCountedThreadSafe
<PrintQueriesQueue
>;
48 typedef std::vector
<scoped_refptr
<PrinterQuery
> > PrinterQueries
;
50 virtual ~PrintQueriesQueue();
52 // Used to serialize access to queued_workers_.
55 PrinterQueries queued_queries_
;
57 scoped_refptr
<PrintDestinationInterface
> destination_
;
59 DISALLOW_COPY_AND_ASSIGN(PrintQueriesQueue
);
62 class PrintJobManager
: public content::NotificationObserver
{
65 virtual ~PrintJobManager();
67 // On browser quit, we should wait to have the print job finished.
70 // content::NotificationObserver
71 virtual void Observe(int type
,
72 const content::NotificationSource
& source
,
73 const content::NotificationDetails
& details
) OVERRIDE
;
75 // Returns queries queue. Never returns NULL. Must be called on Browser UI
76 // Thread. Reference could be stored and used from any thread.
77 scoped_refptr
<PrintQueriesQueue
> queue();
80 typedef std::set
<scoped_refptr
<PrintJob
> > PrintJobs
;
82 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
83 void OnPrintJobEvent(PrintJob
* print_job
,
84 const JobEventDetails
& event_details
);
86 // Stops all printing jobs. If wait_for_finish is true, tries to give jobs
87 // a chance to complete before stopping them.
88 void StopJobs(bool wait_for_finish
);
90 content::NotificationRegistrar registrar_
;
92 // Current print jobs that are active.
93 PrintJobs current_jobs_
;
95 scoped_refptr
<PrintQueriesQueue
> queue_
;
99 DISALLOW_COPY_AND_ASSIGN(PrintJobManager
);
102 } // namespace printing
104 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_