OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ |
6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "chrome/browser/prefs/pref_member.h" | 13 #include "chrome/browser/prefs/pref_member.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "printing/print_destination_interface.h" |
16 | 17 |
17 class PrefService; | 18 class PrefService; |
18 | 19 |
19 namespace printing { | 20 namespace printing { |
20 | 21 |
21 class JobEventDetails; | 22 class JobEventDetails; |
22 class PrintJob; | 23 class PrintJob; |
23 class PrinterQuery; | 24 class PrinterQuery; |
24 | 25 |
25 class PrintJobManager : public content::NotificationObserver { | 26 class PrintJobManager : public content::NotificationObserver { |
26 public: | 27 public: |
27 PrintJobManager(); | 28 PrintJobManager(); |
28 virtual ~PrintJobManager(); | 29 virtual ~PrintJobManager(); |
29 | 30 |
30 // Registers for changes to the printing enabled preference in |prefs|. | 31 // Registers for changes to the printing enabled preference in |prefs|. |
31 // This method should be called on the UI thread. | 32 // This method should be called on the UI thread. |
32 void InitOnUIThread(PrefService* prefs); | 33 void InitOnUIThread(PrefService* prefs); |
33 | 34 |
34 // On browser quit, we should wait to have the print job finished. | 35 // On browser quit, we should wait to have the print job finished. |
35 void OnQuit(); | 36 void OnQuit(); |
36 | 37 |
37 // Stops all printing jobs. If wait_for_finish is true, tries to give jobs | 38 // Stops all printing jobs. If wait_for_finish is true, tries to give jobs |
38 // a chance to complete before stopping them. | 39 // a chance to complete before stopping them. |
39 void StopJobs(bool wait_for_finish); | 40 void StopJobs(bool wait_for_finish); |
40 | 41 |
| 42 // Sets the print destination to be set on the next print job. |
| 43 void SetPrintDestination(PrintDestinationInterface* destination); |
| 44 |
41 // Queues a semi-initialized worker thread. Can be called from any thread. | 45 // Queues a semi-initialized worker thread. Can be called from any thread. |
42 // Current use case is queuing from the I/O thread. | 46 // Current use case is queuing from the I/O thread. |
43 // TODO(maruel): Have them vanish after a timeout (~5 minutes?) | 47 // TODO(maruel): Have them vanish after a timeout (~5 minutes?) |
44 void QueuePrinterQuery(PrinterQuery* job); | 48 void QueuePrinterQuery(PrinterQuery* job); |
45 | 49 |
46 // Pops a queued PrintJobWorkerOwner object that was previously queued. Can be | 50 // Pops a queued PrintJobWorkerOwner object that was previously queued. Can be |
47 // called from any thread. Current use case is poping from the browser thread. | 51 // called from any thread. Current use case is poping from the browser thread. |
48 void PopPrinterQuery(int document_cookie, scoped_refptr<PrinterQuery>* job); | 52 void PopPrinterQuery(int document_cookie, scoped_refptr<PrinterQuery>* job); |
49 | 53 |
50 static void RegisterPrefs(PrefService* prefs); | 54 static void RegisterPrefs(PrefService* prefs); |
51 | 55 |
52 // content::NotificationObserver | 56 // content::NotificationObserver |
53 virtual void Observe(int type, | 57 virtual void Observe(int type, |
54 const content::NotificationSource& source, | 58 const content::NotificationSource& source, |
55 const content::NotificationDetails& details) OVERRIDE; | 59 const content::NotificationDetails& details) OVERRIDE; |
56 | 60 |
57 // Only accessed on the IO thread. UI thread can query | 61 // Only accessed on the IO thread. UI thread can query |
58 // prefs::kPrintingEnabled via g_browser_process->local_state() directly. | 62 // prefs::kPrintingEnabled via g_browser_process->local_state() directly. |
59 bool printing_enabled() const; | 63 bool printing_enabled() const; |
60 | 64 |
| 65 // May return NULL when no destination was set. |
| 66 PrintDestinationInterface* destination() const { return destination_.get(); } |
| 67 |
61 private: | 68 private: |
62 typedef std::vector<scoped_refptr<PrintJob> > PrintJobs; | 69 typedef std::vector<scoped_refptr<PrintJob> > PrintJobs; |
63 typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries; | 70 typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries; |
64 | 71 |
65 // Processes a NOTIFY_PRINT_JOB_EVENT notification. | 72 // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
66 void OnPrintJobEvent(PrintJob* print_job, | 73 void OnPrintJobEvent(PrintJob* print_job, |
67 const JobEventDetails& event_details); | 74 const JobEventDetails& event_details); |
68 | 75 |
69 content::NotificationRegistrar registrar_; | 76 content::NotificationRegistrar registrar_; |
70 | 77 |
71 // Printing is enabled/disabled. For printing with the native print dialog, | 78 // Printing is enabled/disabled. For printing with the native print dialog, |
72 // this variable is checked at only one place, by | 79 // this variable is checked at only one place, by |
73 // PrintingMessageFilter::OnGetDefaultPrintSettings. If its value is true | 80 // PrintingMessageFilter::OnGetDefaultPrintSettings. If its value is true |
74 // at that point, then the initiated print flow will complete itself, | 81 // at that point, then the initiated print flow will complete itself, |
75 // even if the value of this variable changes afterwards. | 82 // even if the value of this variable changes afterwards. |
76 // In the print preview workflow, this variable is checked in | 83 // In the print preview workflow, this variable is checked in |
77 // PrintingMessageFilter::OnUpdatePrintSettings, which gets called multiple | 84 // PrintingMessageFilter::OnUpdatePrintSettings, which gets called multiple |
78 // times in the print preview workflow. | 85 // times in the print preview workflow. |
79 BooleanPrefMember printing_enabled_; | 86 BooleanPrefMember printing_enabled_; |
80 | 87 |
81 // Used to serialize access to queued_workers_. | 88 // Used to serialize access to queued_workers_. |
82 base::Lock lock_; | 89 base::Lock lock_; |
83 | 90 |
84 PrinterQueries queued_queries_; | 91 PrinterQueries queued_queries_; |
85 | 92 |
| 93 scoped_refptr<PrintDestinationInterface> destination_; |
| 94 |
86 // Current print jobs that are active. | 95 // Current print jobs that are active. |
87 PrintJobs current_jobs_; | 96 PrintJobs current_jobs_; |
88 | 97 |
89 DISALLOW_COPY_AND_ASSIGN(PrintJobManager); | 98 DISALLOW_COPY_AND_ASSIGN(PrintJobManager); |
90 }; | 99 }; |
91 | 100 |
92 } // namespace printing | 101 } // namespace printing |
93 | 102 |
94 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ | 103 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ |
OLD | NEW |