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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 238 } |
239 | 239 |
240 void PrintJobWorker::UseDefaultSettings() { | 240 void PrintJobWorker::UseDefaultSettings() { |
241 PrintingContext::Result result = printing_context_->UseDefaultSettings(); | 241 PrintingContext::Result result = printing_context_->UseDefaultSettings(); |
242 GetSettingsDone(result); | 242 GetSettingsDone(result); |
243 } | 243 } |
244 | 244 |
245 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { | 245 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { |
246 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 246 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
247 DCHECK_EQ(page_number_, PageNumber::npos()); | 247 DCHECK_EQ(page_number_, PageNumber::npos()); |
248 DCHECK_EQ(document_, new_document); | 248 DCHECK_EQ(document_.get(), new_document); |
249 DCHECK(document_.get()); | 249 DCHECK(document_.get()); |
250 | 250 |
251 if (!document_.get() || page_number_ != PageNumber::npos() || | 251 if (!document_.get() || page_number_ != PageNumber::npos() || |
252 document_.get() != new_document) { | 252 document_.get() != new_document) { |
253 return; | 253 return; |
254 } | 254 } |
255 | 255 |
256 base::string16 document_name = | 256 base::string16 document_name = |
257 printing::SimplifyDocumentTitle(document_->name()); | 257 printing::SimplifyDocumentTitle(document_->name()); |
258 if (document_name.empty()) { | 258 if (document_name.empty()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // We have enough information to initialize page_number_. | 304 // We have enough information to initialize page_number_. |
305 page_number_.Init(document_->settings(), page_count); | 305 page_number_.Init(document_->settings(), page_count); |
306 if (destination_.get() != NULL) | 306 if (destination_.get() != NULL) |
307 destination_->SetPageCount(page_count); | 307 destination_->SetPageCount(page_count); |
308 } | 308 } |
309 DCHECK_NE(page_number_, PageNumber::npos()); | 309 DCHECK_NE(page_number_, PageNumber::npos()); |
310 | 310 |
311 while (true) { | 311 while (true) { |
312 // Is the page available? | 312 // Is the page available? |
313 scoped_refptr<PrintedPage> page = document_->GetPage(page_number_.ToInt()); | 313 scoped_refptr<PrintedPage> page = document_->GetPage(page_number_.ToInt()); |
314 if (!page) { | 314 if (!page.get()) { |
315 // We need to wait for the page to be available. | 315 // We need to wait for the page to be available. |
316 base::MessageLoop::current()->PostDelayedTask( | 316 base::MessageLoop::current()->PostDelayedTask( |
317 FROM_HERE, | 317 FROM_HERE, |
318 base::Bind(&PrintJobWorker::OnNewPage, weak_factory_.GetWeakPtr()), | 318 base::Bind(&PrintJobWorker::OnNewPage, weak_factory_.GetWeakPtr()), |
319 base::TimeDelta::FromMilliseconds(500)); | 319 base::TimeDelta::FromMilliseconds(500)); |
320 break; | 320 break; |
321 } | 321 } |
322 // The page is there, print it. | 322 // The page is there, print it. |
323 SpoolPage(page.get()); | 323 SpoolPage(page.get()); |
324 ++page_number_; | 324 ++page_number_; |
(...skipping 11 matching lines...) Expand all Loading... |
336 // Cannot touch any member variable since we don't know in which thread | 336 // Cannot touch any member variable since we don't know in which thread |
337 // context we run. | 337 // context we run. |
338 } | 338 } |
339 | 339 |
340 bool PrintJobWorker::IsRunning() const { | 340 bool PrintJobWorker::IsRunning() const { |
341 return thread_.IsRunning(); | 341 return thread_.IsRunning(); |
342 } | 342 } |
343 | 343 |
344 bool PrintJobWorker::PostTask(const tracked_objects::Location& from_here, | 344 bool PrintJobWorker::PostTask(const tracked_objects::Location& from_here, |
345 const base::Closure& task) { | 345 const base::Closure& task) { |
346 if (task_runner_) | 346 if (task_runner_.get()) |
347 return task_runner_->PostTask(from_here, task); | 347 return task_runner_->PostTask(from_here, task); |
348 return false; | 348 return false; |
349 } | 349 } |
350 | 350 |
351 void PrintJobWorker::StopSoon() { | 351 void PrintJobWorker::StopSoon() { |
352 thread_.StopSoon(); | 352 thread_.StopSoon(); |
353 } | 353 } |
354 | 354 |
355 void PrintJobWorker::Stop() { | 355 void PrintJobWorker::Stop() { |
356 thread_.Stop(); | 356 thread_.Stop(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 document_, | 448 document_, |
449 scoped_refptr<PrintedPage>())); | 449 scoped_refptr<PrintedPage>())); |
450 Cancel(); | 450 Cancel(); |
451 | 451 |
452 // Makes sure the variables are reinitialized. | 452 // Makes sure the variables are reinitialized. |
453 document_ = NULL; | 453 document_ = NULL; |
454 page_number_ = PageNumber::npos(); | 454 page_number_ = PageNumber::npos(); |
455 } | 455 } |
456 | 456 |
457 } // namespace printing | 457 } // namespace printing |
OLD | NEW |