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_WORKER_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_ |
6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "content/public/browser/browser_thread.h" |
12 #include "printing/page_number.h" | 13 #include "printing/page_number.h" |
13 #include "printing/print_destination_interface.h" | 14 #include "printing/print_destination_interface.h" |
| 15 #include "printing/print_job_constants.h" |
14 #include "printing/printing_context.h" | 16 #include "printing/printing_context.h" |
15 #include "printing/print_job_constants.h" | |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class DictionaryValue; | 19 class DictionaryValue; |
19 } | 20 } |
20 | 21 |
21 namespace printing { | 22 namespace printing { |
22 | 23 |
23 class PrintJob; | 24 class PrintJob; |
24 class PrintJobWorkerOwner; | 25 class PrintJobWorkerOwner; |
25 class PrintedDocument; | 26 class PrintedDocument; |
26 class PrintedPage; | 27 class PrintedPage; |
27 class PrintingUIWebContentsObserver; | |
28 | 28 |
29 // Worker thread code. It manages the PrintingContext, which can be blocking | 29 // Worker thread code. It manages the PrintingContext, which can be blocking |
30 // and/or run a message loop. This is the object that generates most | 30 // and/or run a message loop. This is the object that generates most |
31 // NOTIFY_PRINT_JOB_EVENT notifications, but they are generated through a | 31 // NOTIFY_PRINT_JOB_EVENT notifications, but they are generated through a |
32 // NotificationTask task to be executed from the right thread, the UI thread. | 32 // NotificationTask task to be executed from the right thread, the UI thread. |
33 // PrintJob always outlives its worker instance. | 33 // PrintJob always outlives its worker instance. |
34 class PrintJobWorker { | 34 class PrintJobWorker { |
35 public: | 35 public: |
36 explicit PrintJobWorker(PrintJobWorkerOwner* owner); | 36 PrintJobWorker(int render_process_id, |
| 37 int render_view_id, |
| 38 PrintJobWorkerOwner* owner); |
37 virtual ~PrintJobWorker(); | 39 virtual ~PrintJobWorker(); |
38 | 40 |
39 void SetNewOwner(PrintJobWorkerOwner* new_owner); | 41 void SetNewOwner(PrintJobWorkerOwner* new_owner); |
40 | 42 |
41 // Set a destination for print. | 43 // Set a destination for print. |
42 // This supersedes the document's rendering destination. | 44 // This supersedes the document's rendering destination. |
43 void SetPrintDestination(PrintDestinationInterface* destination); | 45 void SetPrintDestination(PrintDestinationInterface* destination); |
44 | 46 |
45 // Initializes the print settings. If |ask_user_for_settings| is true, a | 47 // Initializes the print settings. If |ask_user_for_settings| is true, a |
46 // Print... dialog box will be shown to ask the user his preference. | 48 // Print... dialog box will be shown to ask the user his preference. |
47 void GetSettings( | 49 void GetSettings( |
48 bool ask_user_for_settings, | 50 bool ask_user_for_settings, |
49 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer, | |
50 int document_page_count, | 51 int document_page_count, |
51 bool has_selection, | 52 bool has_selection, |
52 MarginType margin_type); | 53 MarginType margin_type); |
53 | 54 |
54 // Set the new print settings. | 55 // Set the new print settings. |
55 void SetSettings( | 56 void SetSettings(scoped_ptr<base::DictionaryValue> new_settings); |
56 scoped_ptr<base::DictionaryValue> new_settings); | |
57 | 57 |
58 // Starts the printing loop. Every pages are printed as soon as the data is | 58 // Starts the printing loop. Every pages are printed as soon as the data is |
59 // available. Makes sure the new_document is the right one. | 59 // available. Makes sure the new_document is the right one. |
60 void StartPrinting(PrintedDocument* new_document); | 60 void StartPrinting(PrintedDocument* new_document); |
61 | 61 |
62 // Updates the printed document. | 62 // Updates the printed document. |
63 void OnDocumentChanged(PrintedDocument* new_document); | 63 void OnDocumentChanged(PrintedDocument* new_document); |
64 | 64 |
65 // Dequeues waiting pages. Called when PrintJob receives a | 65 // Dequeues waiting pages. Called when PrintJob receives a |
66 // NOTIFY_PRINTED_DOCUMENT_UPDATED notification. It's time to look again if | 66 // NOTIFY_PRINTED_DOCUMENT_UPDATED notification. It's time to look again if |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void OnDocumentDone(); | 105 void OnDocumentDone(); |
106 | 106 |
107 // Discards the current document, the current page and cancels the printing | 107 // Discards the current document, the current page and cancels the printing |
108 // context. | 108 // context. |
109 void OnFailure(); | 109 void OnFailure(); |
110 | 110 |
111 // Asks the user for print settings. Must be called on the UI thread. | 111 // Asks the user for print settings. Must be called on the UI thread. |
112 // Required on Mac and Linux. Windows can display UI from non-main threads, | 112 // Required on Mac and Linux. Windows can display UI from non-main threads, |
113 // but sticks with this for consistency. | 113 // but sticks with this for consistency. |
114 void GetSettingsWithUI( | 114 void GetSettingsWithUI( |
115 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer, | |
116 int document_page_count, | 115 int document_page_count, |
117 bool has_selection); | 116 bool has_selection); |
118 | 117 |
119 // The callback used by PrintingContext::GetSettingsWithUI() to notify this | 118 // The callback used by PrintingContext::GetSettingsWithUI() to notify this |
120 // object that the print settings are set. This is needed in order to bounce | 119 // object that the print settings are set. This is needed in order to bounce |
121 // back into the IO thread for GetSettingsDone(). | 120 // back into the IO thread for GetSettingsDone(). |
122 void GetSettingsWithUIDone(PrintingContext::Result result); | 121 void GetSettingsWithUIDone(PrintingContext::Result result); |
123 | 122 |
124 // Called on the UI thread to update the print settings. | 123 // Called on the UI thread to update the print settings. |
125 void UpdatePrintSettings(scoped_ptr<base::DictionaryValue> new_settings); | 124 void UpdatePrintSettings(scoped_ptr<base::DictionaryValue> new_settings); |
126 | 125 |
127 // Reports settings back to owner_. | 126 // Reports settings back to owner_. |
128 void GetSettingsDone(PrintingContext::Result result); | 127 void GetSettingsDone(PrintingContext::Result result); |
129 | 128 |
130 // Use the default settings. When using GTK+ or Mac, this can still end up | 129 // Use the default settings. When using GTK+ or Mac, this can still end up |
131 // displaying a dialog. So this needs to happen from the UI thread on these | 130 // displaying a dialog. So this needs to happen from the UI thread on these |
132 // systems. | 131 // systems. |
133 void UseDefaultSettings(); | 132 void UseDefaultSettings(); |
134 | 133 |
| 134 // Printing context delegate. |
| 135 scoped_ptr<PrintingContext::Delegate, |
| 136 content::BrowserThread::DeleteOnUIThread> |
| 137 printing_context_delegate_; |
| 138 |
135 // Information about the printer setting. | 139 // Information about the printer setting. |
136 scoped_ptr<PrintingContext> printing_context_; | 140 scoped_ptr<PrintingContext> printing_context_; |
137 | 141 |
138 // The printed document. Only has read-only access. | 142 // The printed document. Only has read-only access. |
139 scoped_refptr<PrintedDocument> document_; | 143 scoped_refptr<PrintedDocument> document_; |
140 | 144 |
141 // The print destination, may be NULL. | 145 // The print destination, may be NULL. |
142 scoped_refptr<PrintDestinationInterface> destination_; | 146 scoped_refptr<PrintDestinationInterface> destination_; |
143 | 147 |
144 // The print job owning this worker thread. It is guaranteed to outlive this | 148 // The print job owning this worker thread. It is guaranteed to outlive this |
(...skipping 11 matching lines...) Expand all Loading... |
156 | 160 |
157 // Used to generate a WeakPtr for callbacks. | 161 // Used to generate a WeakPtr for callbacks. |
158 base::WeakPtrFactory<PrintJobWorker> weak_factory_; | 162 base::WeakPtrFactory<PrintJobWorker> weak_factory_; |
159 | 163 |
160 DISALLOW_COPY_AND_ASSIGN(PrintJobWorker); | 164 DISALLOW_COPY_AND_ASSIGN(PrintJobWorker); |
161 }; | 165 }; |
162 | 166 |
163 } // namespace printing | 167 } // namespace printing |
164 | 168 |
165 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_ | 169 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H_ |
OLD | NEW |