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 "base/basictypes.h" | 8 #include "base/basictypes.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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "chrome/browser/printing/print_job_worker_owner.h" | 12 #include "chrome/browser/printing/print_job_worker_owner.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 | 15 |
16 class Thread; | 16 class Thread; |
17 | 17 |
| 18 namespace base { |
| 19 class RefCountedMemory; |
| 20 } |
| 21 |
18 namespace printing { | 22 namespace printing { |
19 | 23 |
20 // See definition below. | |
21 class JobEventDetails; | 24 class JobEventDetails; |
22 | 25 class MetafilePlayer; |
| 26 class PdfToEmfConverter; |
| 27 class PrintJobWorker; |
23 class PrintedDocument; | 28 class PrintedDocument; |
24 class PrintedPage; | 29 class PrintedPage; |
25 class PrintedPagesSource; | 30 class PrintedPagesSource; |
26 class PrintJobWorker; | |
27 class PrinterQuery; | 31 class PrinterQuery; |
28 | 32 |
29 // Manages the print work for a specific document. Talks to the printer through | 33 // Manages the print work for a specific document. Talks to the printer through |
30 // PrintingContext through PrintJobWorker. Hides access to PrintingContext in a | 34 // PrintingContext through PrintJobWorker. Hides access to PrintingContext in a |
31 // worker thread so the caller never blocks. PrintJob will send notifications on | 35 // worker thread so the caller never blocks. PrintJob will send notifications on |
32 // any state change. While printing, the PrintJobManager instance keeps a | 36 // any state change. While printing, the PrintJobManager instance keeps a |
33 // reference to the job to be sure it is kept alive. All the code in this class | 37 // reference to the job to be sure it is kept alive. All the code in this class |
34 // runs in the UI thread. | 38 // runs in the UI thread. |
35 class PrintJob : public PrintJobWorkerOwner, | 39 class PrintJob : public PrintJobWorkerOwner, |
36 public content::NotificationObserver { | 40 public content::NotificationObserver { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // the source is being destroyed. | 83 // the source is being destroyed. |
80 void DisconnectSource(); | 84 void DisconnectSource(); |
81 | 85 |
82 // 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() |
83 // and the end of the spooling. | 87 // and the end of the spooling. |
84 bool is_job_pending() const; | 88 bool is_job_pending() const; |
85 | 89 |
86 // Access the current printed document. Warning: may be NULL. | 90 // Access the current printed document. Warning: may be NULL. |
87 PrintedDocument* document() const; | 91 PrintedDocument* document() const; |
88 | 92 |
| 93 #if defined(OS_WIN) |
| 94 void StartPdfToEmfConversion( |
| 95 const scoped_refptr<base::RefCountedMemory>& bytes, |
| 96 const gfx::Size& page_size, |
| 97 const gfx::Rect& content_area); |
| 98 #endif // OS_WIN |
| 99 |
89 protected: | 100 protected: |
90 virtual ~PrintJob(); | 101 virtual ~PrintJob(); |
91 | 102 |
92 private: | 103 private: |
93 // Updates document_ to a new instance. | 104 // Updates document_ to a new instance. |
94 void UpdatePrintedDocument(PrintedDocument* new_document); | 105 void UpdatePrintedDocument(PrintedDocument* new_document); |
95 | 106 |
96 // Processes a NOTIFY_PRINT_JOB_EVENT notification. | 107 // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
97 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); | 108 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); |
98 | 109 |
99 // Releases the worker thread by calling Stop(), then broadcasts a JOB_DONE | 110 // Releases the worker thread by calling Stop(), then broadcasts a JOB_DONE |
100 // notification. | 111 // notification. |
101 void OnDocumentDone(); | 112 void OnDocumentDone(); |
102 | 113 |
103 // Terminates the worker thread in a very controlled way, to work around any | 114 // Terminates the worker thread in a very controlled way, to work around any |
104 // eventual deadlock. | 115 // eventual deadlock. |
105 void ControlledWorkerShutdown(); | 116 void ControlledWorkerShutdown(); |
106 | 117 |
107 // Called at shutdown when running a nested message loop. | 118 // Called at shutdown when running a nested message loop. |
108 void Quit(); | 119 void Quit(); |
109 | 120 |
110 void HoldUntilStopIsCalled(); | 121 void HoldUntilStopIsCalled(); |
111 | 122 |
| 123 #if defined(OS_WIN) |
| 124 void OnPdfToEmfStarted(int page_count); |
| 125 void OnPdfToEmfPageConverted(int page_number, |
| 126 double scale_factor, |
| 127 scoped_ptr<MetafilePlayer> emf); |
| 128 #endif // OS_WIN |
| 129 |
112 content::NotificationRegistrar registrar_; | 130 content::NotificationRegistrar registrar_; |
113 | 131 |
114 // Source that generates the PrintedPage's (i.e. a WebContents). It will be | 132 // Source that generates the PrintedPage's (i.e. a WebContents). It will be |
115 // set back to NULL if the source is deleted before this object. | 133 // set back to NULL if the source is deleted before this object. |
116 PrintedPagesSource* source_; | 134 PrintedPagesSource* source_; |
117 | 135 |
118 // All the UI is done in a worker thread because many Win32 print functions | 136 // All the UI is done in a worker thread because many Win32 print functions |
119 // are blocking and enters a message loop without your consent. There is one | 137 // are blocking and enters a message loop without your consent. There is one |
120 // worker thread per print job. | 138 // worker thread per print job. |
121 scoped_ptr<PrintJobWorker> worker_; | 139 scoped_ptr<PrintJobWorker> worker_; |
122 | 140 |
123 // Cache of the print context settings for access in the UI thread. | 141 // Cache of the print context settings for access in the UI thread. |
124 PrintSettings settings_; | 142 PrintSettings settings_; |
125 | 143 |
126 // The printed document. | 144 // The printed document. |
127 scoped_refptr<PrintedDocument> document_; | 145 scoped_refptr<PrintedDocument> document_; |
128 | 146 |
129 // Is the worker thread printing. | 147 // Is the worker thread printing. |
130 bool is_job_pending_; | 148 bool is_job_pending_; |
131 | 149 |
132 // Is Canceling? If so, try to not cause recursion if on FAILED notification, | 150 // Is Canceling? If so, try to not cause recursion if on FAILED notification, |
133 // the notified calls Cancel() again. | 151 // the notified calls Cancel() again. |
134 bool is_canceling_; | 152 bool is_canceling_; |
135 | 153 |
| 154 #if defined(OS_WIN) |
| 155 class PdfToEmfState; |
| 156 scoped_ptr<PdfToEmfState> ptd_to_emf_state_; |
| 157 #endif // OS_WIN |
| 158 |
136 // Used at shutdown so that we can quit a nested message loop. | 159 // Used at shutdown so that we can quit a nested message loop. |
137 base::WeakPtrFactory<PrintJob> quit_factory_; | 160 base::WeakPtrFactory<PrintJob> quit_factory_; |
138 | 161 |
139 DISALLOW_COPY_AND_ASSIGN(PrintJob); | 162 DISALLOW_COPY_AND_ASSIGN(PrintJob); |
140 }; | 163 }; |
141 | 164 |
142 // Details for a NOTIFY_PRINT_JOB_EVENT notification. The members may be NULL. | 165 // Details for a NOTIFY_PRINT_JOB_EVENT notification. The members may be NULL. |
143 class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> { | 166 class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> { |
144 public: | 167 public: |
145 // Event type. | 168 // Event type. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 scoped_refptr<PrintedDocument> document_; | 217 scoped_refptr<PrintedDocument> document_; |
195 scoped_refptr<PrintedPage> page_; | 218 scoped_refptr<PrintedPage> page_; |
196 const Type type_; | 219 const Type type_; |
197 | 220 |
198 DISALLOW_COPY_AND_ASSIGN(JobEventDetails); | 221 DISALLOW_COPY_AND_ASSIGN(JobEventDetails); |
199 }; | 222 }; |
200 | 223 |
201 } // namespace printing | 224 } // namespace printing |
202 | 225 |
203 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_H_ | 226 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
OLD | NEW |