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

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

Issue 2919693002: Print Preview: Change getPrinters to cr.sendWithPromise (Closed)
Patch Set: Address comments Created 3 years, 6 months 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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 printer_backend_proxy_ = 654 printer_backend_proxy_ =
655 printing::PrinterBackendProxy::Create(Profile::FromWebUI(web_ui())); 655 printing::PrinterBackendProxy::Create(Profile::FromWebUI(web_ui()));
656 #else 656 #else
657 printer_backend_proxy_ = printing::PrinterBackendProxy::Create(); 657 printer_backend_proxy_ = printing::PrinterBackendProxy::Create();
658 #endif 658 #endif
659 } 659 }
660 660
661 return printer_backend_proxy_.get(); 661 return printer_backend_proxy_.get();
662 } 662 }
663 663
664 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { 664 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* args) {
665 VLOG(1) << "Enumerate printers start"; 665 VLOG(1) << "Enumerate printers start";
666 printer_backend_proxy()->EnumeratePrinters(base::Bind( 666 std::string callback_id;
667 &PrintPreviewHandler::SetupPrinterList, weak_factory_.GetWeakPtr())); 667 CHECK(args->GetString(0, &callback_id));
668 CHECK(!callback_id.empty());
669
670 AllowJavascript();
671
672 printer_backend_proxy()->EnumeratePrinters(
673 base::Bind(&PrintPreviewHandler::SetupPrinterList,
674 weak_factory_.GetWeakPtr(), callback_id));
668 } 675 }
669 676
670 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { 677 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) {
671 if (!PrivetPrintingEnabled()) 678 if (!PrivetPrintingEnabled())
672 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone"); 679 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone");
673 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) 680 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
674 using local_discovery::ServiceDiscoverySharedClient; 681 using local_discovery::ServiceDiscoverySharedClient;
675 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = 682 scoped_refptr<ServiceDiscoverySharedClient> service_discovery =
676 ServiceDiscoverySharedClient::GetInstance(); 683 ServiceDiscoverySharedClient::GetInstance();
677 StartPrivetLister(service_discovery); 684 StartPrivetLister(service_discovery);
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 } 1325 }
1319 1326
1320 response->SetString("printerId", printer_name); 1327 response->SetString("printerId", printer_name);
1321 response->SetBoolean("success", success); 1328 response->SetBoolean("success", success);
1322 response->Set("capabilities", std::move(caps)); 1329 response->Set("capabilities", std::move(caps));
1323 1330
1324 ResolveJavascriptCallback(base::Value(callback_id), *response); 1331 ResolveJavascriptCallback(base::Value(callback_id), *response);
1325 } 1332 }
1326 1333
1327 void PrintPreviewHandler::SetupPrinterList( 1334 void PrintPreviewHandler::SetupPrinterList(
1335 const std::string& callback_id,
1328 const printing::PrinterList& printer_list) { 1336 const printing::PrinterList& printer_list) {
1329 base::ListValue printers; 1337 base::ListValue printers;
1330 PrintersToValues(printer_list, &printers); 1338 PrintersToValues(printer_list, &printers);
1331 1339
1332 VLOG(1) << "Enumerate printers finished, found " << printers.GetSize() 1340 VLOG(1) << "Enumerate printers finished, found " << printers.GetSize()
1333 << " printers"; 1341 << " printers";
1334 1342
1335 if (!has_logged_printers_count_) { 1343 if (!has_logged_printers_count_) {
1336 UMA_HISTOGRAM_COUNTS("PrintPreview.NumberOfPrinters", printers.GetSize()); 1344 UMA_HISTOGRAM_COUNTS("PrintPreview.NumberOfPrinters", printers.GetSize());
1337 has_logged_printers_count_ = true; 1345 has_logged_printers_count_ = true;
1338 } 1346 }
1339 1347
1340 web_ui()->CallJavascriptFunctionUnsafe("setPrinters", printers); 1348 ResolveJavascriptCallback(base::Value(callback_id), printers);
1341 } 1349 }
1342 1350
1343 void PrintPreviewHandler::SendCloudPrintEnabled() { 1351 void PrintPreviewHandler::SendCloudPrintEnabled() {
1344 Profile* profile = Profile::FromBrowserContext( 1352 Profile* profile = Profile::FromBrowserContext(
1345 preview_web_contents()->GetBrowserContext()); 1353 preview_web_contents()->GetBrowserContext());
1346 PrefService* prefs = profile->GetPrefs(); 1354 PrefService* prefs = profile->GetPrefs();
1347 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { 1355 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) {
1348 base::DictionaryValue settings; 1356 base::DictionaryValue settings;
1349 settings.SetString(kCloudPrintUrl, 1357 settings.SetString(kCloudPrintUrl,
1350 GURL(cloud_devices::GetCloudPrintURL()).spec()); 1358 GURL(cloud_devices::GetCloudPrintURL()).spec());
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 1793
1786 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { 1794 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
1787 if (gaia_cookie_manager_service_) 1795 if (gaia_cookie_manager_service_)
1788 gaia_cookie_manager_service_->RemoveObserver(this); 1796 gaia_cookie_manager_service_->RemoveObserver(this);
1789 } 1797 }
1790 1798
1791 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1799 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1792 const base::Closure& closure) { 1800 const base::Closure& closure) {
1793 pdf_file_saved_closure_ = closure; 1801 pdf_file_saved_closure_ = closure;
1794 } 1802 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698