summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc12
-rw-r--r--chrome/browser/resources/options/chromeos/internet_detail.js72
-rw-r--r--chrome/browser/resources/options/chromeos/onc_data.js9
-rw-r--r--chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc74
-rw-r--r--chrome/browser/ui/webui/options/chromeos/internet_options_handler.h4
-rw-r--r--chrome/test/data/extensions/api_test/networking/test.js53
-rw-r--r--chromeos/dbus/fake_shill_service_client.cc70
-rw-r--r--chromeos/network/managed_network_configuration_handler_impl.cc27
-rw-r--r--chromeos/network/network_util.cc8
-rw-r--r--chromeos/network/network_util.h3
-rw-r--r--chromeos/network/onc/onc_translator_onc_to_shill.cc7
11 files changed, 177 insertions, 162 deletions
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc b/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc
index d8b8cea..a2b706e 100644
--- a/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc
+++ b/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc
@@ -314,6 +314,10 @@ class NetworkingPrivateChromeOSApiTest : public ExtensionApiTest {
profile_test->AddService(kUser1ProfilePath, "stub_wifi2");
AddService("stub_vpn1", "vpn1", shill::kTypeVPN, shill::kStateOnline);
+ service_test_->SetServiceProperty(
+ "stub_vpn1", shill::kProviderTypeProperty,
+ base::StringValue(shill::kProviderOpenVpn));
+ profile_test->AddService(kUser1ProfilePath, "stub_vpn1");
content::RunAllPendingInMessageLoop();
}
@@ -401,8 +405,12 @@ IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetStateNonExistent) {
EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_;
}
-IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, SetProperties) {
- EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_;
+IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, SetWiFiProperties) {
+ EXPECT_TRUE(RunNetworkingSubtest("setWiFiProperties")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, SetVPNProperties) {
+ EXPECT_TRUE(RunNetworkingSubtest("setVPNProperties")) << message_;
}
IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, CreateNetwork) {
diff --git a/chrome/browser/resources/options/chromeos/internet_detail.js b/chrome/browser/resources/options/chromeos/internet_detail.js
index 3fdc203..31e5d5f 100644
--- a/chrome/browser/resources/options/chromeos/internet_detail.js
+++ b/chrome/browser/resources/options/chromeos/internet_detail.js
@@ -88,22 +88,6 @@ cr.define('options.internet', function() {
}
/**
- * Sends the 'checked' state of a control to chrome for a network.
- * @param {string} path The service path of the network.
- * @param {string} message The message to send to chrome.
- * @param {string} checkboxId The id of the checkbox with the value to send.
- * @param {string=} opt_action Optional action to record.
- */
- function sendCheckedIfEnabled(path, message, checkboxId, opt_action) {
- var checkbox = assertInstanceof($(checkboxId), HTMLInputElement);
- if (!checkbox.hidden && !checkbox.disabled) {
- chrome.send(message, [path, !!checkbox.checked]);
- if (opt_action)
- sendChromeMetricsAction(opt_action);
- }
- }
-
- /**
* Send metrics to Chrome when the detailed page is opened.
* @param {string} type The ONC type of the network being shown.
* @param {string} state The ONC network state.
@@ -834,7 +818,7 @@ cr.define('options.internet', function() {
stringFromValue(defaultApn['AccessPointName']);
activeApn['Username'] = stringFromValue(defaultApn['Username']);
activeApn['Password'] = stringFromValue(defaultApn['Password']);
- onc.setManagedProperty('Cellular.APN', activeApn);
+ onc.setProperty('Cellular.APN', activeApn);
chrome.send('setApn', [this.servicePath_,
activeApn['AccessPointName'],
activeApn['Username'],
@@ -862,7 +846,7 @@ cr.define('options.internet', function() {
activeApn['AccessPointName'] = stringFromValue(apnValue);
activeApn['Username'] = stringFromValue($('cellular-apn-username').value);
activeApn['Password'] = stringFromValue($('cellular-apn-password').value);
- onc.setManagedProperty('Cellular.APN', activeApn);
+ onc.setProperty('Cellular.APN', activeApn);
this.userApn_ = activeApn;
chrome.send('setApn', [this.servicePath_,
activeApn['AccessPointName'],
@@ -1086,32 +1070,34 @@ cr.define('options.internet', function() {
var detailsPage = DetailsInternetPage.getInstance();
var type = detailsPage.type_;
var servicePath = detailsPage.servicePath_;
+ var oncData = new OncData({});
+ var autoConnectCheckboxId = '';
if (type == 'WiFi') {
- sendCheckedIfEnabled(servicePath,
- 'setPreferNetwork',
- 'prefer-network-wifi',
- 'Options_NetworkSetPrefer');
- sendCheckedIfEnabled(servicePath,
- 'setAutoConnect',
- 'auto-connect-network-wifi',
- 'Options_NetworkAutoConnect');
+ var preferredCheckbox =
+ assertInstanceof($('prefer-network-wifi'), HTMLInputElement);
+ if (!preferredCheckbox.hidden && !preferredCheckbox.disabled) {
+ var kPreferredPriority = 1;
+ var priority = preferredCheckbox.checked ? kPreferredPriority : 0;
+ oncData.setProperty('Priority', priority);
+ sendChromeMetricsAction('Options_NetworkSetPrefer');
+ }
+ autoConnectCheckboxId = 'auto-connect-network-wifi';
} else if (type == 'WiMAX') {
- sendCheckedIfEnabled(servicePath,
- 'setAutoConnect',
- 'auto-connect-network-wimax',
- 'Options_NetworkAutoConnect');
+ autoConnectCheckboxId = 'auto-connect-network-wimax';
} else if (type == 'Cellular') {
- sendCheckedIfEnabled(servicePath,
- 'setAutoConnect',
- 'auto-connect-network-cellular',
- 'Options_NetworkAutoConnect');
+ autoConnectCheckboxId = 'auto-connect-network-cellular';
} else if (type == 'VPN') {
- chrome.send('setServerHostname',
- [servicePath, $('inet-server-hostname').value]);
- sendCheckedIfEnabled(servicePath,
- 'setAutoConnect',
- 'auto-connect-network-vpn',
- 'Options_NetworkAutoConnect');
+ oncData.setProperty('VPN.Host', $('inet-server-hostname').value);
+ autoConnectCheckboxId = 'auto-connect-network-vpn';
+ }
+ if (autoConnectCheckboxId != '') {
+ var autoConnectCheckbox =
+ assertInstanceof($(autoConnectCheckboxId), HTMLInputElement);
+ if (!autoConnectCheckbox.hidden && !autoConnectCheckbox.disabled) {
+ var autoConnectKey = type + '.AutoConnect';
+ oncData.setProperty(autoConnectKey, !!autoConnectCheckbox.checked);
+ sendChromeMetricsAction('Options_NetworkAutoConnect');
+ }
}
var nameServerTypes = ['automatic', 'google', 'user'];
@@ -1124,6 +1110,12 @@ cr.define('options.internet', function() {
}
detailsPage.sendIpConfig_(nameServerType);
+ var data = oncData.getData();
+ if (Object.keys(data).length > 0) {
+ // TODO(stevenjb): chrome.networkingPrivate.setProperties
+ chrome.send('setProperties', [servicePath, data]);
+ }
+
PageManager.closeOverlay();
};
diff --git a/chrome/browser/resources/options/chromeos/onc_data.js b/chrome/browser/resources/options/chromeos/onc_data.js
index d6dfcf6..4dd3067 100644
--- a/chrome/browser/resources/options/chromeos/onc_data.js
+++ b/chrome/browser/resources/options/chromeos/onc_data.js
@@ -49,7 +49,7 @@ cr.define('cr.onc', function() {
* @param {string} key The property key.
* @param {Object} value The property value to set.
*/
- setManagedProperty: function(key, value) {
+ setProperty: function(key, value) {
var data = this.data_;
while (true) {
var index = key.indexOf('.');
@@ -177,6 +177,13 @@ cr.define('cr.onc', function() {
return property[effective];
}
return undefined;
+ },
+
+ /**
+ * Returns the complete ONC dictionary.
+ */
+ getData: function() {
+ return this.data_;
}
};
diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
index 6a293d8..ce5f031a 100644
--- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
@@ -95,11 +95,8 @@ const char kUpdateCarrierFunction[] =
// Setter methods called from JS that still need to be converted to match
// networkingPrivate methods.
const char kSetApnMessage[] = "setApn";
-const char kSetAutoConnectMessage[] = "setAutoConnect";
const char kSetCarrierMessage[] = "setCarrier";
const char kSetIPConfigMessage[] = "setIPConfig";
-const char kSetPreferNetworkMessage[] = "setPreferNetwork";
-const char kSetServerHostname[] = "setServerHostname";
const char kShowMorePlanInfoMessage[] = "showMorePlanInfo";
const char kSimOperationMessage[] = "simOperation";
@@ -111,6 +108,7 @@ const char kGetManagedPropertiesMessage[] = "getManagedProperties";
const char kRequestNetworkScanMessage[] = "requestNetworkScan";
const char kStartConnectMessage[] = "startConnect";
const char kStartDisconnectMessage[] = "startDisconnect";
+const char kSetPropertiesMessage[] = "setProperties";
// TODO(stevenjb): Add these to networkingPrivate.
const char kRemoveNetworkMessage[] = "removeNetwork";
@@ -145,8 +143,6 @@ const char kNetworkInfoKeyServicePath[] = "servicePath";
const char kTagErrorMessage[] = "errorMessage";
const char kTagShowViewAccountButton[] = "showViewAccountButton";
-const int kPreferredPriority = 1;
-
void ShillError(const std::string& function,
const std::string& error_name,
scoped_ptr<base::DictionaryValue> error_data) {
@@ -164,19 +160,6 @@ const NetworkState* GetNetworkState(const std::string& service_path) {
GetNetworkState(service_path);
}
-void SetNetworkProperty(const std::string& service_path,
- const std::string& property,
- base::Value* value) {
- NET_LOG_EVENT("SetNetworkProperty: " + property, service_path);
- base::DictionaryValue properties;
- properties.SetWithoutPathExpansion(property, value);
- NetworkHandler::Get()->network_configuration_handler()->SetProperties(
- service_path, properties,
- NetworkConfigurationObserver::SOURCE_USER_ACTION,
- base::Bind(&base::DoNothing),
- base::Bind(&ShillError, "SetNetworkProperty"));
-}
-
// Builds a dictionary with network information and an icon used for the
// NetworkList on the settings page. Ownership of the returned pointer is
// transferred to the caller.
@@ -341,12 +324,6 @@ void InternetOptionsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(kActivateNetworkMessage,
base::Bind(&InternetOptionsHandler::ActivateNetwork,
base::Unretained(this)));
- web_ui()->RegisterMessageCallback(kSetPreferNetworkMessage,
- base::Bind(&InternetOptionsHandler::SetPreferNetworkCallback,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(kSetAutoConnectMessage,
- base::Bind(&InternetOptionsHandler::SetAutoConnectCallback,
- base::Unretained(this)));
web_ui()->RegisterMessageCallback(kSetIPConfigMessage,
base::Bind(&InternetOptionsHandler::SetIPConfigCallback,
base::Unretained(this)));
@@ -362,9 +339,6 @@ void InternetOptionsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(kSimOperationMessage,
base::Bind(&InternetOptionsHandler::SimOperationCallback,
base::Unretained(this)));
- web_ui()->RegisterMessageCallback(kSetServerHostname,
- base::Bind(&InternetOptionsHandler::SetServerHostnameCallback,
- base::Unretained(this)));
// networkingPrivate methods
web_ui()->RegisterMessageCallback(kDisableNetworkTypeMessage,
@@ -385,6 +359,9 @@ void InternetOptionsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(kStartDisconnectMessage,
base::Bind(&InternetOptionsHandler::StartDisconnectCallback,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(kSetPropertiesMessage,
+ base::Bind(&InternetOptionsHandler::SetPropertiesCallback,
+ base::Unretained(this)));
}
void InternetOptionsHandler::ShowMorePlanInfoCallback(
@@ -703,49 +680,20 @@ void InternetOptionsHandler::DevicePropertiesUpdated(
UpdateConnectionData(network->path());
}
-void InternetOptionsHandler::SetServerHostnameCallback(
- const base::ListValue* args) {
- std::string service_path, server_hostname;
- if (args->GetSize() < 2 ||
- !args->GetString(0, &service_path) ||
- !args->GetString(1, &server_hostname)) {
- NOTREACHED();
- return;
- }
- SetNetworkProperty(service_path,
- shill::kProviderHostProperty,
- new base::StringValue(server_hostname));
-}
-
-void InternetOptionsHandler::SetPreferNetworkCallback(
+void InternetOptionsHandler::SetPropertiesCallback(
const base::ListValue* args) {
std::string service_path;
- bool prefer_network;
+ const base::DictionaryValue* properties;
if (args->GetSize() < 2 ||
!args->GetString(0, &service_path) ||
- !args->GetBoolean(1, &prefer_network)) {
+ !args->GetDictionary(1, &properties)) {
NOTREACHED();
return;
}
- int priority = prefer_network ? kPreferredPriority : 0;
- SetNetworkProperty(service_path,
- shill::kPriorityProperty,
- new base::FundamentalValue(priority));
-}
-
-void InternetOptionsHandler::SetAutoConnectCallback(
- const base::ListValue* args) {
- std::string service_path;
- bool auto_connect;
- if (args->GetSize() < 2 ||
- !args->GetString(0, &service_path) ||
- !args->GetBoolean(1, &auto_connect)) {
- NOTREACHED();
- return;
- }
- SetNetworkProperty(service_path,
- shill::kAutoConnectProperty,
- new base::FundamentalValue(auto_connect));
+ NetworkHandler::Get()->managed_network_configuration_handler()->SetProperties(
+ service_path, *properties,
+ base::Bind(&base::DoNothing),
+ base::Bind(&ShillError, "SetProperties"));
}
void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) {
diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h
index 63eac6f1..5b4e24a 100644
--- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h
+++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h
@@ -101,9 +101,7 @@ class InternetOptionsHandler
void UpdateLoggedInUserType();
// Additional callbacks to set network state properties.
- void SetServerHostnameCallback(const base::ListValue* args);
- void SetPreferNetworkCallback(const base::ListValue* args);
- void SetAutoConnectCallback(const base::ListValue* args);
+ void SetPropertiesCallback(const base::ListValue* args);
void SetIPConfigCallback(const base::ListValue* args);
void SetIPConfigProperties(const base::ListValue* args,
const std::string& service_path,
diff --git a/chrome/test/data/extensions/api_test/networking/test.js b/chrome/test/data/extensions/api_test/networking/test.js
index c3e8b62..efa8dc5 100644
--- a/chrome/test/data/extensions/api_test/networking/test.js
+++ b/chrome/test/data/extensions/api_test/networking/test.js
@@ -373,23 +373,64 @@ var availableTests = [
}, result);
}));
},
- function setProperties() {
+ function setWiFiProperties() {
var done = chrome.test.callbackAdded();
- var network_guid = "stub_wifi2_guid";
+ var network_guid = "stub_wifi1_guid";
+ chrome.networkingPrivate.getProperties(
+ network_guid,
+ callbackPass(function(result) {
+ assertEq(network_guid, result.GUID);
+ var new_properties = {
+ Priority: 1,
+ WiFi: {
+ AutoConnect: true
+ }
+ };
+ chrome.networkingPrivate.setProperties(
+ network_guid,
+ new_properties,
+ callbackPass(function() {
+ chrome.networkingPrivate.getProperties(
+ network_guid,
+ callbackPass(function(result) {
+ // Ensure that the properties were set.
+ assertEq(1, result['Priority']);
+ assertTrue('WiFi' in result);
+ assertTrue('AutoConnect' in result['WiFi']);
+ assertEq(true, result['WiFi']['AutoConnect']);
+ // Ensure that the GUID doesn't change.
+ assertEq(network_guid, result.GUID);
+ done();
+ }));
+ }));
+ }));
+ },
+ function setVPNProperties() {
+ var done = chrome.test.callbackAdded();
+ var network_guid = "stub_vpn1_guid";
chrome.networkingPrivate.getProperties(
network_guid,
callbackPass(function(result) {
assertEq(network_guid, result.GUID);
- result.WiFi.Security = "WEP-PSK";
+ var new_properties = {
+ Priority: 1,
+ VPN: {
+ Host: 'vpn.host1'
+ }
+ };
chrome.networkingPrivate.setProperties(
network_guid,
- result,
+ new_properties,
callbackPass(function() {
chrome.networkingPrivate.getProperties(
network_guid,
callbackPass(function(result) {
- // Ensure that the property was set.
- assertEq("WEP-PSK", result.WiFi.Security);
+ console.log('Result: ' + JSON.stringify(result));
+ // Ensure that the properties were set.
+ assertEq(1, result['Priority']);
+ assertTrue('VPN' in result);
+ assertTrue('Host' in result['VPN']);
+ assertEq('vpn.host1', result['VPN']['Host']);
// Ensure that the GUID doesn't change.
assertEq(network_guid, result.GUID);
done();
diff --git a/chromeos/dbus/fake_shill_service_client.cc b/chromeos/dbus/fake_shill_service_client.cc
index b21ae61..9751972 100644
--- a/chromeos/dbus/fake_shill_service_client.cc
+++ b/chromeos/dbus/fake_shill_service_client.cc
@@ -344,7 +344,6 @@ void FakeShillServiceClient::AddServiceWithIPConfig(
AddManagerService(service_path, true);
}
-
base::DictionaryValue* FakeShillServiceClient::SetServiceProperties(
const std::string& service_path,
const std::string& guid,
@@ -358,11 +357,12 @@ base::DictionaryValue* FakeShillServiceClient::SetServiceProperties(
std::string profile_path;
base::DictionaryValue profile_properties;
- if (DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()->
- GetService(service_path, &profile_path, &profile_properties)) {
- properties->SetWithoutPathExpansion(
- shill::kProfileProperty,
- new base::StringValue(profile_path));
+ if (DBusThreadManager::Get()
+ ->GetShillProfileClient()
+ ->GetTestInterface()
+ ->GetService(service_path, &profile_path, &profile_properties)) {
+ properties->SetStringWithoutPathExpansion(shill::kProfileProperty,
+ profile_path);
}
// If |guid| is provided, set Service.GUID to that. Otherwise if a GUID is
@@ -370,39 +370,30 @@ base::DictionaryValue* FakeShillServiceClient::SetServiceProperties(
// not enforce a valid guid, we do that at the NetworkStateHandler layer.
std::string guid_to_set = guid;
if (guid_to_set.empty()) {
- profile_properties.GetStringWithoutPathExpansion(
- shill::kGuidProperty, &guid_to_set);
+ profile_properties.GetStringWithoutPathExpansion(shill::kGuidProperty,
+ &guid_to_set);
}
if (!guid_to_set.empty()) {
- properties->SetWithoutPathExpansion(shill::kGuidProperty,
- new base::StringValue(guid_to_set));
+ properties->SetStringWithoutPathExpansion(shill::kGuidProperty,
+ guid_to_set);
}
- shill_property_util::SetSSID(name, properties);
- properties->SetWithoutPathExpansion(
- shill::kNameProperty,
- new base::StringValue(name));
- std::string device_path =
- DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()->
- GetDevicePathForType(type);
- properties->SetWithoutPathExpansion(
- shill::kDeviceProperty,
- new base::StringValue(device_path));
- properties->SetWithoutPathExpansion(
- shill::kTypeProperty,
- new base::StringValue(type));
- properties->SetWithoutPathExpansion(
- shill::kStateProperty,
- new base::StringValue(state));
- properties->SetWithoutPathExpansion(
- shill::kVisibleProperty,
- new base::FundamentalValue(visible));
+ properties->SetStringWithoutPathExpansion(shill::kSSIDProperty, name);
+ shill_property_util::SetSSID(name, properties); // Sets kWifiHexSsid
+ properties->SetStringWithoutPathExpansion(shill::kNameProperty, name);
+ std::string device_path = DBusThreadManager::Get()
+ ->GetShillDeviceClient()
+ ->GetTestInterface()
+ ->GetDevicePathForType(type);
+ properties->SetStringWithoutPathExpansion(shill::kDeviceProperty,
+ device_path);
+ properties->SetStringWithoutPathExpansion(shill::kTypeProperty, type);
+ properties->SetStringWithoutPathExpansion(shill::kStateProperty, state);
+ properties->SetBooleanWithoutPathExpansion(shill::kVisibleProperty, visible);
if (type == shill::kTypeWifi) {
- properties->SetWithoutPathExpansion(
- shill::kSecurityProperty,
- new base::StringValue(shill::kSecurityNone));
- properties->SetWithoutPathExpansion(
- shill::kModeProperty,
- new base::StringValue(shill::kModeManaged));
+ properties->SetStringWithoutPathExpansion(shill::kSecurityProperty,
+ shill::kSecurityNone);
+ properties->SetStringWithoutPathExpansion(shill::kModeProperty,
+ shill::kModeManaged);
}
return properties;
}
@@ -431,9 +422,14 @@ bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path,
StartsWithASCII(property, "OpenVPN.", case_sensitive) ||
StartsWithASCII(property, "L2TPIPsec.", case_sensitive)) {
// These properties are only nested within the Provider dictionary if read
- // from Shill.
+ // from Shill. Properties that start with "Provider" need to have that
+ // stripped off, other properties are nested in the "Provider" dictionary
+ // as-is.
+ std::string key = property;
+ if (StartsWithASCII(property, "Provider.", case_sensitive))
+ key = property.substr(strlen("Provider."));
base::DictionaryValue* provider = new base::DictionaryValue;
- provider->SetWithoutPathExpansion(property, value.DeepCopy());
+ provider->SetWithoutPathExpansion(key, value.DeepCopy());
new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider);
changed_property = shill::kProviderProperty;
} else {
diff --git a/chromeos/network/managed_network_configuration_handler_impl.cc b/chromeos/network/managed_network_configuration_handler_impl.cc
index 3e6a324..eb16c55 100644
--- a/chromeos/network/managed_network_configuration_handler_impl.cc
+++ b/chromeos/network/managed_network_configuration_handler_impl.cc
@@ -28,6 +28,7 @@
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_ui_data.h"
+#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_merger.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_translator.h"
@@ -265,6 +266,15 @@ void ManagedNetworkConfigurationHandlerImpl::SetProperties(
return;
}
+ // We need to ensure that required configuration properties (e.g. Type) are
+ // included for ONC validation and translation to Shill properties.
+ scoped_ptr<base::DictionaryValue> user_settings_copy(
+ user_settings.DeepCopy());
+ user_settings_copy->SetStringWithoutPathExpansion(
+ ::onc::network_config::kType,
+ network_util::TranslateShillTypeToONC(state->type()));
+ user_settings_copy->MergeDictionary(&user_settings);
+
// Validate the ONC dictionary. We are liberal and ignore unknown field
// names. User settings are only partial ONC, thus we ignore missing fields.
onc::Validator validator(false, // Ignore unknown fields.
@@ -276,7 +286,7 @@ void ManagedNetworkConfigurationHandlerImpl::SetProperties(
scoped_ptr<base::DictionaryValue> validated_user_settings =
validator.ValidateAndRepairObject(
&onc::kNetworkConfigurationSignature,
- user_settings,
+ *user_settings_copy,
&validation_result);
if (validation_result == onc::Validator::INVALID) {
@@ -722,14 +732,17 @@ void ManagedNetworkConfigurationHandlerImpl::GetPropertiesCallback(
scoped_ptr<base::DictionaryValue> shill_properties_copy(
shill_properties.DeepCopy());
- // Add associated Device properties before the ONC translation.
- GetDeviceStateProperties(service_path, shill_properties_copy.get());
+ std::string type;
+ shill_properties_copy->GetStringWithoutPathExpansion(shill::kTypeProperty,
+ &type);
+ // Add associated DeviceState properties for non-VPN networks.
+ if (type != shill::kTypeVPN)
+ GetDeviceStateProperties(service_path, shill_properties_copy.get());
- // Only request Device properties for Cellular networks with a valid device.
- std::string type, device_path;
+ // Only request additional Device properties for Cellular networks with a
+ // valid device.
+ std::string device_path;
if (!network_device_handler_ ||
- !shill_properties_copy->GetStringWithoutPathExpansion(
- shill::kTypeProperty, &type) ||
type != shill::kTypeCellular ||
!shill_properties_copy->GetStringWithoutPathExpansion(
shill::kDeviceProperty, &device_path) ||
diff --git a/chromeos/network/network_util.cc b/chromeos/network/network_util.cc
index 7f0aaf8..1d84adf 100644
--- a/chromeos/network/network_util.cc
+++ b/chromeos/network/network_util.cc
@@ -191,5 +191,13 @@ std::string TranslateONCTypeToShill(const std::string& onc_type) {
return shill_type;
}
+std::string TranslateShillTypeToONC(const std::string& shill_type) {
+ if (shill_type == shill::kTypeEthernet)
+ return ::onc::network_type::kEthernet;
+ std::string onc_type;
+ onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type);
+ return onc_type;
+}
+
} // namespace network_util
} // namespace chromeos
diff --git a/chromeos/network/network_util.h b/chromeos/network/network_util.h
index 307f131..f07fdaf 100644
--- a/chromeos/network/network_util.h
+++ b/chromeos/network/network_util.h
@@ -114,6 +114,9 @@ CHROMEOS_EXPORT scoped_ptr<base::ListValue> TranslateNetworkListToONC(
// there is no match. Only valid for ethernet, wifi, wimax, cellular, and vpn.
CHROMEOS_EXPORT std::string TranslateONCTypeToShill(const std::string& type);
+// Inverse of TranslateONCTypeToShill.
+CHROMEOS_EXPORT std::string TranslateShillTypeToONC(const std::string& type);
+
} // namespace network_util
} // namespace chromeos
diff --git a/chromeos/network/onc/onc_translator_onc_to_shill.cc b/chromeos/network/onc/onc_translator_onc_to_shill.cc
index 69d0d41..5300a9d 100644
--- a/chromeos/network/onc/onc_translator_onc_to_shill.cc
+++ b/chromeos/network/onc/onc_translator_onc_to_shill.cc
@@ -218,8 +218,8 @@ void LocalTranslator::TranslateIPsec() {
void LocalTranslator::TranslateVPN() {
CopyFieldFromONCToShill(::onc::vpn::kHost, shill::kProviderHostProperty);
std::string type;
- onc_object_->GetStringWithoutPathExpansion(::onc::vpn::kType, &type);
- TranslateWithTableAndSet(type, kVPNTypeTable, shill::kProviderTypeProperty);
+ if (onc_object_->GetStringWithoutPathExpansion(::onc::vpn::kType, &type))
+ TranslateWithTableAndSet(type, kVPNTypeTable, shill::kProviderTypeProperty);
CopyFieldsAccordingToSignature();
}
@@ -232,7 +232,8 @@ void LocalTranslator::TranslateWiFi() {
std::string ssid;
onc_object_->GetStringWithoutPathExpansion(::onc::wifi::kSSID, &ssid);
- shill_property_util::SetSSID(ssid, shill_dictionary_);
+ if (!ssid.empty())
+ shill_property_util::SetSSID(ssid, shill_dictionary_);
// We currently only support managed and no adhoc networks.
shill_dictionary_->SetStringWithoutPathExpansion(shill::kModeProperty,