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_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/printing/print_job_worker_owner.h" | 14 #include "chrome/browser/printing/print_job_worker_owner.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 | 17 |
18 class Thread; | |
19 | |
20 namespace base { | 18 namespace base { |
21 class RefCountedMemory; | 19 class RefCountedMemory; |
22 } | 20 } |
23 | 21 |
24 namespace printing { | 22 namespace printing { |
25 | 23 |
26 class JobEventDetails; | 24 class JobEventDetails; |
27 class MetafilePlayer; | 25 class MetafilePlayer; |
28 class PdfToEmfConverter; | 26 class PdfToEmfConverter; |
29 class PrintJobWorker; | 27 class PrintJobWorker; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 void DisconnectSource(); | 84 void DisconnectSource(); |
87 | 85 |
88 // Returns true if the print job is pending, i.e. between a StartPrinting() | 86 // Returns true if the print job is pending, i.e. between a StartPrinting() |
89 // and the end of the spooling. | 87 // and the end of the spooling. |
90 bool is_job_pending() const; | 88 bool is_job_pending() const; |
91 | 89 |
92 // Access the current printed document. Warning: may be NULL. | 90 // Access the current printed document. Warning: may be NULL. |
93 PrintedDocument* document() const; | 91 PrintedDocument* document() const; |
94 | 92 |
95 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
| 94 // Let the PrintJob know the 0-based |page_number| of a given printed page. |
| 95 void AppendPrintedPage(int page_number); |
| 96 |
96 void StartPdfToEmfConversion( | 97 void StartPdfToEmfConversion( |
97 const scoped_refptr<base::RefCountedMemory>& bytes, | 98 const scoped_refptr<base::RefCountedMemory>& bytes, |
98 const gfx::Size& page_size, | 99 const gfx::Size& page_size, |
99 const gfx::Rect& content_area); | 100 const gfx::Rect& content_area); |
100 #endif // OS_WIN | 101 #endif // defined(OS_WIN) |
101 | 102 |
102 protected: | 103 protected: |
103 ~PrintJob() override; | 104 ~PrintJob() override; |
104 | 105 |
105 private: | 106 private: |
106 // Updates document_ to a new instance. | 107 // Updates |document_| to a new instance. |
107 void UpdatePrintedDocument(PrintedDocument* new_document); | 108 void UpdatePrintedDocument(PrintedDocument* new_document); |
108 | 109 |
109 // Processes a NOTIFY_PRINT_JOB_EVENT notification. | 110 // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
110 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); | 111 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); |
111 | 112 |
112 // Releases the worker thread by calling Stop(), then broadcasts a JOB_DONE | 113 // Releases the worker thread by calling Stop(), then broadcasts a JOB_DONE |
113 // notification. | 114 // notification. |
114 void OnDocumentDone(); | 115 void OnDocumentDone(); |
115 | 116 |
116 // Terminates the worker thread in a very controlled way, to work around any | 117 // Terminates the worker thread in a very controlled way, to work around any |
117 // eventual deadlock. | 118 // eventual deadlock. |
118 void ControlledWorkerShutdown(); | 119 void ControlledWorkerShutdown(); |
119 | 120 |
120 // Called at shutdown when running a nested message loop. | 121 // Called at shutdown when running a nested message loop. |
121 void Quit(); | 122 void Quit(); |
122 | 123 |
123 void HoldUntilStopIsCalled(); | 124 void HoldUntilStopIsCalled(); |
124 | 125 |
125 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
126 void OnPdfToEmfStarted(int page_count); | 127 void OnPdfToEmfStarted(int page_count); |
127 void OnPdfToEmfPageConverted(int page_number, | 128 void OnPdfToEmfPageConverted(int page_number, |
128 float scale_factor, | 129 float scale_factor, |
129 std::unique_ptr<MetafilePlayer> emf); | 130 std::unique_ptr<MetafilePlayer> emf); |
130 #endif // OS_WIN | 131 #endif // defined(OS_WIN) |
131 | 132 |
132 content::NotificationRegistrar registrar_; | 133 content::NotificationRegistrar registrar_; |
133 | 134 |
134 // Source that generates the PrintedPage's (i.e. a WebContents). It will be | 135 // Source that generates the PrintedPage's (i.e. a WebContents). It will be |
135 // set back to NULL if the source is deleted before this object. | 136 // set back to NULL if the source is deleted before this object. |
136 PrintedPagesSource* source_; | 137 PrintedPagesSource* source_; |
137 | 138 |
138 // All the UI is done in a worker thread because many Win32 print functions | 139 // All the UI is done in a worker thread because many Win32 print functions |
139 // are blocking and enters a message loop without your consent. There is one | 140 // are blocking and enters a message loop without your consent. There is one |
140 // worker thread per print job. | 141 // worker thread per print job. |
141 std::unique_ptr<PrintJobWorker> worker_; | 142 std::unique_ptr<PrintJobWorker> worker_; |
142 | 143 |
143 // Cache of the print context settings for access in the UI thread. | 144 // Cache of the print context settings for access in the UI thread. |
144 PrintSettings settings_; | 145 PrintSettings settings_; |
145 | 146 |
146 // The printed document. | 147 // The printed document. |
147 scoped_refptr<PrintedDocument> document_; | 148 scoped_refptr<PrintedDocument> document_; |
148 | 149 |
149 // Is the worker thread printing. | 150 // Is the worker thread printing. |
150 bool is_job_pending_; | 151 bool is_job_pending_; |
151 | 152 |
152 // Is Canceling? If so, try to not cause recursion if on FAILED notification, | 153 // Is Canceling? If so, try to not cause recursion if on FAILED notification, |
153 // the notified calls Cancel() again. | 154 // the notified calls Cancel() again. |
154 bool is_canceling_; | 155 bool is_canceling_; |
155 | 156 |
156 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
157 class PdfToEmfState; | 158 class PdfToEmfState; |
158 std::unique_ptr<PdfToEmfState> ptd_to_emf_state_; | 159 std::unique_ptr<PdfToEmfState> pdf_to_emf_state_; |
159 #endif // OS_WIN | 160 std::vector<int> pdf_page_mapping_; |
| 161 #endif // defined(OS_WIN) |
160 | 162 |
161 // Used at shutdown so that we can quit a nested message loop. | 163 // Used at shutdown so that we can quit a nested message loop. |
162 base::WeakPtrFactory<PrintJob> quit_factory_; | 164 base::WeakPtrFactory<PrintJob> quit_factory_; |
163 | 165 |
164 DISALLOW_COPY_AND_ASSIGN(PrintJob); | 166 DISALLOW_COPY_AND_ASSIGN(PrintJob); |
165 }; | 167 }; |
166 | 168 |
167 // Details for a NOTIFY_PRINT_JOB_EVENT notification. The members may be NULL. | 169 // Details for a NOTIFY_PRINT_JOB_EVENT notification. The members may be NULL. |
168 class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> { | 170 class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> { |
169 public: | 171 public: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 scoped_refptr<PrintedDocument> document_; | 221 scoped_refptr<PrintedDocument> document_; |
220 scoped_refptr<PrintedPage> page_; | 222 scoped_refptr<PrintedPage> page_; |
221 const Type type_; | 223 const Type type_; |
222 | 224 |
223 DISALLOW_COPY_AND_ASSIGN(JobEventDetails); | 225 DISALLOW_COPY_AND_ASSIGN(JobEventDetails); |
224 }; | 226 }; |
225 | 227 |
226 } // namespace printing | 228 } // namespace printing |
227 | 229 |
228 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_H_ | 230 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
OLD | NEW |