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 <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.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/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 17 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
17 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 18 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
18 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | 19 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" |
19 #include "chrome/browser/printing/cloud_print/privet_confirm_api_flow.h" | 20 #include "chrome/browser/printing/cloud_print/privet_confirm_api_flow.h" |
20 #include "chrome/browser/printing/cloud_print/privet_constants.h" | 21 #include "chrome/browser/printing/cloud_print/privet_constants.h" |
21 #include "chrome/browser/printing/cloud_print/privet_device_lister_impl.h" | 22 #include "chrome/browser/printing/cloud_print/privet_device_lister_impl.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 const char kDictionaryKeyType[] = "type"; | 56 const char kDictionaryKeyType[] = "type"; |
56 const char kDictionaryKeyIsWifi[] = "is_wifi"; | 57 const char kDictionaryKeyIsWifi[] = "is_wifi"; |
57 const char kDictionaryKeyID[] = "id"; | 58 const char kDictionaryKeyID[] = "id"; |
58 | 59 |
59 const char kKeyPrefixMDns[] = "MDns:"; | 60 const char kKeyPrefixMDns[] = "MDns:"; |
60 | 61 |
61 int g_num_visible = 0; | 62 int g_num_visible = 0; |
62 | 63 |
63 const int kCloudDevicesPrivetVersion = 3; | 64 const int kCloudDevicesPrivetVersion = 3; |
64 | 65 |
65 scoped_ptr<base::DictionaryValue> CreateDeviceInfo( | 66 std::unique_ptr<base::DictionaryValue> CreateDeviceInfo( |
66 const CloudPrintPrinterList::Device& description) { | 67 const CloudPrintPrinterList::Device& description) { |
67 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue); | 68 std::unique_ptr<base::DictionaryValue> return_value( |
| 69 new base::DictionaryValue); |
68 | 70 |
69 return_value->SetString(kDictionaryKeyID, description.id); | 71 return_value->SetString(kDictionaryKeyID, description.id); |
70 return_value->SetString(kDictionaryKeyDisplayName, description.display_name); | 72 return_value->SetString(kDictionaryKeyDisplayName, description.display_name); |
71 return_value->SetString(kDictionaryKeyDescription, description.description); | 73 return_value->SetString(kDictionaryKeyDescription, description.description); |
72 return_value->SetString(kDictionaryKeyType, "printer"); | 74 return_value->SetString(kDictionaryKeyType, "printer"); |
73 | 75 |
74 return return_value; | 76 return return_value; |
75 } | 77 } |
76 | 78 |
77 void ReadDevicesList(const CloudPrintPrinterList::DeviceList& devices, | 79 void ReadDevicesList(const CloudPrintPrinterList::DeviceList& devices, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 void LocalDiscoveryUIHandler::HandleRequestDeviceList( | 237 void LocalDiscoveryUIHandler::HandleRequestDeviceList( |
236 const base::ListValue* args) { | 238 const base::ListValue* args) { |
237 failed_list_count_ = 0; | 239 failed_list_count_ = 0; |
238 succeded_list_count_ = 0; | 240 succeded_list_count_ = 0; |
239 cloud_devices_.clear(); | 241 cloud_devices_.clear(); |
240 | 242 |
241 cloud_print_printer_list_ = CreateApiFlow(); | 243 cloud_print_printer_list_ = CreateApiFlow(); |
242 | 244 |
243 if (cloud_print_printer_list_) { | 245 if (cloud_print_printer_list_) { |
244 cloud_print_printer_list_->Start( | 246 cloud_print_printer_list_->Start( |
245 make_scoped_ptr<GCDApiFlow::Request>(new CloudPrintPrinterList(this))); | 247 base::WrapUnique<GCDApiFlow::Request>(new CloudPrintPrinterList(this))); |
246 } | 248 } |
247 | 249 |
248 CheckListingDone(); | 250 CheckListingDone(); |
249 } | 251 } |
250 | 252 |
251 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL( | 253 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL( |
252 const base::ListValue* args) { | 254 const base::ListValue* args) { |
253 std::string id; | 255 std::string id; |
254 bool rv = args->GetString(0, &id); | 256 bool rv = args->GetString(0, &id); |
255 DCHECK(rv); | 257 DCHECK(rv); |
(...skipping 10 matching lines...) Expand all Loading... |
266 void LocalDiscoveryUIHandler::HandleShowSyncUI( | 268 void LocalDiscoveryUIHandler::HandleShowSyncUI( |
267 const base::ListValue* args) { | 269 const base::ListValue* args) { |
268 Browser* browser = chrome::FindBrowserWithWebContents( | 270 Browser* browser = chrome::FindBrowserWithWebContents( |
269 web_ui()->GetWebContents()); | 271 web_ui()->GetWebContents()); |
270 DCHECK(browser); | 272 DCHECK(browser); |
271 chrome::ShowBrowserSignin( | 273 chrome::ShowBrowserSignin( |
272 browser, signin_metrics::AccessPoint::ACCESS_POINT_DEVICES_PAGE); | 274 browser, signin_metrics::AccessPoint::ACCESS_POINT_DEVICES_PAGE); |
273 } | 275 } |
274 | 276 |
275 void LocalDiscoveryUIHandler::StartRegisterHTTP( | 277 void LocalDiscoveryUIHandler::StartRegisterHTTP( |
276 scoped_ptr<cloud_print::PrivetHTTPClient> http_client) { | 278 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
277 current_http_client_ = | 279 current_http_client_ = |
278 cloud_print::PrivetV1HTTPClient::CreateDefault(std::move(http_client)); | 280 cloud_print::PrivetV1HTTPClient::CreateDefault(std::move(http_client)); |
279 | 281 |
280 std::string user = GetSyncAccount(); | 282 std::string user = GetSyncAccount(); |
281 | 283 |
282 if (!current_http_client_) { | 284 if (!current_http_client_) { |
283 SendRegisterError(); | 285 SendRegisterError(); |
284 return; | 286 return; |
285 } | 287 } |
286 | 288 |
(...skipping 11 matching lines...) Expand all Loading... |
298 if (device_descriptions_.count(current_http_client_->GetName()) == 0) { | 300 if (device_descriptions_.count(current_http_client_->GetName()) == 0) { |
299 SendRegisterError(); | 301 SendRegisterError(); |
300 return; | 302 return; |
301 } | 303 } |
302 | 304 |
303 confirm_api_call_flow_ = CreateApiFlow(); | 305 confirm_api_call_flow_ = CreateApiFlow(); |
304 if (!confirm_api_call_flow_) { | 306 if (!confirm_api_call_flow_) { |
305 SendRegisterError(); | 307 SendRegisterError(); |
306 return; | 308 return; |
307 } | 309 } |
308 confirm_api_call_flow_->Start( | 310 confirm_api_call_flow_->Start(base::WrapUnique<GCDApiFlow::Request>( |
309 make_scoped_ptr<GCDApiFlow::Request>( | 311 new cloud_print::PrivetConfirmApiCallFlow( |
310 new cloud_print::PrivetConfirmApiCallFlow( | 312 token, base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone, |
311 token, | 313 base::Unretained(this))))); |
312 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone, | |
313 base::Unretained(this))))); | |
314 } | 314 } |
315 | 315 |
316 void LocalDiscoveryUIHandler::OnPrivetRegisterError( | 316 void LocalDiscoveryUIHandler::OnPrivetRegisterError( |
317 PrivetRegisterOperation* operation, | 317 PrivetRegisterOperation* operation, |
318 const std::string& action, | 318 const std::string& action, |
319 PrivetRegisterOperation::FailureReason reason, | 319 PrivetRegisterOperation::FailureReason reason, |
320 int printer_http_code, | 320 int printer_http_code, |
321 const base::DictionaryValue* json) { | 321 const base::DictionaryValue* json) { |
322 std::string error; | 322 std::string error; |
323 | 323 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 if (description.id.empty()) { | 373 if (description.id.empty()) { |
374 info.SetString(kDictionaryKeyServiceName, name); | 374 info.SetString(kDictionaryKeyServiceName, name); |
375 info.SetString(kDictionaryKeyDisplayName, description.name); | 375 info.SetString(kDictionaryKeyDisplayName, description.name); |
376 info.SetString(kDictionaryKeyDescription, description.description); | 376 info.SetString(kDictionaryKeyDescription, description.description); |
377 info.SetString(kDictionaryKeyType, description.type); | 377 info.SetString(kDictionaryKeyType, description.type); |
378 info.SetBoolean(kDictionaryKeyIsWifi, false); | 378 info.SetBoolean(kDictionaryKeyIsWifi, false); |
379 | 379 |
380 web_ui()->CallJavascriptFunction( | 380 web_ui()->CallJavascriptFunction( |
381 "local_discovery.onUnregisteredDeviceUpdate", service_key, info); | 381 "local_discovery.onUnregisteredDeviceUpdate", service_key, info); |
382 } else { | 382 } else { |
383 scoped_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 383 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
384 | 384 |
385 web_ui()->CallJavascriptFunction( | 385 web_ui()->CallJavascriptFunction( |
386 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value); | 386 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value); |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 void LocalDiscoveryUIHandler::DeviceRemoved(const std::string& name) { | 390 void LocalDiscoveryUIHandler::DeviceRemoved(const std::string& name) { |
391 device_descriptions_.erase(name); | 391 device_descriptions_.erase(name); |
392 scoped_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 392 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
393 base::StringValue name_value(kKeyPrefixMDns + name); | 393 base::StringValue name_value(kKeyPrefixMDns + name); |
394 | 394 |
395 web_ui()->CallJavascriptFunction("local_discovery.onUnregisteredDeviceUpdate", | 395 web_ui()->CallJavascriptFunction("local_discovery.onUnregisteredDeviceUpdate", |
396 name_value, *null_value); | 396 name_value, *null_value); |
397 } | 397 } |
398 | 398 |
399 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { | 399 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { |
400 web_ui()->CallJavascriptFunction("local_discovery.onDeviceCacheFlushed"); | 400 web_ui()->CallJavascriptFunction("local_discovery.onDeviceCacheFlushed"); |
401 privet_lister_->DiscoverNewDevices(false); | 401 privet_lister_->DiscoverNewDevices(false); |
402 } | 402 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 local_ids.insert(i->second.id); | 518 local_ids.insert(i->second.id); |
519 } | 519 } |
520 | 520 |
521 ReadDevicesList(cloud_devices_, local_ids, &devices_list); | 521 ReadDevicesList(cloud_devices_, local_ids, &devices_list); |
522 | 522 |
523 web_ui()->CallJavascriptFunction( | 523 web_ui()->CallJavascriptFunction( |
524 "local_discovery.onCloudDeviceListAvailable", devices_list); | 524 "local_discovery.onCloudDeviceListAvailable", devices_list); |
525 cloud_print_printer_list_.reset(); | 525 cloud_print_printer_list_.reset(); |
526 } | 526 } |
527 | 527 |
528 scoped_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow() { | 528 std::unique_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow() { |
529 Profile* profile = Profile::FromWebUI(web_ui()); | 529 Profile* profile = Profile::FromWebUI(web_ui()); |
530 if (!profile) | 530 if (!profile) |
531 return scoped_ptr<GCDApiFlow>(); | 531 return std::unique_ptr<GCDApiFlow>(); |
532 ProfileOAuth2TokenService* token_service = | 532 ProfileOAuth2TokenService* token_service = |
533 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 533 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
534 if (!token_service) | 534 if (!token_service) |
535 return scoped_ptr<GCDApiFlow>(); | 535 return std::unique_ptr<GCDApiFlow>(); |
536 SigninManagerBase* signin_manager = | 536 SigninManagerBase* signin_manager = |
537 SigninManagerFactory::GetInstance()->GetForProfile(profile); | 537 SigninManagerFactory::GetInstance()->GetForProfile(profile); |
538 if (!signin_manager) | 538 if (!signin_manager) |
539 return scoped_ptr<GCDApiFlow>(); | 539 return std::unique_ptr<GCDApiFlow>(); |
540 return GCDApiFlow::Create(profile->GetRequestContext(), | 540 return GCDApiFlow::Create(profile->GetRequestContext(), |
541 token_service, | 541 token_service, |
542 signin_manager->GetAuthenticatedAccountId()); | 542 signin_manager->GetAuthenticatedAccountId()); |
543 } | 543 } |
544 | 544 |
545 bool LocalDiscoveryUIHandler::IsUserSupervisedOrOffTheRecord() { | 545 bool LocalDiscoveryUIHandler::IsUserSupervisedOrOffTheRecord() { |
546 Profile* profile = Profile::FromWebUI(web_ui()); | 546 Profile* profile = Profile::FromWebUI(web_ui()); |
547 | 547 |
548 return profile->IsSupervised() || profile->IsOffTheRecord(); | 548 return profile->IsSupervised() || profile->IsOffTheRecord(); |
549 } | 549 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 650 |
651 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { | 651 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { |
652 if (cloud_print_connector_ui_enabled_) | 652 if (cloud_print_connector_ui_enabled_) |
653 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> | 653 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> |
654 RefreshStatusFromService(); | 654 RefreshStatusFromService(); |
655 } | 655 } |
656 | 656 |
657 #endif // cloud print connector option stuff | 657 #endif // cloud print connector option stuff |
658 | 658 |
659 } // namespace local_discovery | 659 } // namespace local_discovery |
OLD | NEW |