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

Side by Side 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, 3 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 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 BrowserThread::PostTaskAndReply( 631 BrowserThread::PostTaskAndReply(
632 BrowserThread::FILE, FROM_HERE, 632 BrowserThread::FILE, FROM_HERE,
633 base::Bind(&EnumeratePrintersOnFileThread, 633 base::Bind(&EnumeratePrintersOnFileThread,
634 base::Unretained(results)), 634 base::Unretained(results)),
635 base::Bind(&PrintPreviewHandler::SetupPrinterList, 635 base::Bind(&PrintPreviewHandler::SetupPrinterList,
636 weak_factory_.GetWeakPtr(), 636 weak_factory_.GetWeakPtr(),
637 base::Owned(results))); 637 base::Owned(results)));
638 } 638 }
639 639
640 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { 640 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) {
641 if (!PrivetPrintingEnabled())
642 return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone");
641 #if defined(ENABLE_SERVICE_DISCOVERY) 643 #if defined(ENABLE_SERVICE_DISCOVERY)
642 if (PrivetPrintingEnabled()) { 644 local_discovery::ServiceDiscoverySharedClient::GetInstanceWithoutAlert(
643 Profile* profile = Profile::FromWebUI(web_ui()); 645 base::Bind(&PrintPreviewHandler::StartPrivetLister,
644 service_discovery_client_ = 646 weak_factory_.GetWeakPtr()));
645 local_discovery::ServiceDiscoverySharedClient::GetInstance(); 647 #endif // ENABLE_SERVICE_DISCOVERY
646 printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister(
647 service_discovery_client_.get(),
648 profile->GetRequestContext(),
649 this));
650 printer_lister_->Start();
651 }
652 #endif
653
654 if (!PrivetPrintingEnabled()) {
655 web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone");
656 }
657 } 648 }
658 649
659 void PrintPreviewHandler::HandleStopGetPrivetPrinters( 650 void PrintPreviewHandler::HandleStopGetPrivetPrinters(
660 const base::ListValue* args) { 651 const base::ListValue* args) {
661 #if defined(ENABLE_SERVICE_DISCOVERY) 652 #if defined(ENABLE_SERVICE_DISCOVERY)
662 if (PrivetPrintingEnabled()) { 653 if (PrivetPrintingEnabled() && printer_lister_) {
663 printer_lister_->Stop(); 654 printer_lister_->Stop();
664 } 655 }
665 #endif 656 #endif
666 } 657 }
667 658
668 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( 659 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities(
669 const base::ListValue* args) { 660 const base::ListValue* args) {
670 #if defined(ENABLE_SERVICE_DISCOVERY) 661 #if defined(ENABLE_SERVICE_DISCOVERY)
671 std::string name; 662 std::string name;
672 bool success = args->GetString(0, &name); 663 bool success = args->GetString(0, &name);
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 return false; 1348 return false;
1358 } 1349 }
1359 DCHECK(tmp_data->size() && tmp_data->front()); 1350 DCHECK(tmp_data->size() && tmp_data->front());
1360 1351
1361 *data = tmp_data; 1352 *data = tmp_data;
1362 *title = print_preview_ui->initiator_title(); 1353 *title = print_preview_ui->initiator_title();
1363 return true; 1354 return true;
1364 } 1355 }
1365 1356
1366 #if defined(ENABLE_SERVICE_DISCOVERY) 1357 #if defined(ENABLE_SERVICE_DISCOVERY)
1358
1359 void PrintPreviewHandler::StartPrivetLister(
1360 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> client) {
1361 if (!PrivetPrintingEnabled())
1362 return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone");
1363
1364 Profile* profile = Profile::FromWebUI(web_ui());
1365 DCHECK(!service_discovery_client_ || service_discovery_client_ == client);
1366 service_discovery_client_ = client;
1367 printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister(
1368 service_discovery_client_.get(), profile->GetRequestContext(), this));
1369 printer_lister_->Start();
1370 }
1371
1367 void PrintPreviewHandler::LocalPrinterChanged( 1372 void PrintPreviewHandler::LocalPrinterChanged(
1368 bool added, 1373 bool added,
1369 const std::string& name, 1374 const std::string& name,
1370 bool has_local_printing, 1375 bool has_local_printing,
1371 const local_discovery::DeviceDescription& description) { 1376 const local_discovery::DeviceDescription& description) {
1372 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 1377 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1373 if (has_local_printing || 1378 if (has_local_printing ||
1374 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { 1379 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) {
1375 base::DictionaryValue info; 1380 base::DictionaryValue info;
1376 FillPrinterDescription(name, description, has_local_printing, &info); 1381 FillPrinterDescription(name, description, has_local_printing, &info);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 } 1462 }
1458 1463
1459 privet_local_print_operation_->Start(); 1464 privet_local_print_operation_->Start();
1460 } 1465 }
1461 1466
1462 1467
1463 void PrintPreviewHandler::OnPrivetCapabilities( 1468 void PrintPreviewHandler::OnPrivetCapabilities(
1464 const base::DictionaryValue* capabilities) { 1469 const base::DictionaryValue* capabilities) {
1465 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); 1470 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName();
1466 1471
1467 if (!capabilities || capabilities->HasKey(local_discovery::kPrivetKeyError)) { 1472 if (!capabilities || capabilities->HasKey(local_discovery::kPrivetKeyError) ||
1473 !printer_lister_) {
1468 SendPrivetCapabilitiesError(name); 1474 SendPrivetCapabilitiesError(name);
1469 return; 1475 return;
1470 } 1476 }
1471 1477
1472 base::DictionaryValue printer_info; 1478 base::DictionaryValue printer_info;
1473 const local_discovery::DeviceDescription* description = 1479 const local_discovery::DeviceDescription* description =
1474 printer_lister_->GetDeviceDescription(name); 1480 printer_lister_->GetDeviceDescription(name);
1475 1481
1476 if (!description) { 1482 if (!description) {
1477 SendPrivetCapabilitiesError(name); 1483 SendPrivetCapabilitiesError(name);
(...skipping 29 matching lines...) Expand all
1507 ticket, 1513 ticket,
1508 capabilities, 1514 capabilities,
1509 page_size)); 1515 page_size));
1510 } 1516 }
1511 1517
1512 bool PrintPreviewHandler::CreatePrivetHTTP( 1518 bool PrintPreviewHandler::CreatePrivetHTTP(
1513 const std::string& name, 1519 const std::string& name,
1514 const local_discovery::PrivetHTTPAsynchronousFactory::ResultCallback& 1520 const local_discovery::PrivetHTTPAsynchronousFactory::ResultCallback&
1515 callback) { 1521 callback) {
1516 const local_discovery::DeviceDescription* device_description = 1522 const local_discovery::DeviceDescription* device_description =
1517 printer_lister_->GetDeviceDescription(name); 1523 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL;
1518 1524
1519 if (!device_description) { 1525 if (!device_description) {
1520 SendPrivetCapabilitiesError(name); 1526 SendPrivetCapabilitiesError(name);
1521 return false; 1527 return false;
1522 } 1528 }
1523 1529
1524 privet_http_factory_ = 1530 privet_http_factory_ =
1525 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance( 1531 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance(
1526 service_discovery_client_, 1532 service_discovery_client_,
1527 Profile::FromWebUI(web_ui())->GetRequestContext()); 1533 Profile::FromWebUI(web_ui())->GetRequestContext());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 1581
1576 void PrintPreviewHandler::UnregisterForMergeSession() { 1582 void PrintPreviewHandler::UnregisterForMergeSession() {
1577 if (reconcilor_) 1583 if (reconcilor_)
1578 reconcilor_->RemoveMergeSessionObserver(this); 1584 reconcilor_->RemoveMergeSessionObserver(this);
1579 } 1585 }
1580 1586
1581 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1587 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1582 const base::Closure& closure) { 1588 const base::Closure& closure) {
1583 pdf_file_saved_closure_ = closure; 1589 pdf_file_saved_closure_ = closure;
1584 } 1590 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698