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

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

Issue 2407483002: Make enable_service_discovery a chrome/ feature. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_handler.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 #include "printing/printing_context.h" 83 #include "printing/printing_context.h"
84 #include "printing/units.h" 84 #include "printing/units.h"
85 #include "third_party/icu/source/i18n/unicode/ulocdata.h" 85 #include "third_party/icu/source/i18n/unicode/ulocdata.h"
86 86
87 #if defined(OS_CHROMEOS) 87 #if defined(OS_CHROMEOS)
88 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 88 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
89 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 89 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
90 #include "chrome/common/url_constants.h" 90 #include "chrome/common/url_constants.h"
91 #endif 91 #endif
92 92
93 #if defined(ENABLE_SERVICE_DISCOVERY) 93 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
94 #include "chrome/browser/printing/cloud_print/privet_constants.h" 94 #include "chrome/browser/printing/cloud_print/privet_constants.h"
95 #endif 95 #endif
96 96
97 using content::BrowserThread; 97 using content::BrowserThread;
98 using content::RenderViewHost; 98 using content::RenderViewHost;
99 using content::WebContents; 99 using content::WebContents;
100 100
101 namespace { 101 namespace {
102 102
103 enum UserActionBuckets { 103 enum UserActionBuckets {
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 base::FilePath unique_path = path; 494 base::FilePath unique_path = path;
495 int uniquifier = 495 int uniquifier =
496 base::GetUniquePathNumber(path, base::FilePath::StringType()); 496 base::GetUniquePathNumber(path, base::FilePath::StringType());
497 if (uniquifier > 0) { 497 if (uniquifier > 0) {
498 unique_path = unique_path.InsertBeforeExtensionASCII( 498 unique_path = unique_path.InsertBeforeExtensionASCII(
499 base::StringPrintf(" (%d)", uniquifier)); 499 base::StringPrintf(" (%d)", uniquifier));
500 } 500 }
501 return unique_path; 501 return unique_path;
502 } 502 }
503 503
504 bool PrivetPrintingEnabled() {
505 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
506 return true;
507 #else
508 return false;
509 #endif
510 }
511
504 } // namespace 512 } // namespace
505 513
506 class PrintPreviewHandler::AccessTokenService 514 class PrintPreviewHandler::AccessTokenService
507 : public OAuth2TokenService::Consumer { 515 : public OAuth2TokenService::Consumer {
508 public: 516 public:
509 explicit AccessTokenService(PrintPreviewHandler* handler) 517 explicit AccessTokenService(PrintPreviewHandler* handler)
510 : OAuth2TokenService::Consumer("print_preview"), 518 : OAuth2TokenService::Consumer("print_preview"),
511 handler_(handler) { 519 handler_(handler) {
512 } 520 }
513 521
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 "getExtensionPrinterCapabilities", 670 "getExtensionPrinterCapabilities",
663 base::Bind(&PrintPreviewHandler::HandleGetExtensionPrinterCapabilities, 671 base::Bind(&PrintPreviewHandler::HandleGetExtensionPrinterCapabilities,
664 base::Unretained(this))); 672 base::Unretained(this)));
665 web_ui()->RegisterMessageCallback( 673 web_ui()->RegisterMessageCallback(
666 "grantExtensionPrinterAccess", 674 "grantExtensionPrinterAccess",
667 base::Bind(&PrintPreviewHandler::HandleGrantExtensionPrinterAccess, 675 base::Bind(&PrintPreviewHandler::HandleGrantExtensionPrinterAccess,
668 base::Unretained(this))); 676 base::Unretained(this)));
669 RegisterForGaiaCookieChanges(); 677 RegisterForGaiaCookieChanges();
670 } 678 }
671 679
672 bool PrintPreviewHandler::PrivetPrintingEnabled() {
673 #if defined(ENABLE_SERVICE_DISCOVERY)
674 return true;
675 #else
676 return false;
677 #endif
678 }
679
680 WebContents* PrintPreviewHandler::preview_web_contents() const { 680 WebContents* PrintPreviewHandler::preview_web_contents() const {
681 return web_ui()->GetWebContents(); 681 return web_ui()->GetWebContents();
682 } 682 }
683 683
684 PrintPreviewUI* PrintPreviewHandler::print_preview_ui() const { 684 PrintPreviewUI* PrintPreviewHandler::print_preview_ui() const {
685 return static_cast<PrintPreviewUI*>(web_ui()->GetController()); 685 return static_cast<PrintPreviewUI*>(web_ui()->GetController());
686 } 686 }
687 687
688 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) { 688 void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) {
689 base::ListValue* results = new base::ListValue; 689 base::ListValue* results = new base::ListValue;
690 BrowserThread::PostBlockingPoolTaskAndReply( 690 BrowserThread::PostBlockingPoolTaskAndReply(
691 FROM_HERE, base::Bind(&EnumeratePrintersOnBlockingPoolThread, 691 FROM_HERE, base::Bind(&EnumeratePrintersOnBlockingPoolThread,
692 base::Unretained(results)), 692 base::Unretained(results)),
693 base::Bind(&PrintPreviewHandler::SetupPrinterList, 693 base::Bind(&PrintPreviewHandler::SetupPrinterList,
694 weak_factory_.GetWeakPtr(), base::Owned(results))); 694 weak_factory_.GetWeakPtr(), base::Owned(results)));
695 } 695 }
696 696
697 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { 697 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) {
698 if (!PrivetPrintingEnabled()) 698 if (!PrivetPrintingEnabled())
699 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone"); 699 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone");
700 #if defined(ENABLE_SERVICE_DISCOVERY) 700 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
701 using local_discovery::ServiceDiscoverySharedClient; 701 using local_discovery::ServiceDiscoverySharedClient;
702 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = 702 scoped_refptr<ServiceDiscoverySharedClient> service_discovery =
703 ServiceDiscoverySharedClient::GetInstance(); 703 ServiceDiscoverySharedClient::GetInstance();
704 StartPrivetLister(service_discovery); 704 StartPrivetLister(service_discovery);
705 #endif // ENABLE_SERVICE_DISCOVERY 705 #endif
706 } 706 }
707 707
708 void PrintPreviewHandler::HandleStopGetPrivetPrinters( 708 void PrintPreviewHandler::HandleStopGetPrivetPrinters(
709 const base::ListValue* args) { 709 const base::ListValue* args) {
710 #if defined(ENABLE_SERVICE_DISCOVERY) 710 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
711 if (PrivetPrintingEnabled() && printer_lister_) { 711 if (PrivetPrintingEnabled() && printer_lister_) {
712 printer_lister_->Stop(); 712 printer_lister_->Stop();
713 } 713 }
714 #endif 714 #endif
715 } 715 }
716 716
717 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( 717 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities(
718 const base::ListValue* args) { 718 const base::ListValue* args) {
719 #if defined(ENABLE_SERVICE_DISCOVERY) 719 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
720 std::string name; 720 std::string name;
721 bool success = args->GetString(0, &name); 721 bool success = args->GetString(0, &name);
722 DCHECK(success); 722 DCHECK(success);
723 723
724 CreatePrivetHTTP( 724 CreatePrivetHTTP(
725 name, 725 name,
726 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient, 726 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient,
727 base::Unretained(this))); 727 base::Unretained(this)));
728 #endif 728 #endif
729 } 729 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 int page_count = 0; 883 int page_count = 0;
884 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); 884 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count);
885 885
886 if (print_to_pdf) { 886 if (print_to_pdf) {
887 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); 887 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count);
888 ReportUserActionHistogram(PRINT_TO_PDF); 888 ReportUserActionHistogram(PRINT_TO_PDF);
889 PrintToPdf(); 889 PrintToPdf();
890 return; 890 return;
891 } 891 }
892 892
893 #if defined(ENABLE_SERVICE_DISCOVERY) 893 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
894 if (print_with_privet && PrivetPrintingEnabled()) { 894 if (print_with_privet && PrivetPrintingEnabled()) {
895 std::string printer_name; 895 std::string printer_name;
896 std::string print_ticket; 896 std::string print_ticket;
897 std::string capabilities; 897 std::string capabilities;
898 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count); 898 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count);
899 ReportUserActionHistogram(PRINT_WITH_PRIVET); 899 ReportUserActionHistogram(PRINT_WITH_PRIVET);
900 900
901 int width = 0; 901 int width = 0;
902 int height = 0; 902 int height = 0;
903 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || 903 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) ||
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 // Nothing to print, no preview available. 1478 // Nothing to print, no preview available.
1479 return false; 1479 return false;
1480 } 1480 }
1481 DCHECK(tmp_data->size() && tmp_data->front()); 1481 DCHECK(tmp_data->size() && tmp_data->front());
1482 1482
1483 *data = tmp_data; 1483 *data = tmp_data;
1484 *title = print_preview_ui()->initiator_title(); 1484 *title = print_preview_ui()->initiator_title();
1485 return true; 1485 return true;
1486 } 1486 }
1487 1487
1488 #if defined(ENABLE_SERVICE_DISCOVERY) 1488 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
1489
1490 void PrintPreviewHandler::StartPrivetLister(const scoped_refptr< 1489 void PrintPreviewHandler::StartPrivetLister(const scoped_refptr<
1491 local_discovery::ServiceDiscoverySharedClient>& client) { 1490 local_discovery::ServiceDiscoverySharedClient>& client) {
1492 if (!PrivetPrintingEnabled()) 1491 if (!PrivetPrintingEnabled())
1493 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone"); 1492 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone");
1494 1493
1495 Profile* profile = Profile::FromWebUI(web_ui()); 1494 Profile* profile = Profile::FromWebUI(web_ui());
1496 DCHECK(!service_discovery_client_.get() || 1495 DCHECK(!service_discovery_client_.get() ||
1497 service_discovery_client_.get() == client.get()); 1496 service_discovery_client_.get() == client.get());
1498 service_discovery_client_ = client; 1497 service_discovery_client_ = client;
1499 printer_lister_.reset(new cloud_print::PrivetLocalPrinterLister( 1498 printer_lister_.reset(new cloud_print::PrivetLocalPrinterLister(
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 1686
1688 printer_value->SetString("serviceName", name); 1687 printer_value->SetString("serviceName", name);
1689 printer_value->SetString("name", description.name); 1688 printer_value->SetString("name", description.name);
1690 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); 1689 printer_value->SetBoolean("hasLocalPrinting", has_local_printing);
1691 printer_value->SetBoolean( 1690 printer_value->SetBoolean(
1692 "isUnregistered", 1691 "isUnregistered",
1693 description.id.empty() && 1692 description.id.empty() &&
1694 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); 1693 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos));
1695 printer_value->SetString("cloudID", description.id); 1694 printer_value->SetString("cloudID", description.id);
1696 } 1695 }
1697 1696 #endif // BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
1698 #endif // defined(ENABLE_SERVICE_DISCOVERY)
1699 1697
1700 void PrintPreviewHandler::EnsureExtensionPrinterHandlerSet() { 1698 void PrintPreviewHandler::EnsureExtensionPrinterHandlerSet() {
1701 if (extension_printer_handler_) 1699 if (extension_printer_handler_)
1702 return; 1700 return;
1703 1701
1704 extension_printer_handler_ = 1702 extension_printer_handler_ =
1705 PrinterHandler::CreateForExtensionPrinters(Profile::FromWebUI(web_ui())); 1703 PrinterHandler::CreateForExtensionPrinters(Profile::FromWebUI(web_ui()));
1706 } 1704 }
1707 1705
1708 void PrintPreviewHandler::OnGotPrintersForExtension( 1706 void PrintPreviewHandler::OnGotPrintersForExtension(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 1765
1768 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { 1766 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
1769 if (gaia_cookie_manager_service_) 1767 if (gaia_cookie_manager_service_)
1770 gaia_cookie_manager_service_->RemoveObserver(this); 1768 gaia_cookie_manager_service_->RemoveObserver(this);
1771 } 1769 }
1772 1770
1773 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1771 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1774 const base::Closure& closure) { 1772 const base::Closure& closure) {
1775 pdf_file_saved_closure_ = closure; 1773 pdf_file_saved_closure_ = closure;
1776 } 1774 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_handler.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698