| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/local_discovery/local_discovery_ui_handler.h" | 5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <set> | 8 #include <set> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( | 167 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( |
| 167 profile->GetRequestContext()); | 168 profile->GetRequestContext()); |
| 168 | 169 |
| 169 SigninManagerBase* signin_manager = | 170 SigninManagerBase* signin_manager = |
| 170 SigninManagerFactory::GetInstance()->GetForProfile(profile); | 171 SigninManagerFactory::GetInstance()->GetForProfile(profile); |
| 171 if (signin_manager) | 172 if (signin_manager) |
| 172 signin_manager->AddObserver(this); | 173 signin_manager->AddObserver(this); |
| 173 } | 174 } |
| 174 | 175 |
| 175 privet_lister_->Start(); | 176 privet_lister_->Start(); |
| 176 privet_lister_->DiscoverNewDevices(false); | 177 privet_lister_->DiscoverNewDevices(); |
| 177 | 178 |
| 178 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 179 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
| 179 StartCloudPrintConnector(); | 180 StartCloudPrintConnector(); |
| 180 #endif | 181 #endif |
| 181 | 182 |
| 182 CheckUserLoggedIn(); | 183 CheckUserLoggedIn(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void LocalDiscoveryUIHandler::HandleIsVisible(const base::ListValue* args) { | 186 void LocalDiscoveryUIHandler::HandleIsVisible(const base::ListValue* args) { |
| 186 bool is_visible = false; | 187 bool is_visible = false; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 auto null_value = base::MakeUnique<base::Value>(); | 374 auto null_value = base::MakeUnique<base::Value>(); |
| 374 base::Value name_value(kKeyPrefixMDns + name); | 375 base::Value name_value(kKeyPrefixMDns + name); |
| 375 | 376 |
| 376 web_ui()->CallJavascriptFunctionUnsafe( | 377 web_ui()->CallJavascriptFunctionUnsafe( |
| 377 "local_discovery.onUnregisteredDeviceUpdate", name_value, *null_value); | 378 "local_discovery.onUnregisteredDeviceUpdate", name_value, *null_value); |
| 378 } | 379 } |
| 379 | 380 |
| 380 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { | 381 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { |
| 381 web_ui()->CallJavascriptFunctionUnsafe( | 382 web_ui()->CallJavascriptFunctionUnsafe( |
| 382 "local_discovery.onDeviceCacheFlushed"); | 383 "local_discovery.onDeviceCacheFlushed"); |
| 383 privet_lister_->DiscoverNewDevices(false); | 384 privet_lister_->DiscoverNewDevices(); |
| 384 } | 385 } |
| 385 | 386 |
| 386 void LocalDiscoveryUIHandler::OnDeviceListReady( | 387 void LocalDiscoveryUIHandler::OnDeviceListReady( |
| 387 const CloudPrintPrinterList::DeviceList& devices) { | 388 const CloudPrintPrinterList::DeviceList& devices) { |
| 388 cloud_devices_.insert(cloud_devices_.end(), devices.begin(), devices.end()); | 389 cloud_devices_.insert(cloud_devices_.end(), devices.begin(), devices.end()); |
| 389 ++succeded_list_count_; | 390 ++succeded_list_count_; |
| 390 CheckListingDone(); | 391 CheckListingDone(); |
| 391 } | 392 } |
| 392 | 393 |
| 393 void LocalDiscoveryUIHandler::OnDeviceListUnavailable() { | 394 void LocalDiscoveryUIHandler::OnDeviceListUnavailable() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 409 | 410 |
| 410 void LocalDiscoveryUIHandler::SendRegisterError() { | 411 void LocalDiscoveryUIHandler::SendRegisterError() { |
| 411 web_ui()->CallJavascriptFunctionUnsafe( | 412 web_ui()->CallJavascriptFunctionUnsafe( |
| 412 "local_discovery.onRegistrationFailed"); | 413 "local_discovery.onRegistrationFailed"); |
| 413 } | 414 } |
| 414 | 415 |
| 415 void LocalDiscoveryUIHandler::SendRegisterDone( | 416 void LocalDiscoveryUIHandler::SendRegisterDone( |
| 416 const std::string& service_name) { | 417 const std::string& service_name) { |
| 417 // HACK(noamsml): Generate network traffic so the Windows firewall doesn't | 418 // HACK(noamsml): Generate network traffic so the Windows firewall doesn't |
| 418 // block the printer's announcement. | 419 // block the printer's announcement. |
| 419 privet_lister_->DiscoverNewDevices(false); | 420 privet_lister_->DiscoverNewDevices(); |
| 420 | 421 |
| 421 DeviceDescriptionMap::iterator it = device_descriptions_.find(service_name); | 422 DeviceDescriptionMap::iterator it = device_descriptions_.find(service_name); |
| 422 | 423 |
| 423 if (it == device_descriptions_.end()) { | 424 if (it == device_descriptions_.end()) { |
| 424 // TODO(noamsml): Handle the case where a printer's record is not present at | 425 // TODO(noamsml): Handle the case where a printer's record is not present at |
| 425 // the end of registration. | 426 // the end of registration. |
| 426 SendRegisterError(); | 427 SendRegisterError(); |
| 427 return; | 428 return; |
| 428 } | 429 } |
| 429 | 430 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 service->RefreshStatusFromService(); | 611 service->RefreshStatusFromService(); |
| 611 } | 612 } |
| 612 | 613 |
| 613 CloudPrintProxyService* LocalDiscoveryUIHandler::GetCloudPrintProxyService() { | 614 CloudPrintProxyService* LocalDiscoveryUIHandler::GetCloudPrintProxyService() { |
| 614 return CloudPrintProxyServiceFactory::GetForProfile( | 615 return CloudPrintProxyServiceFactory::GetForProfile( |
| 615 Profile::FromWebUI(web_ui())); | 616 Profile::FromWebUI(web_ui())); |
| 616 } | 617 } |
| 617 #endif // defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 618 #endif // defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
| 618 | 619 |
| 619 } // namespace local_discovery | 620 } // namespace local_discovery |
| OLD | NEW |