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.h" | 5 #include "chrome/browser/printing/print_job.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/timer.h" | 8 #include "base/timer.h" |
9 #include "chrome/browser/printing/print_job_worker.h" | 9 #include "chrome/browser/printing/print_job_worker.h" |
10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
11 #include "printing/printed_document.h" | 11 #include "printing/printed_document.h" |
12 #include "printing/printed_page.h" | 12 #include "printing/printed_page.h" |
13 | 13 |
14 #ifdef _MSC_VER | 14 #ifdef _MSC_VER |
15 #pragma warning(disable:4355) // 'this' : used in base member initializer list | 15 #pragma warning(disable:4355) // 'this' : used in base member initializer list |
16 #endif | 16 #endif |
17 | 17 |
18 using base::TimeDelta; | 18 using base::TimeDelta; |
19 | 19 |
20 namespace printing { | 20 namespace printing { |
21 | 21 |
22 PrintJob::PrintJob() | 22 PrintJob::PrintJob() |
23 : ui_message_loop_(MessageLoop::current()), | 23 : ui_message_loop_(MessageLoop::current()), |
24 source_(NULL), | |
24 worker_(), | 25 worker_(), |
25 source_(NULL), | |
26 settings_(), | 26 settings_(), |
27 is_job_pending_(false), | 27 is_job_pending_(false), |
28 is_print_dialog_box_shown_(false), | 28 is_print_dialog_box_shown_(false), |
29 is_canceling_(false) { | 29 is_canceling_(false) { |
30 DCHECK(ui_message_loop_); | 30 DCHECK(ui_message_loop_); |
31 ui_message_loop_->AddDestructionObserver(this); | 31 ui_message_loop_->AddDestructionObserver(this); |
32 } | 32 } |
33 | 33 |
34 PrintJob::~PrintJob() { | 34 PrintJob::~PrintJob() { |
35 ui_message_loop_->RemoveDestructionObserver(this); | 35 ui_message_loop_->RemoveDestructionObserver(this); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 scoped_refptr<JobEventDetails> details( | 277 scoped_refptr<JobEventDetails> details( |
278 new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), NULL)); | 278 new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), NULL)); |
279 NotificationService::current()->Notify( | 279 NotificationService::current()->Notify( |
280 NotificationType::PRINT_JOB_EVENT, | 280 NotificationType::PRINT_JOB_EVENT, |
281 Source<PrintJob>(this), | 281 Source<PrintJob>(this), |
282 Details<JobEventDetails>(details.get())); | 282 Details<JobEventDetails>(details.get())); |
283 } | 283 } |
284 | 284 |
285 void PrintJob::ControlledWorkerShutdown() { | 285 void PrintJob::ControlledWorkerShutdown() { |
286 DCHECK_EQ(ui_message_loop_, MessageLoop::current()); | 286 DCHECK_EQ(ui_message_loop_, MessageLoop::current()); |
287 #if defined(OS_WIN) | |
pink (ping after 24hrs)
2009/10/13 21:04:51
add a todo to come back to this on mac and comment
stuartmorgan
2009/10/13 22:07:43
I don't think we'll ever need to come back to this
| |
287 // We could easily get into a deadlock case if worker_->Stop() is used; the | 288 // We could easily get into a deadlock case if worker_->Stop() is used; the |
288 // printer driver created a window as a child of the browser window. By | 289 // printer driver created a window as a child of the browser window. By |
289 // canceling the job, the printer driver initiated dialog box is destroyed, | 290 // canceling the job, the printer driver initiated dialog box is destroyed, |
290 // which sends a blocking message to its parent window. If the browser window | 291 // which sends a blocking message to its parent window. If the browser window |
291 // thread is not processing messages, a deadlock occurs. | 292 // thread is not processing messages, a deadlock occurs. |
292 // | 293 // |
293 // This function ensures that the dialog box will be destroyed in a timely | 294 // This function ensures that the dialog box will be destroyed in a timely |
294 // manner by the mere fact that the thread will terminate. So the potential | 295 // manner by the mere fact that the thread will terminate. So the potential |
295 // deadlock is eliminated. | 296 // deadlock is eliminated. |
296 worker_->StopSoon(); | 297 worker_->StopSoon(); |
(...skipping 19 matching lines...) Expand all Loading... | |
316 } | 317 } |
317 else if (result == WAIT_OBJECT_0) { | 318 else if (result == WAIT_OBJECT_0) { |
318 // The thread quit. | 319 // The thread quit. |
319 break; | 320 break; |
320 } else { | 321 } else { |
321 // An error occured. Assume the thread quit. | 322 // An error occured. Assume the thread quit. |
322 NOTREACHED(); | 323 NOTREACHED(); |
323 break; | 324 break; |
324 } | 325 } |
325 } | 326 } |
327 #endif | |
326 | 328 |
327 // Now make sure the thread object is cleaned up. | 329 // Now make sure the thread object is cleaned up. |
328 worker_->Stop(); | 330 worker_->Stop(); |
329 } | 331 } |
330 | 332 |
331 // Takes settings_ ownership and will be deleted in the receiving thread. | 333 // Takes settings_ ownership and will be deleted in the receiving thread. |
332 JobEventDetails::JobEventDetails(Type type, | 334 JobEventDetails::JobEventDetails(Type type, |
333 PrintedDocument* document, | 335 PrintedDocument* document, |
334 PrintedPage* page) | 336 PrintedPage* page) |
335 : document_(document), | 337 : document_(document), |
336 page_(page), | 338 page_(page), |
337 type_(type) { | 339 type_(type) { |
338 } | 340 } |
339 | 341 |
340 JobEventDetails::~JobEventDetails() { | 342 JobEventDetails::~JobEventDetails() { |
341 } | 343 } |
342 | 344 |
343 PrintedDocument* JobEventDetails::document() const { | 345 PrintedDocument* JobEventDetails::document() const { |
344 return document_; | 346 return document_; |
345 } | 347 } |
346 | 348 |
347 PrintedPage* JobEventDetails::page() const { | 349 PrintedPage* JobEventDetails::page() const { |
348 return page_; | 350 return page_; |
349 } | 351 } |
350 | 352 |
351 } // namespace printing | 353 } // namespace printing |
OLD | NEW |