| 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 #include "chrome/browser/printing/print_job_worker.h" | 5 #include "chrome/browser/printing/print_job_worker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 PrintedDocument* document, | 86 PrintedDocument* document, |
| 87 PrintedPage* page) { | 87 PrintedPage* page) { |
| 88 JobEventDetails* details = new JobEventDetails(detail_type, document, page); | 88 JobEventDetails* details = new JobEventDetails(detail_type, document, page); |
| 89 content::NotificationService::current()->Notify( | 89 content::NotificationService::current()->Notify( |
| 90 chrome::NOTIFICATION_PRINT_JOB_EVENT, | 90 chrome::NOTIFICATION_PRINT_JOB_EVENT, |
| 91 // We know that is is a PrintJob object in this circumstance. | 91 // We know that is is a PrintJob object in this circumstance. |
| 92 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), | 92 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), |
| 93 content::Details<JobEventDetails>(details)); | 93 content::Details<JobEventDetails>(details)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void PostOnOwnerThread(const scoped_refptr<PrintJobWorkerOwner>& owner, |
| 97 const PrintingContext::PrintSettingsCallback& callback, |
| 98 PrintingContext::Result result) { |
| 99 owner->PostTask(FROM_HERE, base::Bind(&HoldRefCallback, owner, |
| 100 base::Bind(callback, result))); |
| 101 } |
| 102 |
| 96 } // namespace | 103 } // namespace |
| 97 | 104 |
| 98 PrintJobWorker::PrintJobWorker(int render_process_id, | 105 PrintJobWorker::PrintJobWorker(int render_process_id, |
| 99 int render_view_id, | 106 int render_view_id, |
| 100 PrintJobWorkerOwner* owner) | 107 PrintJobWorkerOwner* owner) |
| 101 : owner_(owner), thread_("Printing_Worker"), weak_factory_(this) { | 108 : owner_(owner), thread_("Printing_Worker"), weak_factory_(this) { |
| 102 // The object is created in the IO thread. | 109 // The object is created in the IO thread. |
| 103 DCHECK(owner_->RunsTasksOnCurrentThread()); | 110 DCHECK(owner_->RunsTasksOnCurrentThread()); |
| 104 | 111 |
| 105 printing_context_delegate_.reset( | 112 printing_context_delegate_.reset( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 219 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 213 | 220 |
| 214 // Regardless of whether the following call fails or not, the javascript | 221 // Regardless of whether the following call fails or not, the javascript |
| 215 // call will return since startPendingPrint will make it return immediately | 222 // call will return since startPendingPrint will make it return immediately |
| 216 // in case of error. | 223 // in case of error. |
| 217 if (tab) | 224 if (tab) |
| 218 tab->SetPendingPrint(); | 225 tab->SetPendingPrint(); |
| 219 } | 226 } |
| 220 #endif | 227 #endif |
| 221 | 228 |
| 229 // weak_factory_ creates pointers valid only on owner_ thread. |
| 222 printing_context_->AskUserForSettings( | 230 printing_context_->AskUserForSettings( |
| 223 document_page_count, | 231 document_page_count, has_selection, is_scripted, |
| 224 has_selection, | 232 base::Bind(&PostOnOwnerThread, make_scoped_refptr(owner_), |
| 225 is_scripted, | 233 base::Bind(&PrintJobWorker::GetSettingsDone, |
| 226 base::Bind(&PrintJobWorker::GetSettingsWithUIDone, | 234 weak_factory_.GetWeakPtr()))); |
| 227 base::Unretained(this))); | |
| 228 } | |
| 229 | |
| 230 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { | |
| 231 PostTask(FROM_HERE, | |
| 232 base::Bind(&HoldRefCallback, | |
| 233 make_scoped_refptr(owner_), | |
| 234 base::Bind(&PrintJobWorker::GetSettingsDone, | |
| 235 base::Unretained(this), | |
| 236 result))); | |
| 237 } | 235 } |
| 238 | 236 |
| 239 void PrintJobWorker::UseDefaultSettings() { | 237 void PrintJobWorker::UseDefaultSettings() { |
| 240 PrintingContext::Result result = printing_context_->UseDefaultSettings(); | 238 PrintingContext::Result result = printing_context_->UseDefaultSettings(); |
| 241 GetSettingsDone(result); | 239 GetSettingsDone(result); |
| 242 } | 240 } |
| 243 | 241 |
| 244 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { | 242 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { |
| 245 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 243 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 246 DCHECK_EQ(page_number_, PageNumber::npos()); | 244 DCHECK_EQ(page_number_, PageNumber::npos()); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 document_, | 431 document_, |
| 434 scoped_refptr<PrintedPage>())); | 432 scoped_refptr<PrintedPage>())); |
| 435 Cancel(); | 433 Cancel(); |
| 436 | 434 |
| 437 // Makes sure the variables are reinitialized. | 435 // Makes sure the variables are reinitialized. |
| 438 document_ = NULL; | 436 document_ = NULL; |
| 439 page_number_ = PageNumber::npos(); | 437 page_number_ = PageNumber::npos(); |
| 440 } | 438 } |
| 441 | 439 |
| 442 } // namespace printing | 440 } // namespace printing |
| OLD | NEW |