OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/printing/print_job_worker.h" | 5 #include "chrome/browser/printing/print_job_worker.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
9 #include "chrome/browser/printing/print_job.h" | 9 #include "chrome/browser/printing/print_job.h" |
10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 this, &PrintJobWorker::GetSettingsDone, result)); | 130 this, &PrintJobWorker::GetSettingsDone, result)); |
131 } | 131 } |
132 #endif // defined(OS_MACOSX) || defined(USE_X11) | 132 #endif // defined(OS_MACOSX) || defined(USE_X11) |
133 | 133 |
134 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { | 134 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { |
135 DCHECK_EQ(message_loop(), MessageLoop::current()); | 135 DCHECK_EQ(message_loop(), MessageLoop::current()); |
136 DCHECK_EQ(page_number_, PageNumber::npos()); | 136 DCHECK_EQ(page_number_, PageNumber::npos()); |
137 DCHECK_EQ(document_, new_document); | 137 DCHECK_EQ(document_, new_document); |
138 DCHECK(document_.get()); | 138 DCHECK(document_.get()); |
139 DCHECK(new_document->settings().Equals(printing_context_.settings())); | 139 DCHECK(new_document->settings().Equals(printing_context_.settings())); |
140 #if !defined(OS_MACOSX) | 140 |
141 DCHECK(printing_context_.context()); | |
142 #endif | |
143 if (!document_.get() || page_number_ != PageNumber::npos() || | 141 if (!document_.get() || page_number_ != PageNumber::npos() || |
144 document_ != new_document) { | 142 document_ != new_document) { |
145 return; | 143 return; |
146 } | 144 } |
147 | 145 |
148 PrintingContext::Result result = | 146 PrintingContext::Result result = |
149 printing_context_.NewDocument(document_->name()); | 147 printing_context_.NewDocument(document_->name()); |
150 if (result != PrintingContext::OK) { | 148 if (result != PrintingContext::OK) { |
151 OnFailure(); | 149 OnFailure(); |
152 return; | 150 return; |
153 } | 151 } |
154 | 152 |
155 // Try to print already cached data. It may already have been generated for | 153 // Try to print already cached data. It may already have been generated for |
156 // the print preview. | 154 // the print preview. |
157 OnNewPage(); | 155 OnNewPage(); |
158 // Don't touch this anymore since the instance could be destroyed. It happens | 156 // Don't touch this anymore since the instance could be destroyed. It happens |
159 // if all the pages are printed a one sweep and the client doesn't have a | 157 // if all the pages are printed a one sweep and the client doesn't have a |
160 // handle to us anymore. There's a timing issue involved between the worker | 158 // handle to us anymore. There's a timing issue involved between the worker |
161 // thread and the UI thread. Take no chance. | 159 // thread and the UI thread. Take no chance. |
162 } | 160 } |
163 | 161 |
164 void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) { | 162 void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) { |
165 DCHECK_EQ(message_loop(), MessageLoop::current()); | 163 DCHECK_EQ(message_loop(), MessageLoop::current()); |
166 DCHECK_EQ(page_number_, PageNumber::npos()); | 164 DCHECK_EQ(page_number_, PageNumber::npos()); |
167 DCHECK(!new_document || | 165 DCHECK(!new_document || |
168 new_document->settings().Equals(printing_context_.settings())); | 166 new_document->settings().Equals(printing_context_.settings())); |
169 #if !defined(OS_MACOSX) | 167 |
170 DCHECK(printing_context_.context()); | |
171 #endif | |
172 if (page_number_ != PageNumber::npos()) | 168 if (page_number_ != PageNumber::npos()) |
173 return; | 169 return; |
174 | 170 |
175 document_ = new_document; | 171 document_ = new_document; |
176 } | 172 } |
177 | 173 |
178 void PrintJobWorker::OnNewPage() { | 174 void PrintJobWorker::OnNewPage() { |
179 if (!document_.get()) { | 175 if (!document_.get()) { |
180 // Spurious message. | 176 // Spurious message. |
181 return; | 177 return; |
182 } | 178 } |
183 // message_loop() could return NULL when the print job is cancelled. | 179 // message_loop() could return NULL when the print job is cancelled. |
184 DCHECK_EQ(message_loop(), MessageLoop::current()); | 180 DCHECK_EQ(message_loop(), MessageLoop::current()); |
185 #if !defined(OS_MACOSX) | |
186 DCHECK(printing_context_.context()); | |
187 if (!printing_context_.context()) | |
188 return; | |
189 #endif | |
190 | 181 |
191 if (page_number_ == PageNumber::npos()) { | 182 if (page_number_ == PageNumber::npos()) { |
192 // Find first page to print. | 183 // Find first page to print. |
193 int page_count = document_->page_count(); | 184 int page_count = document_->page_count(); |
194 if (!page_count) { | 185 if (!page_count) { |
195 // We still don't know how many pages the document contains. We can't | 186 // We still don't know how many pages the document contains. We can't |
196 // start to print the document yet since the header/footer may refer to | 187 // start to print the document yet since the header/footer may refer to |
197 // the document's page count. | 188 // the document's page count. |
198 return; | 189 return; |
199 } | 190 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 223 } |
233 | 224 |
234 void PrintJobWorker::DismissDialog() { | 225 void PrintJobWorker::DismissDialog() { |
235 printing_context_.DismissDialog(); | 226 printing_context_.DismissDialog(); |
236 } | 227 } |
237 | 228 |
238 void PrintJobWorker::OnDocumentDone() { | 229 void PrintJobWorker::OnDocumentDone() { |
239 DCHECK_EQ(message_loop(), MessageLoop::current()); | 230 DCHECK_EQ(message_loop(), MessageLoop::current()); |
240 DCHECK_EQ(page_number_, PageNumber::npos()); | 231 DCHECK_EQ(page_number_, PageNumber::npos()); |
241 DCHECK(document_.get()); | 232 DCHECK(document_.get()); |
242 #if !defined(OS_MACOSX) | |
243 DCHECK(printing_context_.context()); | |
244 #endif | |
245 | 233 |
246 if (printing_context_.DocumentDone() != PrintingContext::OK) { | 234 if (printing_context_.DocumentDone() != PrintingContext::OK) { |
247 OnFailure(); | 235 OnFailure(); |
248 return; | 236 return; |
249 } | 237 } |
250 | 238 |
251 // Tell everyone! | 239 // Tell everyone! |
252 NotificationTask* task = new NotificationTask(); | 240 NotificationTask* task = new NotificationTask(); |
253 task->Init(owner_, | 241 task->Init(owner_, |
254 JobEventDetails::DOC_DONE, | 242 JobEventDetails::DOC_DONE, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 printing::PrintJobWorker* obj) { | 309 printing::PrintJobWorker* obj) { |
322 DCHECK(!owner_.get()); | 310 DCHECK(!owner_.get()); |
323 owner_ = obj->owner_; | 311 owner_ = obj->owner_; |
324 } | 312 } |
325 | 313 |
326 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( | 314 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( |
327 printing::PrintJobWorker* obj) { | 315 printing::PrintJobWorker* obj) { |
328 DCHECK_EQ(owner_, obj->owner_); | 316 DCHECK_EQ(owner_, obj->owner_); |
329 owner_ = NULL; | 317 owner_ = NULL; |
330 } | 318 } |
OLD | NEW |