OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "printing/page_number.h" | 13 #include "printing/page_number.h" |
14 #include "printing/printing_context.h" | 14 #include "printing/printing_context.h" |
15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
16 | 16 |
| 17 class DictionaryValue; |
| 18 |
17 namespace printing { | 19 namespace printing { |
18 | 20 |
19 class PrintedDocument; | 21 class PrintedDocument; |
20 class PrintedPage; | 22 class PrintedPage; |
21 class PrintJob; | 23 class PrintJob; |
22 class PrintJobWorkerOwner; | 24 class PrintJobWorkerOwner; |
23 | 25 |
24 // Worker thread code. All this code, except for the constructor, is executed in | 26 // Worker thread code. All this code, except for the constructor, is executed in |
25 // the worker thread. It manages the PrintingContext, which can be blocking | 27 // the worker thread. It manages the PrintingContext, which can be blocking |
26 // and/or run a message loop. This is the object that generates most | 28 // and/or run a message loop. This is the object that generates most |
27 // NOTIFY_PRINT_JOB_EVENT notifications, but they are generated through a | 29 // NOTIFY_PRINT_JOB_EVENT notifications, but they are generated through a |
28 // NotificationTask task to be executed from the right thread, the UI thread. | 30 // NotificationTask task to be executed from the right thread, the UI thread. |
29 // PrintJob always outlives its worker instance. | 31 // PrintJob always outlives its worker instance. |
30 class PrintJobWorker : public base::Thread { | 32 class PrintJobWorker : public base::Thread { |
31 public: | 33 public: |
32 explicit PrintJobWorker(PrintJobWorkerOwner* owner); | 34 explicit PrintJobWorker(PrintJobWorkerOwner* owner); |
33 ~PrintJobWorker(); | 35 ~PrintJobWorker(); |
34 | 36 |
35 void SetNewOwner(PrintJobWorkerOwner* new_owner); | 37 void SetNewOwner(PrintJobWorkerOwner* new_owner); |
36 | 38 |
37 // Initializes the print settings. If |ask_user_for_settings| is true, a | 39 // Initializes the print settings. If |ask_user_for_settings| is true, a |
38 // Print... dialog box will be shown to ask the user his preference. | 40 // Print... dialog box will be shown to ask the user his preference. |
39 void GetSettings(bool ask_user_for_settings, | 41 void GetSettings(bool ask_user_for_settings, |
40 gfx::NativeView parent_view, | 42 gfx::NativeView parent_view, |
41 int document_page_count, | 43 int document_page_count, |
42 bool has_selection, | 44 bool has_selection, |
43 bool use_overlays); | 45 bool use_overlays); |
44 | 46 |
| 47 // Set the new print settings. This function takes ownership of |new_settings| |
| 48 // and frees it. |
| 49 void SetSettings(const DictionaryValue* const new_settings); |
| 50 |
45 // Starts the printing loop. Every pages are printed as soon as the data is | 51 // Starts the printing loop. Every pages are printed as soon as the data is |
46 // available. Makes sure the new_document is the right one. | 52 // available. Makes sure the new_document is the right one. |
47 void StartPrinting(PrintedDocument* new_document); | 53 void StartPrinting(PrintedDocument* new_document); |
48 | 54 |
49 // Updates the printed document. | 55 // Updates the printed document. |
50 void OnDocumentChanged(PrintedDocument* new_document); | 56 void OnDocumentChanged(PrintedDocument* new_document); |
51 | 57 |
52 // Unqueues waiting pages. Called when PrintJob receives a | 58 // Unqueues waiting pages. Called when PrintJob receives a |
53 // NOTIFY_PRINTED_DOCUMENT_UPDATED notification. It's time to look again if | 59 // NOTIFY_PRINTED_DOCUMENT_UPDATED notification. It's time to look again if |
54 // the next page can be printed. | 60 // the next page can be printed. |
(...skipping 30 matching lines...) Expand all Loading... |
85 // but sticks with this for consistency. | 91 // but sticks with this for consistency. |
86 void GetSettingsWithUI(gfx::NativeView parent_view, | 92 void GetSettingsWithUI(gfx::NativeView parent_view, |
87 int document_page_count, | 93 int document_page_count, |
88 bool has_selection); | 94 bool has_selection); |
89 | 95 |
90 // The callback used by PrintingContext::GetSettingsWithUI() to notify this | 96 // The callback used by PrintingContext::GetSettingsWithUI() to notify this |
91 // object that the print settings are set. This is needed in order to bounce | 97 // object that the print settings are set. This is needed in order to bounce |
92 // back into the IO thread for GetSettingsDone(). | 98 // back into the IO thread for GetSettingsDone(). |
93 void GetSettingsWithUIDone(PrintingContext::Result result); | 99 void GetSettingsWithUIDone(PrintingContext::Result result); |
94 | 100 |
| 101 // Called on the UI thread to update the print settings. |
| 102 void UpdatePrintSettings(const DictionaryValue* const new_settings); |
| 103 |
95 // Reports settings back to owner_. | 104 // Reports settings back to owner_. |
96 void GetSettingsDone(PrintingContext::Result result); | 105 void GetSettingsDone(PrintingContext::Result result); |
97 | 106 |
98 // Use the default settings. When using GTK+ or Mac, this can still end up | 107 // Use the default settings. When using GTK+ or Mac, this can still end up |
99 // displaying a dialog. So this needs to happen from the UI thread on these | 108 // displaying a dialog. So this needs to happen from the UI thread on these |
100 // systems. | 109 // systems. |
101 void UseDefaultSettings(); | 110 void UseDefaultSettings(); |
102 | 111 |
103 // Information about the printer setting. | 112 // Information about the printer setting. |
104 scoped_ptr<PrintingContext> printing_context_; | 113 scoped_ptr<PrintingContext> printing_context_; |
(...skipping 15 matching lines...) Expand all Loading... |
120 | 129 |
121 template <> | 130 template <> |
122 struct RunnableMethodTraits<printing::PrintJobWorker> { | 131 struct RunnableMethodTraits<printing::PrintJobWorker> { |
123 void RetainCallee(printing::PrintJobWorker* obj); | 132 void RetainCallee(printing::PrintJobWorker* obj); |
124 void ReleaseCallee(printing::PrintJobWorker* obj); | 133 void ReleaseCallee(printing::PrintJobWorker* obj); |
125 private: | 134 private: |
126 scoped_refptr<printing::PrintJobWorkerOwner> owner_; | 135 scoped_refptr<printing::PrintJobWorkerOwner> owner_; |
127 }; | 136 }; |
128 | 137 |
129 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__ | 138 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__ |
OLD | NEW |