Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2810)

Unified Diff: chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc

Issue 427903004: Support Managed NetworkState format dictionaries for controlled settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
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 ca679e2e5a12353e1bdc4fc35a928c3775801c3b..51e2a9c8964122b7fe9c1ad47af92b100d0bb590 100644
--- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
@@ -126,7 +126,6 @@ const char kTagActivate[] = "activate";
const char kTagActivationState[] = "activationState";
const char kTagAddConnection[] = "add";
const char kTagApn[] = "apn";
-const char kTagAutoConnect[] = "autoConnect";
const char kTagCarrierSelectFlag[] = "showCarrierSelect";
const char kTagCarrierUrl[] = "carrierUrl";
const char kTagCellularAvailable[] = "cellularAvailable";
@@ -137,9 +136,8 @@ const char kTagConnect[] = "connect";
const char kTagControlledBy[] = "controlledBy";
const char kTagDeviceConnected[] = "deviceConnected";
const char kTagDisconnect[] = "disconnect";
-const char kTagErrorState[] = "errorState";
+const char kTagErrorMessage[] = "errorMessage";
const char kTagForget[] = "forget";
-const char kTagIdentity[] = "identity";
const char kTagLanguage[] = "language";
const char kTagLastGoodApn[] = "lastGoodApn";
const char kTagLocalizedName[] = "localizedName";
@@ -164,7 +162,6 @@ const char kTagCarriers[] = "carriers";
const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
const char kTagShared[] = "shared";
const char kTagShowActivateButton[] = "showActivateButton";
-const char kTagShowStaticIPConfig[] = "showStaticIPConfig";
const char kTagShowViewAccountButton[] = "showViewAccountButton";
const char kTagSimCardLockEnabled[] = "simCardLockEnabled";
const char kTagSupportUrl[] = "supportUrl";
@@ -295,57 +292,47 @@ base::DictionaryValue* BuildIPInfoDictionary(
return ip_info_dict.release();
}
-// Decorate dictionary |value_dict| with policy information from |ui_data|.
-void DecorateValueDictionary(const NetworkPropertyUIData& ui_data,
- const base::Value& value,
- base::DictionaryValue* value_dict) {
- const base::Value* recommended_value = ui_data.default_value();
- if (ui_data.IsManaged())
- value_dict->SetString(kTagControlledBy, kTagPolicy);
- else if (recommended_value && recommended_value->Equals(&value))
- value_dict->SetString(kTagControlledBy, kTagRecommended);
-
- if (recommended_value)
- value_dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
-}
-
// Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and
// store it under |key| in |settings|. Takes ownership of |value|.
-void SetValueDictionary(base::DictionaryValue* settings,
- const char* key,
+void SetValueDictionary(const char* key,
base::Value* value,
- const NetworkPropertyUIData& ui_data) {
+ const NetworkPropertyUIData& ui_data,
+ base::DictionaryValue* settings) {
base::DictionaryValue* dict = new base::DictionaryValue();
// DictionaryValue::Set() takes ownership of |value|.
dict->Set(kTagValue, value);
settings->Set(key, dict);
- DecorateValueDictionary(ui_data, *value, dict);
+
+ const base::Value* recommended_value = ui_data.default_value();
+ if (ui_data.IsManaged())
+ dict->SetString(kTagControlledBy, kTagPolicy);
+ else if (recommended_value && recommended_value->Equals(value))
+ dict->SetString(kTagControlledBy, kTagRecommended);
+
+ if (recommended_value)
+ dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
}
-// Creates a decorated dictionary like SetValueDictionary does, but extended for
-// the Autoconnect property, which respects additionally global network policy.
-void SetAutoconnectValueDictionary(bool network_is_private,
- ::onc::ONCSource onc_source,
- bool current_autoconnect,
- const NetworkPropertyUIData& ui_data,
- base::DictionaryValue* settings) {
+// Creates a GetManagedProperties style dictionary. Note(stevenjb): This is
+// bridge code until we use GetManagedProperties to retrieve Shill properties.
+void SetManagedValueDictionary(const char* key,
+ base::Value* value,
+ const NetworkPropertyUIData& ui_data,
+ base::DictionaryValue* settings) {
base::DictionaryValue* dict = new base::DictionaryValue();
- base::Value* value = new base::FundamentalValue(current_autoconnect);
- // DictionaryValue::Set() takes ownership of |value|.
- dict->Set(kTagValue, value);
- settings->Set(kTagAutoConnect, dict);
- if (onc_source != ::onc::ONC_SOURCE_USER_POLICY &&
- onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY) {
- // Autoconnect can be controlled by the GlobalNetworkConfiguration of the
- // ONC policy.
- bool only_policy_autoconnect =
- onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(network_is_private);
- if (only_policy_autoconnect) {
- dict->SetString(kTagControlledBy, kTagPolicy);
- return;
- }
- }
- DecorateValueDictionary(ui_data, *value, dict);
+ settings->Set(key, dict);
+ dict->Set(::onc::kAugmentationActiveSetting, value); // owns |value|
+
+ if (ui_data.onc_source() == ::onc::ONC_SOURCE_NONE)
pneubeck (no reviews) 2014/07/31 20:29:36 this is does not match the behavior of getManagedP
stevenjb 2014/08/01 00:53:41 OK, I looked at the NetworkPropertyUIData code, wh
+ return;
+
+ std::string effective;
+ if (ui_data.onc_source() == ::onc::ONC_SOURCE_DEVICE_POLICY)
+ effective = ::onc::kAugmentationDevicePolicy;
+ else
+ effective = ::onc::kAugmentationUserPolicy;
+ dict->SetString(::onc::kAugmentationEffectiveSetting, effective);
+ dict->Set(effective, ui_data.default_value()->DeepCopy());
}
std::string CopyStringFromDictionary(const base::DictionaryValue& source,
@@ -401,9 +388,10 @@ void PopulateVPNDetails(const NetworkState* vpn,
std::string provider_host;
provider_properties->GetStringWithoutPathExpansion(
shill::kHostProperty, &provider_host);
- SetValueDictionary(dictionary, kTagServerHostname,
+ SetValueDictionary(kTagServerHostname,
new base::StringValue(provider_host),
- hostname_ui_data);
+ hostname_ui_data,
+ dictionary);
}
// Given a list of supported carrier's by the device, return the index of
@@ -430,13 +418,6 @@ int FindCurrentCarrierIndex(const base::ListValue* carriers,
return -1;
}
-void PopulateWimaxDetails(const NetworkState* wimax,
- const base::DictionaryValue& shill_properties,
- base::DictionaryValue* dictionary) {
- CopyStringFromDictionary(
- shill_properties, shill::kEapIdentityProperty, kTagIdentity, dictionary);
-}
-
void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
base::DictionaryValue* dictionary) {
CopyStringFromDictionary(*apn, shill::kApnProperty, kTagApn, dictionary);
@@ -508,10 +489,10 @@ void PopulateCellularDetails(const NetworkState* cellular,
FindPolicyByGUID(LoginState::Get()->primary_user_hash(),
cellular->guid(), &onc_source);
const NetworkPropertyUIData cellular_property_ui_data(onc_source);
- SetValueDictionary(dictionary,
- kTagSimCardLockEnabled,
+ SetValueDictionary(kTagSimCardLockEnabled,
new base::FundamentalValue(device->sim_lock_enabled()),
- cellular_property_ui_data);
+ cellular_property_ui_data,
+ dictionary);
carrier_id = device->home_provider_id();
device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn);
@@ -538,10 +519,10 @@ void PopulateCellularDetails(const NetworkState* cellular,
}
}
}
- SetValueDictionary(dictionary,
- kTagProviderApnList,
+ SetValueDictionary(kTagProviderApnList,
apn_list_value,
- cellular_property_ui_data);
+ cellular_property_ui_data,
+ dictionary);
const base::ListValue* supported_carriers;
if (device_properties.GetListWithoutPathExpansion(
shill::kSupportedCarriersProperty, &supported_carriers)) {
@@ -621,8 +602,15 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
NetworkHandler::Get()->network_state_handler()->GetDeviceState(
network->device_path());
if (device) {
- shill_properties_with_device->Set(shill::kDeviceProperty,
- device->properties().DeepCopy());
+ shill_properties_with_device->SetWithoutPathExpansion(
+ shill::kDeviceProperty, device->properties().DeepCopy());
+ // Get the hardware MAC address from the DeviceState.
+ // (Note: this is done in ManagedNetworkConfigurationHandler but not
+ // in NetworkConfigurationHandler).
+ if (!device->mac_address().empty()) {
+ shill_properties_with_device->SetStringWithoutPathExpansion(
+ shill::kAddressProperty, device->mac_address());
+ }
}
scoped_ptr<base::DictionaryValue> dictionary =
onc::TranslateShillServiceToONCPart(
@@ -630,7 +618,7 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
dictionary->SetString(
- kTagErrorState,
+ kTagErrorMessage,
ash::network_connect::ErrorString(network->error(), network->path()));
dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty());
@@ -644,9 +632,7 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
NetworkTypePattern::Primitive(type));
dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
- if (type == shill::kTypeWimax)
- PopulateWimaxDetails(network, shill_properties, dictionary.get());
- else if (type == shill::kTypeCellular)
+ if (type == shill::kTypeCellular)
PopulateCellularDetails(network, shill_properties, dictionary.get());
else if (type == shill::kTypeVPN)
PopulateVPNDetails(network, shill_properties, dictionary.get());
@@ -1272,10 +1258,10 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers);
ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl,
network->web_proxy_auto_discovery_url().spec());
- SetValueDictionary(dictionary.get(),
- kDictionaryIpConfig,
+ SetValueDictionary(kDictionaryIpConfig,
ipconfig_dhcp.release(),
- property_ui_data);
+ property_ui_data,
+ dictionary.get());
std::string name_server_type = kNameServerTypeAutomatic;
int automatic_ip_config = 0;
@@ -1300,26 +1286,22 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
if (ipconfig_name_servers == kGoogleNameServers) {
name_server_type = kNameServerTypeGoogle;
}
- SetValueDictionary(dictionary.get(),
- kDictionaryStaticIp,
+ SetValueDictionary(kDictionaryStaticIp,
static_ip_dict.release(),
- property_ui_data);
+ property_ui_data,
+ dictionary.get());
dictionary->SetString(kTagNameServerType, name_server_type);
dictionary->SetString(kTagNameServersGoogle, kGoogleNameServers);
- // Enable static ip config for Ethernet or WiFi.
- bool staticIPConfig = network->Matches(NetworkTypePattern::Ethernet()) ||
- network->Matches(NetworkTypePattern::WiFi());
- dictionary->SetBoolean(kTagShowStaticIPConfig, staticIPConfig);
-
int priority = 0;
shill_properties.GetIntegerWithoutPathExpansion(
shill::kPriorityProperty, &priority);
bool preferred = priority > 0;
- SetValueDictionary(dictionary.get(), kTagPreferred,
+ SetValueDictionary(kTagPreferred,
new base::FundamentalValue(preferred),
- property_ui_data);
+ property_ui_data,
+ dictionary.get());
NetworkPropertyUIData auto_connect_ui_data(onc_source);
std::string onc_path_to_auto_connect;
@@ -1356,11 +1338,27 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
bool auto_connect = false;
shill_properties.GetBooleanWithoutPathExpansion(
shill::kAutoConnectProperty, &auto_connect);
- SetAutoconnectValueDictionary(network->IsPrivate(),
- onc_source,
- auto_connect,
- auto_connect_ui_data,
- dictionary.get());
+
+ // Autoconnect can be controlled by the GlobalNetworkConfiguration of the
+ // ONC policy.
+ scoped_ptr<base::Value> auto_connect_value(
+ new base::FundamentalValue(auto_connect));
+ if (auto_connect_ui_data.onc_source() != ::onc::ONC_SOURCE_NONE &&
+ onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(network->IsPrivate())) {
+ ::onc::ONCSource source = network->IsPrivate()
+ ? ::onc::ONC_SOURCE_USER_POLICY : ::onc::ONC_SOURCE_DEVICE_POLICY;
+ // This modifies auto_connect_ui_data, so that the autoconnect value
+ // appears to be set to 'false' by policy and not editable by the user.
+ if (auto_connect) {
+ LOG(WARNING) << "Policy prevents autoconnect, but values is True.";
+ auto_connect_value.reset(new base::FundamentalValue(false));
+ }
+ auto_connect_ui_data.SetOncSourceAndValue(source, auto_connect_value.get());
+ }
+ SetManagedValueDictionary(shill::kAutoConnectProperty,
+ auto_connect_value.release(),
+ auto_connect_ui_data,
+ dictionary.get());
// Show details dialog
web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary);

Powered by Google App Engine
This is Rietveld 408576698