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.h" | 11 #include "base/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/printing/print_job.h" | 14 #include "chrome/browser/printing/print_job.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "grit/generated_resources.h" |
| 19 #include "printing/backend/print_backend.h" |
18 #include "printing/print_job_constants.h" | 20 #include "printing/print_job_constants.h" |
19 #include "printing/printed_document.h" | 21 #include "printing/printed_document.h" |
20 #include "printing/printed_page.h" | 22 #include "printing/printed_page.h" |
| 23 #include "ui/base/l10n/l10n_util.h" |
21 | 24 |
22 using content::BrowserThread; | 25 using content::BrowserThread; |
23 | 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 // Helper function to ensure |owner| is valid until at least |callback| returns. | 29 // Helper function to ensure |owner| is valid until at least |callback| returns. |
27 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, | 30 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, |
28 const base::Closure& callback) { | 31 const base::Closure& callback) { |
29 callback.Run(); | 32 callback.Run(); |
30 } | 33 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 DCHECK_EQ(page_number_, PageNumber::npos()); | 198 DCHECK_EQ(page_number_, PageNumber::npos()); |
196 DCHECK_EQ(document_, new_document); | 199 DCHECK_EQ(document_, new_document); |
197 DCHECK(document_.get()); | 200 DCHECK(document_.get()); |
198 DCHECK(new_document->settings().Equals(printing_context_->settings())); | 201 DCHECK(new_document->settings().Equals(printing_context_->settings())); |
199 | 202 |
200 if (!document_.get() || page_number_ != PageNumber::npos() || | 203 if (!document_.get() || page_number_ != PageNumber::npos() || |
201 document_ != new_document) { | 204 document_ != new_document) { |
202 return; | 205 return; |
203 } | 206 } |
204 | 207 |
| 208 string16 document_name = |
| 209 printing::PrintBackend::SimplifyDocumentTitle(document_->name()); |
| 210 if (document_name.empty()) { |
| 211 document_name = printing::PrintBackend::SimplifyDocumentTitle( |
| 212 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)); |
| 213 } |
205 PrintingContext::Result result = | 214 PrintingContext::Result result = |
206 printing_context_->NewDocument(document_->name()); | 215 printing_context_->NewDocument(document_name); |
207 if (result != PrintingContext::OK) { | 216 if (result != PrintingContext::OK) { |
208 OnFailure(); | 217 OnFailure(); |
209 return; | 218 return; |
210 } | 219 } |
211 | 220 |
212 // Try to print already cached data. It may already have been generated for | 221 // Try to print already cached data. It may already have been generated for |
213 // the print preview. | 222 // the print preview. |
214 OnNewPage(); | 223 OnNewPage(); |
215 // Don't touch this anymore since the instance could be destroyed. It happens | 224 // Don't touch this anymore since the instance could be destroyed. It happens |
216 // if all the pages are printed a one sweep and the client doesn't have a | 225 // if all the pages are printed a one sweep and the client doesn't have a |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 JobEventDetails::FAILED, document_, | 370 JobEventDetails::FAILED, document_, |
362 scoped_refptr<PrintedPage>())); | 371 scoped_refptr<PrintedPage>())); |
363 Cancel(); | 372 Cancel(); |
364 | 373 |
365 // Makes sure the variables are reinitialized. | 374 // Makes sure the variables are reinitialized. |
366 document_ = NULL; | 375 document_ = NULL; |
367 page_number_ = PageNumber::npos(); | 376 page_number_ = PageNumber::npos(); |
368 } | 377 } |
369 | 378 |
370 } // namespace printing | 379 } // namespace printing |
OLD | NEW |