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

Unified Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 504223005: Check Firewall state only initializing mDns from PrintPreview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tue Aug 26 18:22:17 PDT 2014 Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/print_preview/print_preview_handler.cc
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index f872501281d31e22a4bd6d4ae01c39a4c35a97d7..861a87695c3b0b4383aaefd7b7cfa7341768a811 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -638,28 +638,19 @@ void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) {
}
void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) {
+ if (!PrivetPrintingEnabled())
+ return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone");
#if defined(ENABLE_SERVICE_DISCOVERY)
- if (PrivetPrintingEnabled()) {
- Profile* profile = Profile::FromWebUI(web_ui());
- service_discovery_client_ =
- local_discovery::ServiceDiscoverySharedClient::GetInstance();
- printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister(
- service_discovery_client_.get(),
- profile->GetRequestContext(),
- this));
- printer_lister_->Start();
- }
-#endif
-
- if (!PrivetPrintingEnabled()) {
- web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone");
- }
+ local_discovery::ServiceDiscoverySharedClient::GetInstanceWithoutAlert(
+ base::Bind(&PrintPreviewHandler::StartPrivetLister,
+ weak_factory_.GetWeakPtr()));
+#endif // ENABLE_SERVICE_DISCOVERY
}
void PrintPreviewHandler::HandleStopGetPrivetPrinters(
const base::ListValue* args) {
#if defined(ENABLE_SERVICE_DISCOVERY)
- if (PrivetPrintingEnabled()) {
+ if (PrivetPrintingEnabled() && printer_lister_) {
printer_lister_->Stop();
}
#endif
@@ -1364,6 +1355,20 @@ bool PrintPreviewHandler::GetPreviewDataAndTitle(
}
#if defined(ENABLE_SERVICE_DISCOVERY)
+
+void PrintPreviewHandler::StartPrivetLister(
+ scoped_refptr<local_discovery::ServiceDiscoverySharedClient> client) {
+ if (!PrivetPrintingEnabled())
+ return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone");
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+ DCHECK(!service_discovery_client_ || service_discovery_client_ == client);
+ service_discovery_client_ = client;
+ printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister(
+ service_discovery_client_.get(), profile->GetRequestContext(), this));
+ printer_lister_->Start();
+}
+
void PrintPreviewHandler::LocalPrinterChanged(
bool added,
const std::string& name,
@@ -1464,7 +1469,8 @@ void PrintPreviewHandler::OnPrivetCapabilities(
const base::DictionaryValue* capabilities) {
std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName();
- if (!capabilities || capabilities->HasKey(local_discovery::kPrivetKeyError)) {
+ if (!capabilities || capabilities->HasKey(local_discovery::kPrivetKeyError) ||
+ !printer_lister_) {
SendPrivetCapabilitiesError(name);
return;
}
@@ -1514,7 +1520,7 @@ bool PrintPreviewHandler::CreatePrivetHTTP(
const local_discovery::PrivetHTTPAsynchronousFactory::ResultCallback&
callback) {
const local_discovery::DeviceDescription* device_description =
- printer_lister_->GetDeviceDescription(name);
+ printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL;
if (!device_description) {
SendPrivetCapabilitiesError(name);

Powered by Google App Engine
This is Rietveld 408576698