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" |
| 11 #include "base/location.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" |
12 #include "base/values.h" | 15 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/printing/print_job.h" | 18 #include "chrome/browser/printing/print_job.h" |
16 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
17 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
21 #include "printing/print_job_constants.h" | 24 #include "printing/print_job_constants.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 // We have enough information to initialize page_number_. | 304 // We have enough information to initialize page_number_. |
302 page_number_.Init(document_->settings(), page_count); | 305 page_number_.Init(document_->settings(), page_count); |
303 } | 306 } |
304 DCHECK_NE(page_number_, PageNumber::npos()); | 307 DCHECK_NE(page_number_, PageNumber::npos()); |
305 | 308 |
306 while (true) { | 309 while (true) { |
307 // Is the page available? | 310 // Is the page available? |
308 scoped_refptr<PrintedPage> page = document_->GetPage(page_number_.ToInt()); | 311 scoped_refptr<PrintedPage> page = document_->GetPage(page_number_.ToInt()); |
309 if (!page.get()) { | 312 if (!page.get()) { |
310 // We need to wait for the page to be available. | 313 // We need to wait for the page to be available. |
311 base::MessageLoop::current()->PostDelayedTask( | 314 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
312 FROM_HERE, | 315 FROM_HERE, |
313 base::Bind(&PrintJobWorker::OnNewPage, weak_factory_.GetWeakPtr()), | 316 base::Bind(&PrintJobWorker::OnNewPage, weak_factory_.GetWeakPtr()), |
314 base::TimeDelta::FromMilliseconds(500)); | 317 base::TimeDelta::FromMilliseconds(500)); |
315 break; | 318 break; |
316 } | 319 } |
317 // The page is there, print it. | 320 // The page is there, print it. |
318 SpoolPage(page.get()); | 321 SpoolPage(page.get()); |
319 ++page_number_; | 322 ++page_number_; |
320 if (page_number_ == PageNumber::npos()) { | 323 if (page_number_ == PageNumber::npos()) { |
321 OnDocumentDone(); | 324 OnDocumentDone(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 document_, | 434 document_, |
432 scoped_refptr<PrintedPage>())); | 435 scoped_refptr<PrintedPage>())); |
433 Cancel(); | 436 Cancel(); |
434 | 437 |
435 // Makes sure the variables are reinitialized. | 438 // Makes sure the variables are reinitialized. |
436 document_ = NULL; | 439 document_ = NULL; |
437 page_number_ = PageNumber::npos(); | 440 page_number_ = PageNumber::npos(); |
438 } | 441 } |
439 | 442 |
440 } // namespace printing | 443 } // namespace printing |
OLD | NEW |