Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 2542363002: Interrogate PpdProvider from PrintPreview. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 511
512 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); 512 DISALLOW_COPY_AND_ASSIGN(AccessTokenService);
513 }; 513 };
514 514
515 PrintPreviewHandler::PrintPreviewHandler() 515 PrintPreviewHandler::PrintPreviewHandler()
516 : regenerate_preview_request_count_(0), 516 : regenerate_preview_request_count_(0),
517 manage_printers_dialog_request_count_(0), 517 manage_printers_dialog_request_count_(0),
518 manage_cloud_printers_dialog_request_count_(0), 518 manage_cloud_printers_dialog_request_count_(0),
519 reported_failed_preview_(false), 519 reported_failed_preview_(false),
520 has_logged_printers_count_(false), 520 has_logged_printers_count_(false),
521 gaia_cookie_manager_service_(NULL), 521 gaia_cookie_manager_service_(nullptr),
522 printer_backend_proxy_(nullptr),
522 weak_factory_(this) { 523 weak_factory_(this) {
523 ReportUserActionHistogram(PREVIEW_STARTED); 524 ReportUserActionHistogram(PREVIEW_STARTED);
524 } 525 }
525 526
526 PrintPreviewHandler::~PrintPreviewHandler() { 527 PrintPreviewHandler::~PrintPreviewHandler() {
527 if (select_file_dialog_.get()) 528 if (select_file_dialog_.get())
528 select_file_dialog_->ListenerDestroyed(); 529 select_file_dialog_->ListenerDestroyed();
529 530
530 UnregisterForGaiaCookieChanges(); 531 UnregisterForGaiaCookieChanges();
531 } 532 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 605 }
605 606
606 WebContents* PrintPreviewHandler::preview_web_contents() const { 607 WebContents* PrintPreviewHandler::preview_web_contents() const {
607 return web_ui()->GetWebContents(); 608 return web_ui()->GetWebContents();
608 } 609 }
609 610
610 PrintPreviewUI* PrintPreviewHandler::print_preview_ui() const { 611 PrintPreviewUI* PrintPreviewHandler::print_preview_ui() const {
611 return static_cast<PrintPreviewUI*>(web_ui()->GetController()); 612 return static_cast<PrintPreviewUI*>(web_ui()->GetController());
612 } 613 }
613 614
615 printing::PrinterBackendProxy* PrintPreviewHandler::printer_backend_proxy() {
Carlson 2016/12/02 19:10:22 This should run on the UI thread, right? Add a DC
skau 2016/12/05 23:13:34 No. The proxy is actually designed to run on the
Carlson 2016/12/05 23:45:58 I don't understand your response here. Is this fu
skau 2016/12/06 23:20:08 I misread your comment. I've added the DCHECK. I
616 if (!printer_backend_proxy_) {
617 #if defined(OS_CHROMEOS)
618 printer_backend_proxy_ =
619 printing::PrinterBackendProxy::Create(Profile::FromWebUI(web_ui()));
Carlson 2016/12/02 19:10:22 The reason for the multiplexing of proxies here de
skau 2016/12/05 23:13:34 Done.
620 #else
621 printer_backend_proxy_ = printing::PrinterBackendProxy::Create();
622 #endif
623 }
624
625 return printer_backend_proxy_.get();
626 }
627
614 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { 628 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) {
615 VLOG(1) << "Enumerate printers start"; 629 VLOG(1) << "Enumerate printers start";
616 printing::EnumeratePrinters(Profile::FromWebUI(web_ui()), 630 printer_backend_proxy()->EnumeratePrinters(base::Bind(
617 base::Bind(&PrintPreviewHandler::SetupPrinterList, 631 &PrintPreviewHandler::SetupPrinterList, weak_factory_.GetWeakPtr()));
618 weak_factory_.GetWeakPtr()));
619 } 632 }
620 633
621 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { 634 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) {
622 if (!PrivetPrintingEnabled()) 635 if (!PrivetPrintingEnabled())
623 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone"); 636 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone");
624 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) 637 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
625 using local_discovery::ServiceDiscoverySharedClient; 638 using local_discovery::ServiceDiscoverySharedClient;
626 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = 639 scoped_refptr<ServiceDiscoverySharedClient> service_discovery =
627 ServiceDiscoverySharedClient::GetInstance(); 640 ServiceDiscoverySharedClient::GetInstance();
628 StartPrivetLister(service_discovery); 641 StartPrivetLister(service_discovery);
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 printing::kPrinterCapabilities, 1035 printing::kPrinterCapabilities,
1023 GetPdfCapabilities(g_browser_process->GetApplicationLocale())); 1036 GetPdfCapabilities(g_browser_process->GetApplicationLocale()));
1024 SendPrinterCapabilities(printer_name, std::move(printer_info)); 1037 SendPrinterCapabilities(printer_name, std::move(printer_info));
1025 return; 1038 return;
1026 } 1039 }
1027 1040
1028 printing::PrinterSetupCallback cb = 1041 printing::PrinterSetupCallback cb =
1029 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, 1042 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities,
1030 weak_factory_.GetWeakPtr(), printer_name); 1043 weak_factory_.GetWeakPtr(), printer_name);
1031 1044
1032 printing::ConfigurePrinterAndFetchCapabilities(Profile::FromWebUI(web_ui()), 1045 printer_backend_proxy()->ConfigurePrinterAndFetchCapabilities(printer_name,
1033 printer_name, cb); 1046 cb);
1034 } 1047 }
1035 1048
1036 void PrintPreviewHandler::OnSigninComplete() { 1049 void PrintPreviewHandler::OnSigninComplete() {
1037 if (print_preview_ui()) 1050 if (print_preview_ui())
1038 print_preview_ui()->OnReloadPrintersList(); 1051 print_preview_ui()->OnReloadPrintersList();
1039 } 1052 }
1040 1053
1041 void PrintPreviewHandler::HandleSignin(const base::ListValue* args) { 1054 void PrintPreviewHandler::HandleSignin(const base::ListValue* args) {
1042 bool add_account = false; 1055 bool add_account = false;
1043 bool success = args->GetBoolean(0, &add_account); 1056 bool success = args->GetBoolean(0, &add_account);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2)); 1160 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2));
1148 settings->SetInteger(kMeasurementSystem, system); 1161 settings->SetInteger(kMeasurementSystem, system);
1149 } 1162 }
1150 1163
1151 void PrintPreviewHandler::HandleGetInitialSettings( 1164 void PrintPreviewHandler::HandleGetInitialSettings(
1152 const base::ListValue* /*args*/) { 1165 const base::ListValue* /*args*/) {
1153 // Send before SendInitialSettings() to allow cloud printer auto select. 1166 // Send before SendInitialSettings() to allow cloud printer auto select.
1154 SendCloudPrintEnabled(); 1167 SendCloudPrintEnabled();
1155 base::PostTaskAndReplyWithResult( 1168 base::PostTaskAndReplyWithResult(
1156 BrowserThread::GetBlockingPool(), FROM_HERE, 1169 BrowserThread::GetBlockingPool(), FROM_HERE,
1157 base::Bind(&printing::GetDefaultPrinterOnBlockingPoolThread), 1170 base::Bind(
Carlson 2016/12/02 19:10:22 Is this safe? The second bind is weak ptr based,
skau 2016/12/05 23:13:34 I need to think about this a little. WeakPtrs are
skau 2016/12/06 23:20:08 This has been fixed so that we dispatch the call f
1171 &printing::PrinterBackendProxy::GetDefaultPrinterOnBlockingPoolThread,
1172 base::Unretained(printer_backend_proxy())),
1158 base::Bind(&PrintPreviewHandler::SendInitialSettings, 1173 base::Bind(&PrintPreviewHandler::SendInitialSettings,
1159 weak_factory_.GetWeakPtr())); 1174 weak_factory_.GetWeakPtr()));
1160 } 1175 }
1161 1176
1162 void PrintPreviewHandler::HandleForceOpenNewTab(const base::ListValue* args) { 1177 void PrintPreviewHandler::HandleForceOpenNewTab(const base::ListValue* args) {
1163 std::string url; 1178 std::string url;
1164 if (!args->GetString(0, &url)) 1179 if (!args->GetString(0, &url))
1165 return; 1180 return;
1166 Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator()); 1181 Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator());
1167 if (!browser) 1182 if (!browser)
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 1717
1703 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { 1718 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
1704 if (gaia_cookie_manager_service_) 1719 if (gaia_cookie_manager_service_)
1705 gaia_cookie_manager_service_->RemoveObserver(this); 1720 gaia_cookie_manager_service_->RemoveObserver(this);
1706 } 1721 }
1707 1722
1708 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1723 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1709 const base::Closure& closure) { 1724 const base::Closure& closure) {
1710 pdf_file_saved_closure_ = closure; 1725 pdf_file_saved_closure_ = closure;
1711 } 1726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698