| 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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/printing/print_job.h" | 15 #include "chrome/browser/printing/print_job.h" |
| 16 #include "chrome/browser/printing/printing_ui_web_contents_observer.h" | 16 #include "chrome/browser/printing/printing_ui_web_contents_observer.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "printing/backend/print_backend.h" | |
| 21 #include "printing/print_job_constants.h" | 20 #include "printing/print_job_constants.h" |
| 22 #include "printing/printed_document.h" | 21 #include "printing/printed_document.h" |
| 23 #include "printing/printed_page.h" | 22 #include "printing/printed_page.h" |
| 23 #include "printing/printing_utils.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Helper function to ensure |owner| is valid until at least |callback| returns. | 30 // Helper function to ensure |owner| is valid until at least |callback| returns. |
| 31 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, | 31 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, |
| 32 const base::Closure& callback) { | 32 const base::Closure& callback) { |
| 33 callback.Run(); | 33 callback.Run(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 DCHECK_EQ(page_number_, PageNumber::npos()); | 208 DCHECK_EQ(page_number_, PageNumber::npos()); |
| 209 DCHECK_EQ(document_, new_document); | 209 DCHECK_EQ(document_, new_document); |
| 210 DCHECK(document_.get()); | 210 DCHECK(document_.get()); |
| 211 | 211 |
| 212 if (!document_.get() || page_number_ != PageNumber::npos() || | 212 if (!document_.get() || page_number_ != PageNumber::npos() || |
| 213 document_.get() != new_document) { | 213 document_.get() != new_document) { |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 | 216 |
| 217 string16 document_name = | 217 string16 document_name = |
| 218 printing::PrintBackend::SimplifyDocumentTitle(document_->name()); | 218 printing::SimplifyDocumentTitle(document_->name()); |
| 219 if (document_name.empty()) { | 219 if (document_name.empty()) { |
| 220 document_name = printing::PrintBackend::SimplifyDocumentTitle( | 220 document_name = printing::SimplifyDocumentTitle( |
| 221 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)); | 221 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)); |
| 222 } | 222 } |
| 223 PrintingContext::Result result = | 223 PrintingContext::Result result = |
| 224 printing_context_->NewDocument(document_name); | 224 printing_context_->NewDocument(document_name); |
| 225 if (result != PrintingContext::OK) { | 225 if (result != PrintingContext::OK) { |
| 226 OnFailure(); | 226 OnFailure(); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Try to print already cached data. It may already have been generated for | 230 // Try to print already cached data. It may already have been generated for |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 JobEventDetails::FAILED, document_, | 377 JobEventDetails::FAILED, document_, |
| 378 scoped_refptr<PrintedPage>())); | 378 scoped_refptr<PrintedPage>())); |
| 379 Cancel(); | 379 Cancel(); |
| 380 | 380 |
| 381 // Makes sure the variables are reinitialized. | 381 // Makes sure the variables are reinitialized. |
| 382 document_ = NULL; | 382 document_ = NULL; |
| 383 page_number_ = PageNumber::npos(); | 383 page_number_ = PageNumber::npos(); |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace printing | 386 } // namespace printing |
| OLD | NEW |