diff options
author | stevenjb <stevenjb@chromium.org> | 2015-08-20 17:36:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-21 00:36:53 +0000 |
commit | 0149c7cbc8245bc52f388ef9b4a655e7aee72d5f (patch) | |
tree | 16d5f42e9f4ab70fa1511a45f22bf51655bf1c5c | |
parent | 4107a71888ebbdad03c93f80bb024871c620d4bd (diff) | |
download | chromium_src-0149c7cbc8245bc52f388ef9b4a655e7aee72d5f.zip chromium_src-0149c7cbc8245bc52f388ef9b4a655e7aee72d5f.tar.gz chromium_src-0149c7cbc8245bc52f388ef9b4a655e7aee72d5f.tar.bz2 |
Provide ONC Source in MNCH::GetNetworks, Priority in GetState
Ths CL:
* Correctly sets the Source ONC property in GetNetworks
* Provides Priorty for networkingPrivate.getState and getNetworks
BUG=521037
For missing owner in wifi_config_delegate_chromeos_unittest.cc
TBR=stevenjb
Review URL: https://codereview.chromium.org/1304683004
Cr-Commit-Position: refs/heads/master@{#344630}
10 files changed, 67 insertions, 21 deletions
diff --git a/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js b/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js index 5e1205e..8c5d600 100644 --- a/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js +++ b/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js @@ -221,8 +221,9 @@ var availableTests = [ ConnectionState: ConnectionStateType.CONNECTED, GUID: 'stub_wifi1_guid', Name: 'wifi1', - Type: NetworkType.WI_FI, + Priority: 0, Source: 'User', + Type: NetworkType.WI_FI, WiFi: { Security: 'WEP-PSK', SignalStrength: 40 @@ -230,8 +231,9 @@ var availableTests = [ }, { GUID: 'stub_wifi2_guid', Name: 'wifi2_PSK', - Type: NetworkType.WI_FI, + Priority: 0, Source: 'User', + Type: NetworkType.WI_FI, WiFi: { Security: 'WPA-PSK', } @@ -247,6 +249,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.CONNECTED, GUID: 'stub_wifi1_guid', Name: 'wifi1', + Priority: 0, Source: 'User', Type: NetworkType.WI_FI, WiFi: { @@ -270,6 +273,7 @@ var availableTests = [ }, GUID: 'stub_ethernet_guid', Name: 'eth0', + Priority: 0, Source: 'Device', Type: NetworkType.ETHERNET }], result); @@ -288,6 +292,7 @@ var availableTests = [ }, GUID: 'stub_ethernet_guid', Name: 'eth0', + Priority: 0, Source: 'Device', Type: NetworkType.ETHERNET }, { @@ -295,6 +300,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.CONNECTED, GUID: 'stub_wifi1_guid', Name: 'wifi1', + Priority: 0, Source: 'User', Type: NetworkType.WI_FI, WiFi: { @@ -306,6 +312,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.CONNECTED, GUID: 'stub_wimax_guid', Name: 'wimax', + Priority: 0, Source: 'User', Type: NetworkType.WI_MAX, WiMAX: { @@ -315,6 +322,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.CONNECTED, GUID: 'stub_vpn1_guid', Name: 'vpn1', + Priority: 0, Source: 'User', Type: NetworkType.VPN, VPN: { @@ -324,6 +332,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.NOT_CONNECTED, GUID: 'stub_vpn2_guid', Name: 'vpn2', + Priority: 0, Source: 'User', Type: NetworkType.VPN, VPN: { @@ -337,6 +346,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.NOT_CONNECTED, GUID: 'stub_wifi2_guid', Name: 'wifi2_PSK', + Priority: 0, Source: 'User', Type: NetworkType.WI_FI, WiFi: { @@ -355,6 +365,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.CONNECTED, GUID: 'stub_wifi1_guid', Name: 'wifi1', + Priority: 0, Source: 'User', Type: NetworkType.WI_FI, WiFi: { @@ -366,6 +377,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.NOT_CONNECTED, GUID: 'stub_wifi2_guid', Name: 'wifi2_PSK', + Priority: 0, Source: 'User', Type: NetworkType.WI_FI, WiFi: { @@ -442,6 +454,7 @@ var availableTests = [ }], MacAddress: '00:11:22:AA:BB:CC', Name: 'wifi1', + Source: 'User', StaticIPConfig: { IPAddress: '1.2.3.4', Type: 'IPv4' @@ -480,6 +493,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.NOT_CONNECTED, GUID: kCellularGuid, Name: 'cellular1', + Source: 'User', Type: NetworkType.CELLULAR, }, result); })); @@ -639,6 +653,7 @@ var availableTests = [ ConnectionState: ConnectionStateType.NOT_CONNECTED, GUID: 'stub_wifi2_guid', Name: 'wifi2_PSK', + Priority: 0, Source: 'User', Type: NetworkType.WI_FI, WiFi: { diff --git a/chromeos/network/managed_network_configuration_handler.h b/chromeos/network/managed_network_configuration_handler.h index f8672ee..dfdeb722 100644 --- a/chromeos/network/managed_network_configuration_handler.h +++ b/chromeos/network/managed_network_configuration_handler.h @@ -60,14 +60,18 @@ class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler { virtual void RemoveObserver(NetworkPolicyObserver* observer) = 0; // Provides the properties of the network with |service_path| to |callback|. + // |userhash| is used to set the "Source" property. If not provided then + // user polcies will be ignored. virtual void GetProperties( + const std::string& userhash, const std::string& service_path, const network_handler::DictionaryResultCallback& callback, const network_handler::ErrorCallback& error_callback) = 0; // Provides the managed properties of the network with |service_path| to - // |callback|. |userhash| is only used to ensure that the user's policy is - // already applied. + // |callback|. |userhash| is used to ensure that the user's policy is + // already applied, and to set the "Source" property (see note for + // GetProperties). virtual void GetManagedProperties( const std::string& userhash, const std::string& service_path, diff --git a/chromeos/network/managed_network_configuration_handler_impl.cc b/chromeos/network/managed_network_configuration_handler_impl.cc index f20cdcc3..c92e7f6 100644 --- a/chromeos/network/managed_network_configuration_handler_impl.cc +++ b/chromeos/network/managed_network_configuration_handler_impl.cc @@ -197,6 +197,7 @@ void ManagedNetworkConfigurationHandlerImpl::SendManagedProperties( // GetProperties void ManagedNetworkConfigurationHandlerImpl::GetProperties( + const std::string& userhash, const std::string& service_path, const network_handler::DictionaryResultCallback& callback, const network_handler::ErrorCallback& error_callback) { @@ -207,21 +208,30 @@ void ManagedNetworkConfigurationHandlerImpl::GetProperties( &ManagedNetworkConfigurationHandlerImpl::GetPropertiesCallback, weak_ptr_factory_.GetWeakPtr(), base::Bind(&ManagedNetworkConfigurationHandlerImpl::SendProperties, - weak_ptr_factory_.GetWeakPtr(), callback, error_callback)), + weak_ptr_factory_.GetWeakPtr(), userhash, callback, + error_callback)), error_callback); } void ManagedNetworkConfigurationHandlerImpl::SendProperties( + const std::string& userhash, const network_handler::DictionaryResultCallback& callback, const network_handler::ErrorCallback& error_callback, const std::string& service_path, scoped_ptr<base::DictionaryValue> shill_properties) { const NetworkState* network_state = network_state_handler_->GetNetworkState(service_path); + + std::string guid; + shill_properties->GetStringWithoutPathExpansion(shill::kGuidProperty, &guid); + + ::onc::ONCSource onc_source; + FindPolicyByGUID(userhash, guid, &onc_source); + scoped_ptr<base::DictionaryValue> onc_network( - onc::TranslateShillServiceToONCPart( - *shill_properties, ::onc::ONC_SOURCE_UNKNOWN, - &onc::kNetworkWithStateSignature, network_state)); + onc::TranslateShillServiceToONCPart(*shill_properties, onc_source, + &onc::kNetworkWithStateSignature, + network_state)); callback.Run(service_path, *onc_network); } diff --git a/chromeos/network/managed_network_configuration_handler_impl.h b/chromeos/network/managed_network_configuration_handler_impl.h index a2812ef..a204b04 100644 --- a/chromeos/network/managed_network_configuration_handler_impl.h +++ b/chromeos/network/managed_network_configuration_handler_impl.h @@ -42,6 +42,7 @@ class CHROMEOS_EXPORT ManagedNetworkConfigurationHandlerImpl void RemoveObserver(NetworkPolicyObserver* observer) override; void GetProperties( + const std::string& userhash, const std::string& service_path, const network_handler::DictionaryResultCallback& callback, const network_handler::ErrorCallback& error_callback) override; @@ -140,11 +141,11 @@ class CHROMEOS_EXPORT ManagedNetworkConfigurationHandlerImpl scoped_ptr<base::DictionaryValue> shill_properties); // Sends the response to the caller of GetProperties. - void SendProperties( - const network_handler::DictionaryResultCallback& callback, - const network_handler::ErrorCallback& error_callback, - const std::string& service_path, - scoped_ptr<base::DictionaryValue> shill_properties); + void SendProperties(const std::string& userhash, + const network_handler::DictionaryResultCallback& callback, + const network_handler::ErrorCallback& error_callback, + const std::string& service_path, + scoped_ptr<base::DictionaryValue> shill_properties); const Policies* GetPoliciesForUser(const std::string& userhash) const; const Policies* GetPoliciesForProfile(const NetworkProfile& profile) const; diff --git a/chromeos/network/mock_managed_network_configuration_handler.h b/chromeos/network/mock_managed_network_configuration_handler.h index 0ba3579..0af4862 100644 --- a/chromeos/network/mock_managed_network_configuration_handler.h +++ b/chromeos/network/mock_managed_network_configuration_handler.h @@ -24,8 +24,9 @@ class CHROMEOS_EXPORT MockManagedNetworkConfigurationHandler // ManagedNetworkConfigurationHandler overrides MOCK_METHOD1(AddObserver, void(NetworkPolicyObserver* observer)); MOCK_METHOD1(RemoveObserver, void(NetworkPolicyObserver* observer)); - MOCK_METHOD3(GetProperties, - void(const std::string& service_path, + MOCK_METHOD4(GetProperties, + void(const std::string& userhash, + const std::string& service_path, const network_handler::DictionaryResultCallback& callback, const network_handler::ErrorCallback& error_callback)); MOCK_METHOD4(GetManagedProperties, diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc index 93c12e4..f86902a 100644 --- a/chromeos/network/network_state.cc +++ b/chromeos/network/network_state.cc @@ -79,12 +79,12 @@ namespace chromeos { NetworkState::NetworkState(const std::string& path) : ManagedState(MANAGED_TYPE_NETWORK, path), visible_(false), + priority_(0), prefix_length_(0), connectable_(false), is_captive_portal_(false), signal_strength_(0), - cellular_out_of_credits_(false) { -} + cellular_out_of_credits_(false) {} NetworkState::~NetworkState() { } @@ -141,6 +141,8 @@ bool NetworkState::PropertyChanged(const std::string& key, } raw_ssid_.clear(); return base::HexStringToBytes(ssid_hex, &raw_ssid_); + } else if (key == shill::kPriorityProperty) { + return GetIntegerValue(key, value, &priority_); } else if (key == shill::kOutOfCreditsProperty) { return GetBooleanValue(key, value, &cellular_out_of_credits_); } else if (key == shill::kProxyConfigProperty) { @@ -229,6 +231,8 @@ void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const { security_class()); dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty, profile_path()); + dictionary->SetIntegerWithoutPathExpansion(shill::kPriorityProperty, + priority_); if (visible()) { dictionary->SetStringWithoutPathExpansion(shill::kStateProperty, diff --git a/chromeos/network/network_state.h b/chromeos/network/network_state.h index 518e568..b271ca2 100644 --- a/chromeos/network/network_state.h +++ b/chromeos/network/network_state.h @@ -158,6 +158,7 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState { std::string connection_state_; std::string profile_path_; std::vector<uint8_t> raw_ssid_; // Unknown encoding. Not necessarily UTF-8. + int priority_; // Reflects the current Shill Service.Error property. This might get cleared // by Shill shortly after a failure. diff --git a/components/wifi_sync/wifi_config_delegate_chromeos_unittest.cc b/components/wifi_sync/wifi_config_delegate_chromeos_unittest.cc index 2a9cfac..1ff94f8 100644 --- a/components/wifi_sync/wifi_config_delegate_chromeos_unittest.cc +++ b/components/wifi_sync/wifi_config_delegate_chromeos_unittest.cc @@ -39,6 +39,7 @@ class FakeManagedNetworkConfigurationHandler NOTIMPLEMENTED(); } void GetProperties( + const std::string& userhash, const std::string& service_path, const DictionaryResultCallback& callback, const ErrorCallback& error_callback) override { diff --git a/extensions/browser/api/networking_config/networking_config_service.cc b/extensions/browser/api/networking_config/networking_config_service.cc index 7b4e5ec..b9b4233 100644 --- a/extensions/browser/api/networking_config/networking_config_service.cc +++ b/extensions/browser/api/networking_config/networking_config_service.cc @@ -217,10 +217,13 @@ void NetworkingConfigService::DispatchPortalDetectedEvent( return; const std::string service_path = network->path(); + // We do not provide |userhash| here because we only care about properties + // that are not affected by policy, i.e BSSID. network_handler->managed_network_configuration_handler()->GetProperties( - service_path, base::Bind(&NetworkingConfigService::OnGotProperties, - weak_factory_.GetWeakPtr(), extension_id, guid, - authentication_callback), + "" /* empty userhash */, service_path, + base::Bind(&NetworkingConfigService::OnGotProperties, + weak_factory_.GetWeakPtr(), extension_id, guid, + authentication_callback), base::Bind(&NetworkingConfigService::OnGetPropertiesFailed, weak_factory_.GetWeakPtr(), extension_id, guid)); } diff --git a/extensions/browser/api/networking_private/networking_private_chromeos.cc b/extensions/browser/api/networking_private/networking_private_chromeos.cc index b8c18e4..fb04158 100644 --- a/extensions/browser/api/networking_private/networking_private_chromeos.cc +++ b/extensions/browser/api/networking_private/networking_private_chromeos.cc @@ -182,8 +182,14 @@ void NetworkingPrivateChromeOS::GetProperties( return; } + std::string user_id_hash; + if (!GetUserIdHash(browser_context_, &user_id_hash, &error)) { + failure_callback.Run(error); + return; + } + GetManagedConfigurationHandler()->GetProperties( - service_path, + user_id_hash, service_path, base::Bind(&NetworkHandlerDictionaryCallback, success_callback), base::Bind(&NetworkHandlerFailureCallback, failure_callback)); } |