| 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/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 bool external_preview = false; | 272 bool external_preview = false; |
| 273 if (settings.GetBoolean(printing::kSettingOpenPDFInPreview, | 273 if (settings.GetBoolean(printing::kSettingOpenPDFInPreview, |
| 274 &external_preview) && external_preview) { | 274 &external_preview) && external_preview) { |
| 275 ReportPrintSettingHistogram(EXTERNAL_PDF_PREVIEW); | 275 ReportPrintSettingHistogram(EXTERNAL_PDF_PREVIEW); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Callback that stores a PDF file on disk. | 279 // Callback that stores a PDF file on disk. |
| 280 void PrintToPdfCallback(printing::Metafile* metafile, | 280 void PrintToPdfCallback(printing::Metafile* metafile, |
| 281 const base::FilePath& path) { | 281 const base::FilePath& path, |
| 282 const base::Closure& pdf_file_saved_closure) { |
| 282 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 283 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 283 metafile->SaveTo(path); | 284 metafile->SaveTo(path); |
| 284 // |metafile| must be deleted on the UI thread. | 285 // |metafile| must be deleted on the UI thread. |
| 285 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, metafile); | 286 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, metafile); |
| 287 if (!pdf_file_saved_closure.is_null()) |
| 288 pdf_file_saved_closure.Run(); |
| 286 } | 289 } |
| 287 | 290 |
| 288 std::string GetDefaultPrinterOnFileThread() { | 291 std::string GetDefaultPrinterOnFileThread() { |
| 289 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 292 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 290 | 293 |
| 291 scoped_refptr<printing::PrintBackend> print_backend( | 294 scoped_refptr<printing::PrintBackend> print_backend( |
| 292 printing::PrintBackend::CreateInstance(NULL)); | 295 printing::PrintBackend::CreateInstance(NULL)); |
| 293 | 296 |
| 294 std::string default_printer = print_backend->GetDefaultPrinterName(); | 297 std::string default_printer = print_backend->GetDefaultPrinterName(); |
| 295 VLOG(1) << "Default Printer: " << default_printer; | 298 VLOG(1) << "Default Printer: " << default_printer; |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 scoped_refptr<base::RefCountedBytes> data; | 1368 scoped_refptr<base::RefCountedBytes> data; |
| 1366 base::string16 title; | 1369 base::string16 title; |
| 1367 if (!GetPreviewDataAndTitle(&data, &title)) { | 1370 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 1368 NOTREACHED() << "Preview data was checked before file dialog."; | 1371 NOTREACHED() << "Preview data was checked before file dialog."; |
| 1369 return; | 1372 return; |
| 1370 } | 1373 } |
| 1371 scoped_ptr<printing::PreviewMetafile> metafile(new printing::PreviewMetafile); | 1374 scoped_ptr<printing::PreviewMetafile> metafile(new printing::PreviewMetafile); |
| 1372 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 1375 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
| 1373 BrowserThread::PostTask( | 1376 BrowserThread::PostTask( |
| 1374 BrowserThread::FILE, FROM_HERE, | 1377 BrowserThread::FILE, FROM_HERE, |
| 1375 base::Bind(&PrintToPdfCallback, metafile.release(), print_to_pdf_path_)); | 1378 base::Bind(&PrintToPdfCallback, |
| 1379 metafile.release(), |
| 1380 print_to_pdf_path_, |
| 1381 pdf_file_saved_closure_)); |
| 1376 print_to_pdf_path_ = base::FilePath(); | 1382 print_to_pdf_path_ = base::FilePath(); |
| 1377 ClosePreviewDialog(); | 1383 ClosePreviewDialog(); |
| 1378 } | 1384 } |
| 1379 | 1385 |
| 1380 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 1386 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
| 1381 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 1387 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 1382 web_ui()->GetController()); | 1388 web_ui()->GetController()); |
| 1383 print_preview_ui->OnFileSelectionCancelled(); | 1389 print_preview_ui->OnFileSelectionCancelled(); |
| 1384 } | 1390 } |
| 1385 | 1391 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile); | 1630 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile); |
| 1625 if (reconcilor_) | 1631 if (reconcilor_) |
| 1626 reconcilor_->AddMergeSessionObserver(this); | 1632 reconcilor_->AddMergeSessionObserver(this); |
| 1627 } | 1633 } |
| 1628 } | 1634 } |
| 1629 | 1635 |
| 1630 void PrintPreviewHandler::UnregisterForMergeSession() { | 1636 void PrintPreviewHandler::UnregisterForMergeSession() { |
| 1631 if (reconcilor_) | 1637 if (reconcilor_) |
| 1632 reconcilor_->RemoveMergeSessionObserver(this); | 1638 reconcilor_->RemoveMergeSessionObserver(this); |
| 1633 } | 1639 } |
| 1640 |
| 1641 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1642 const base::Closure& closure) { |
| 1643 pdf_file_saved_closure_ = closure; |
| 1644 } |
| OLD | NEW |