| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // The object is deleted in the UI thread. | 58 // The object is deleted in the UI thread. |
| 59 DCHECK_EQ(owner_->message_loop(), MessageLoop::current()); | 59 DCHECK_EQ(owner_->message_loop(), MessageLoop::current()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { | 62 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { |
| 63 DCHECK(page_number_ == PageNumber::npos()); | 63 DCHECK(page_number_ == PageNumber::npos()); |
| 64 owner_ = new_owner; | 64 owner_ = new_owner; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void PrintJobWorker::GetSettings(bool ask_user_for_settings, | 67 void PrintJobWorker::GetSettings(bool ask_user_for_settings, |
| 68 gfx::NativeWindow parent_window, | 68 gfx::NativeView parent_view, |
| 69 int document_page_count, | 69 int document_page_count, |
| 70 bool has_selection, | 70 bool has_selection, |
| 71 bool use_overlays) { | 71 bool use_overlays) { |
| 72 DCHECK_EQ(message_loop(), MessageLoop::current()); | 72 DCHECK_EQ(message_loop(), MessageLoop::current()); |
| 73 DCHECK_EQ(page_number_, PageNumber::npos()); | 73 DCHECK_EQ(page_number_, PageNumber::npos()); |
| 74 | 74 |
| 75 // Recursive task processing is needed for the dialog in case it needs to be | 75 // Recursive task processing is needed for the dialog in case it needs to be |
| 76 // destroyed by a task. | 76 // destroyed by a task. |
| 77 MessageLoop::current()->SetNestableTasksAllowed(true); | 77 MessageLoop::current()->SetNestableTasksAllowed(true); |
| 78 printing_context_.SetUseOverlays(use_overlays); | 78 printing_context_.SetUseOverlays(use_overlays); |
| 79 | 79 |
| 80 if (ask_user_for_settings) { | 80 if (ask_user_for_settings) { |
| 81 #if defined(OS_MACOSX) | 81 #if defined(OS_MACOSX) |
| 82 ChromeThread::PostTask( | 82 ChromeThread::PostTask( |
| 83 ChromeThread::UI, FROM_HERE, | 83 ChromeThread::UI, FROM_HERE, |
| 84 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, | 84 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, |
| 85 parent_window, document_page_count, | 85 parent_view, document_page_count, |
| 86 has_selection)); | 86 has_selection)); |
| 87 #else | 87 #else |
| 88 PrintingContext::Result result = printing_context_.AskUserForSettings( | 88 PrintingContext::Result result = printing_context_.AskUserForSettings( |
| 89 parent_window, document_page_count, has_selection); | 89 parent_view, document_page_count, has_selection); |
| 90 GetSettingsDone(result); | 90 GetSettingsDone(result); |
| 91 #endif | 91 #endif |
| 92 } else { | 92 } else { |
| 93 PrintingContext::Result result = printing_context_.UseDefaultSettings(); | 93 PrintingContext::Result result = printing_context_.UseDefaultSettings(); |
| 94 GetSettingsDone(result); | 94 GetSettingsDone(result); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { | 98 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { |
| 99 // Most PrintingContext functions may start a message loop and process | 99 // Most PrintingContext functions may start a message loop and process |
| 100 // message recursively, so disable recursive task processing. | 100 // message recursively, so disable recursive task processing. |
| 101 MessageLoop::current()->SetNestableTasksAllowed(false); | 101 MessageLoop::current()->SetNestableTasksAllowed(false); |
| 102 | 102 |
| 103 // We can't use OnFailure() here since owner_ may not support notifications. | 103 // We can't use OnFailure() here since owner_ may not support notifications. |
| 104 | 104 |
| 105 // PrintJob will create the new PrintedDocument. | 105 // PrintJob will create the new PrintedDocument. |
| 106 owner_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 106 owner_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 107 owner_, | 107 owner_, |
| 108 &PrintJobWorkerOwner::GetSettingsDone, | 108 &PrintJobWorkerOwner::GetSettingsDone, |
| 109 printing_context_.settings(), | 109 printing_context_.settings(), |
| 110 result)); | 110 result)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 #if defined(OS_MACOSX) | 113 #if defined(OS_MACOSX) |
| 114 void PrintJobWorker::GetSettingsWithUI(gfx::NativeWindow parent_window, | 114 void PrintJobWorker::GetSettingsWithUI(gfx::NativeView parent_view, |
| 115 int document_page_count, | 115 int document_page_count, |
| 116 bool has_selection) { | 116 bool has_selection) { |
| 117 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 117 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 118 | 118 |
| 119 PrintingContext::Result result = printing_context_.AskUserForSettings( | 119 PrintingContext::Result result = printing_context_.AskUserForSettings( |
| 120 parent_window, document_page_count, has_selection); | 120 parent_view, document_page_count, has_selection); |
| 121 message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 121 message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 122 this, &PrintJobWorker::GetSettingsDone, result)); | 122 this, &PrintJobWorker::GetSettingsDone, result)); |
| 123 } | 123 } |
| 124 #endif | 124 #endif |
| 125 | 125 |
| 126 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { | 126 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { |
| 127 DCHECK_EQ(message_loop(), MessageLoop::current()); | 127 DCHECK_EQ(message_loop(), MessageLoop::current()); |
| 128 DCHECK_EQ(page_number_, PageNumber::npos()); | 128 DCHECK_EQ(page_number_, PageNumber::npos()); |
| 129 DCHECK_EQ(document_, new_document); | 129 DCHECK_EQ(document_, new_document); |
| 130 DCHECK(document_.get()); | 130 DCHECK(document_.get()); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 printing::PrintJobWorker* obj) { | 319 printing::PrintJobWorker* obj) { |
| 320 DCHECK(!owner_.get()); | 320 DCHECK(!owner_.get()); |
| 321 owner_ = obj->owner_; | 321 owner_ = obj->owner_; |
| 322 } | 322 } |
| 323 | 323 |
| 324 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( | 324 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( |
| 325 printing::PrintJobWorker* obj) { | 325 printing::PrintJobWorker* obj) { |
| 326 DCHECK_EQ(owner_, obj->owner_); | 326 DCHECK_EQ(owner_, obj->owner_); |
| 327 owner_ = NULL; | 327 owner_ = NULL; |
| 328 } | 328 } |
| OLD | NEW |