Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/arc/net/arc_net_host_impl.h" | 5 #include "components/arc/net/arc_net_host_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 dict->GetBoolean(onc::wifi::kHiddenSSID, &wifi->hidden_ssid); | 93 dict->GetBoolean(onc::wifi::kHiddenSSID, &wifi->hidden_ssid); |
| 94 | 94 |
| 95 wifi->security = TranslateONCWifiSecurityType(dict); | 95 wifi->security = TranslateONCWifiSecurityType(dict); |
| 96 | 96 |
| 97 // Optional; defaults to 0. | 97 // Optional; defaults to 0. |
| 98 dict->GetInteger(onc::wifi::kSignalStrength, &wifi->signal_strength); | 98 dict->GetInteger(onc::wifi::kSignalStrength, &wifi->signal_strength); |
| 99 | 99 |
| 100 return wifi; | 100 return wifi; |
| 101 } | 101 } |
| 102 | 102 |
| 103 mojo::Array<mojo::String> TranslateStringArray(const base::ListValue* list) { | 103 std::vector<std::string> TranslateStringArray(const base::ListValue* list) { |
| 104 mojo::Array<mojo::String> strings = mojo::Array<mojo::String>::New(0); | 104 std::vector<std::string> strings; |
|
Luis Héctor Chávez
2016/12/14 22:55:35
nit: maybe strings.reserve(list->GetSize())? Same
abhishekbh
2016/12/14 23:07:47
I'd rather keep this CL simple. Also, the first pu
Luis Héctor Chávez
2016/12/14 23:09:08
separate CL is also fine by me.
| |
| 105 | 105 |
| 106 for (size_t i = 0; i < list->GetSize(); i++) { | 106 for (size_t i = 0; i < list->GetSize(); i++) { |
| 107 std::string value; | 107 std::string value; |
| 108 list->GetString(i, &value); | 108 list->GetString(i, &value); |
| 109 DCHECK(!value.empty()); | 109 DCHECK(!value.empty()); |
| 110 strings.push_back(static_cast<mojo::String>(value)); | 110 strings.push_back(value); |
| 111 } | 111 } |
| 112 | 112 |
| 113 return strings; | 113 return strings; |
| 114 } | 114 } |
| 115 | 115 |
| 116 mojo::Array<arc::mojom::IPConfigurationPtr> TranslateONCIPConfigs( | 116 std::vector<arc::mojom::IPConfigurationPtr> TranslateONCIPConfigs( |
| 117 const base::ListValue* list) { | 117 const base::ListValue* list) { |
| 118 mojo::Array<arc::mojom::IPConfigurationPtr> configs = | 118 std::vector<arc::mojom::IPConfigurationPtr> configs; |
| 119 mojo::Array<arc::mojom::IPConfigurationPtr>::New(0); | |
| 120 | 119 |
| 121 for (size_t i = 0; i < list->GetSize(); i++) { | 120 for (size_t i = 0; i < list->GetSize(); i++) { |
| 122 const base::DictionaryValue* ip_dict = nullptr; | 121 const base::DictionaryValue* ip_dict = nullptr; |
| 123 arc::mojom::IPConfigurationPtr configuration = | 122 arc::mojom::IPConfigurationPtr configuration = |
| 124 arc::mojom::IPConfiguration::New(); | 123 arc::mojom::IPConfiguration::New(); |
| 125 | 124 |
| 126 list->GetDictionary(i, &ip_dict); | 125 list->GetDictionary(i, &ip_dict); |
| 127 DCHECK(ip_dict); | 126 DCHECK(ip_dict); |
| 128 | 127 |
| 129 // crbug.com/625229 - Gateway is not always present (but it should be). | 128 // crbug.com/625229 - Gateway is not always present (but it should be). |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi); | 362 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi); |
| 364 std::unique_ptr<base::ListValue> network_properties_list = | 363 std::unique_ptr<base::ListValue> network_properties_list = |
| 365 chromeos::network_util::TranslateNetworkListToONC( | 364 chromeos::network_util::TranslateNetworkListToONC( |
| 366 network_pattern, configured_only, visible_only, | 365 network_pattern, configured_only, visible_only, |
| 367 kGetNetworksListLimit); | 366 kGetNetworksListLimit); |
| 368 | 367 |
| 369 // Extract info for each network and add it to the list. | 368 // Extract info for each network and add it to the list. |
| 370 // Even if there's no WiFi, an empty (size=0) list must be returned and not a | 369 // Even if there's no WiFi, an empty (size=0) list must be returned and not a |
| 371 // null one. The explicitly sized New() constructor ensures the non-null | 370 // null one. The explicitly sized New() constructor ensures the non-null |
| 372 // property. | 371 // property. |
| 373 mojo::Array<mojom::WifiConfigurationPtr> networks = | 372 std::vector<mojom::WifiConfigurationPtr> networks; |
| 374 mojo::Array<mojom::WifiConfigurationPtr>::New(0); | |
| 375 for (const auto& value : *network_properties_list) { | 373 for (const auto& value : *network_properties_list) { |
| 376 mojom::WifiConfigurationPtr wc = mojom::WifiConfiguration::New(); | 374 mojom::WifiConfigurationPtr wc = mojom::WifiConfiguration::New(); |
| 377 | 375 |
| 378 base::DictionaryValue* network_dict = nullptr; | 376 base::DictionaryValue* network_dict = nullptr; |
| 379 value->GetAsDictionary(&network_dict); | 377 value->GetAsDictionary(&network_dict); |
| 380 DCHECK(network_dict); | 378 DCHECK(network_dict); |
| 381 | 379 |
| 382 // kName is a post-processed version of kHexSSID. | 380 // kName is a post-processed version of kHexSSID. |
| 383 std::string tmp; | 381 std::string tmp; |
| 384 network_dict->GetString(onc::network_config::kName, &tmp); | 382 network_dict->GetString(onc::network_config::kName, &tmp); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 void ArcNetHostImpl::CreateNetwork(mojom::WifiConfigurationPtr cfg, | 445 void ArcNetHostImpl::CreateNetwork(mojom::WifiConfigurationPtr cfg, |
| 448 const CreateNetworkCallback& callback) { | 446 const CreateNetworkCallback& callback) { |
| 449 if (!IsDeviceOwner()) { | 447 if (!IsDeviceOwner()) { |
| 450 callback.Run(""); | 448 callback.Run(""); |
| 451 return; | 449 return; |
| 452 } | 450 } |
| 453 | 451 |
| 454 std::unique_ptr<base::DictionaryValue> properties(new base::DictionaryValue); | 452 std::unique_ptr<base::DictionaryValue> properties(new base::DictionaryValue); |
| 455 std::unique_ptr<base::DictionaryValue> wifi_dict(new base::DictionaryValue); | 453 std::unique_ptr<base::DictionaryValue> wifi_dict(new base::DictionaryValue); |
| 456 | 454 |
| 457 if (cfg->hexssid.is_null() || !cfg->details) { | 455 if (!cfg->hexssid.has_value() || !cfg->details) { |
| 458 callback.Run(""); | 456 callback.Run(""); |
| 459 return; | 457 return; |
| 460 } | 458 } |
| 461 mojom::ConfiguredNetworkDetailsPtr details = | 459 mojom::ConfiguredNetworkDetailsPtr details = |
| 462 std::move(cfg->details->get_configured()); | 460 std::move(cfg->details->get_configured()); |
| 463 if (!details) { | 461 if (!details) { |
| 464 callback.Run(""); | 462 callback.Run(""); |
| 465 return; | 463 return; |
| 466 } | 464 } |
| 467 | 465 |
| 468 properties->SetStringWithoutPathExpansion(onc::network_config::kType, | 466 properties->SetStringWithoutPathExpansion(onc::network_config::kType, |
| 469 onc::network_config::kWiFi); | 467 onc::network_config::kWiFi); |
| 470 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kHexSSID, | 468 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kHexSSID, |
| 471 cfg->hexssid.get()); | 469 cfg->hexssid.value()); |
| 472 wifi_dict->SetBooleanWithoutPathExpansion(onc::wifi::kAutoConnect, | 470 wifi_dict->SetBooleanWithoutPathExpansion(onc::wifi::kAutoConnect, |
| 473 details->autoconnect); | 471 details->autoconnect); |
| 474 if (cfg->security.get().empty()) { | 472 if (cfg->security.empty()) { |
| 475 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kSecurity, | 473 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kSecurity, |
| 476 onc::wifi::kSecurityNone); | 474 onc::wifi::kSecurityNone); |
| 477 } else { | 475 } else { |
| 478 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kSecurity, | 476 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kSecurity, |
| 479 cfg->security.get()); | 477 cfg->security); |
| 480 if (!details->passphrase.is_null()) { | 478 if (details->passphrase.has_value()) { |
| 481 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kPassphrase, | 479 wifi_dict->SetStringWithoutPathExpansion(onc::wifi::kPassphrase, |
| 482 details->passphrase.get()); | 480 details->passphrase.value()); |
| 483 } | 481 } |
| 484 } | 482 } |
| 485 properties->SetWithoutPathExpansion(onc::network_config::kWiFi, | 483 properties->SetWithoutPathExpansion(onc::network_config::kWiFi, |
| 486 std::move(wifi_dict)); | 484 std::move(wifi_dict)); |
| 487 | 485 |
| 488 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); | 486 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); |
| 489 GetManagedConfigurationHandler()->CreateConfiguration( | 487 GetManagedConfigurationHandler()->CreateConfiguration( |
| 490 user_id_hash, *properties, | 488 user_id_hash, *properties, |
| 491 base::Bind(&ArcNetHostImpl::CreateNetworkSuccessCallback, | 489 base::Bind(&ArcNetHostImpl::CreateNetworkSuccessCallback, |
| 492 weak_factory_.GetWeakPtr(), callback), | 490 weak_factory_.GetWeakPtr(), callback), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 504 } | 502 } |
| 505 | 503 |
| 506 if (cached_guid_ == guid) { | 504 if (cached_guid_ == guid) { |
| 507 *path = cached_service_path_; | 505 *path = cached_service_path_; |
| 508 return true; | 506 return true; |
| 509 } else { | 507 } else { |
| 510 return false; | 508 return false; |
| 511 } | 509 } |
| 512 } | 510 } |
| 513 | 511 |
| 514 void ArcNetHostImpl::ForgetNetwork(const mojo::String& guid, | 512 void ArcNetHostImpl::ForgetNetwork(const std::string& guid, |
| 515 const ForgetNetworkCallback& callback) { | 513 const ForgetNetworkCallback& callback) { |
| 516 if (!IsDeviceOwner()) { | 514 if (!IsDeviceOwner()) { |
| 517 callback.Run(mojom::NetworkResult::FAILURE); | 515 callback.Run(mojom::NetworkResult::FAILURE); |
| 518 return; | 516 return; |
| 519 } | 517 } |
| 520 | 518 |
| 521 std::string path; | 519 std::string path; |
| 522 if (!GetNetworkPathFromGuid(guid, &path)) { | 520 if (!GetNetworkPathFromGuid(guid, &path)) { |
| 523 callback.Run(mojom::NetworkResult::FAILURE); | 521 callback.Run(mojom::NetworkResult::FAILURE); |
| 524 return; | 522 return; |
| 525 } | 523 } |
| 526 | 524 |
| 527 cached_guid_.clear(); | 525 cached_guid_.clear(); |
| 528 GetManagedConfigurationHandler()->RemoveConfiguration( | 526 GetManagedConfigurationHandler()->RemoveConfiguration( |
| 529 path, base::Bind(&ForgetNetworkSuccessCallback, callback), | 527 path, base::Bind(&ForgetNetworkSuccessCallback, callback), |
| 530 base::Bind(&ForgetNetworkFailureCallback, callback)); | 528 base::Bind(&ForgetNetworkFailureCallback, callback)); |
| 531 } | 529 } |
| 532 | 530 |
| 533 void ArcNetHostImpl::StartConnect(const mojo::String& guid, | 531 void ArcNetHostImpl::StartConnect(const std::string& guid, |
| 534 const StartConnectCallback& callback) { | 532 const StartConnectCallback& callback) { |
| 535 std::string path; | 533 std::string path; |
| 536 if (!GetNetworkPathFromGuid(guid, &path)) { | 534 if (!GetNetworkPathFromGuid(guid, &path)) { |
| 537 callback.Run(mojom::NetworkResult::FAILURE); | 535 callback.Run(mojom::NetworkResult::FAILURE); |
| 538 return; | 536 return; |
| 539 } | 537 } |
| 540 | 538 |
| 541 GetNetworkConnectionHandler()->ConnectToNetwork( | 539 GetNetworkConnectionHandler()->ConnectToNetwork( |
| 542 path, base::Bind(&StartConnectSuccessCallback, callback), | 540 path, base::Bind(&StartConnectSuccessCallback, callback), |
| 543 base::Bind(&StartConnectFailureCallback, callback), false); | 541 base::Bind(&StartConnectFailureCallback, callback), false); |
| 544 } | 542 } |
| 545 | 543 |
| 546 void ArcNetHostImpl::StartDisconnect(const mojo::String& guid, | 544 void ArcNetHostImpl::StartDisconnect(const std::string& guid, |
| 547 const StartDisconnectCallback& callback) { | 545 const StartDisconnectCallback& callback) { |
| 548 std::string path; | 546 std::string path; |
| 549 if (!GetNetworkPathFromGuid(guid, &path)) { | 547 if (!GetNetworkPathFromGuid(guid, &path)) { |
| 550 callback.Run(mojom::NetworkResult::FAILURE); | 548 callback.Run(mojom::NetworkResult::FAILURE); |
| 551 return; | 549 return; |
| 552 } | 550 } |
| 553 | 551 |
| 554 GetNetworkConnectionHandler()->DisconnectNetwork( | 552 GetNetworkConnectionHandler()->DisconnectNetwork( |
| 555 path, base::Bind(&StartDisconnectSuccessCallback, callback), | 553 path, base::Bind(&StartDisconnectSuccessCallback, callback), |
| 556 base::Bind(&StartDisconnectFailureCallback, callback)); | 554 base::Bind(&StartDisconnectFailureCallback, callback)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 net_instance->WifiEnabledStateChanged(is_enabled); | 656 net_instance->WifiEnabledStateChanged(is_enabled); |
| 659 } | 657 } |
| 660 | 658 |
| 661 void ArcNetHostImpl::OnShuttingDown() { | 659 void ArcNetHostImpl::OnShuttingDown() { |
| 662 DCHECK(observing_network_state_); | 660 DCHECK(observing_network_state_); |
| 663 GetStateHandler()->RemoveObserver(this, FROM_HERE); | 661 GetStateHandler()->RemoveObserver(this, FROM_HERE); |
| 664 observing_network_state_ = false; | 662 observing_network_state_ = false; |
| 665 } | 663 } |
| 666 | 664 |
| 667 } // namespace arc | 665 } // namespace arc |
| OLD | NEW |