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

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: Don't use NetworkPropertyUIData to generate Managed dictionaries Created 6 years, 4 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..48123619f54e2bd2c835acd9bb9c765035655bf5 100644
--- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc
@@ -44,6 +44,7 @@
#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_translator.h"
+#include "chromeos/network/onc/onc_utils.h"
#include "components/onc/onc_constants.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
@@ -126,7 +127,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 +137,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 +163,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 +293,61 @@ 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());
+}
+
+const char* GetOncSourceString(::onc::ONCSource onc_source) {
+ if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
+ return ::onc::kAugmentationDevicePolicy;
+ return ::onc::kAugmentationUserPolicy;
}
-// 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 and adds it to |settings|.
+// Note(stevenjb): This is bridge code until we use GetManagedProperties to
+// retrieve Shill properties.
+void SetManagedValueDictionary(const char* key,
+ const base::Value* value,
+ ::onc::ONCSource onc_source,
+ bool recommended,
+ const base::Value* default_value,
pneubeck2 2014/08/06 07:13:07 nit: drop a comment that this 'default_value' can
stevenjb 2014/08/06 16:29:44 Done.
+ 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;
- }
+ settings->Set(key, dict);
+ dict->Set(::onc::kAugmentationActiveSetting, value->DeepCopy());
+
+ if (onc_source == ::onc::ONC_SOURCE_NONE)
+ return;
+
+ if (recommended) {
+ // If an ONC property is 'Recommended' it can be edited by the user.
+ std::string editable = onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY
+ ? ::onc::kAugmentationDeviceEditable
+ : ::onc::kAugmentationUserEditable;
+ dict->Set(editable, new base::FundamentalValue(true));
+ }
+ if (default_value) {
+ std::string effective = GetOncSourceString(onc_source);
+ dict->SetString(::onc::kAugmentationEffectiveSetting, effective);
pneubeck2 2014/08/06 07:13:08 Please consider the following case: Policy recomm
stevenjb 2014/08/06 16:29:43 Could you add this as an example to the ONC doc wh
stevenjb 2014/08/06 16:29:43 Done.
+ dict->Set(effective, default_value->DeepCopy());
}
- DecorateValueDictionary(ui_data, *value, dict);
}
std::string CopyStringFromDictionary(const base::DictionaryValue& source,
@@ -401,9 +403,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 +433,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 +504,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 +534,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 +617,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 +633,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 +647,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 +1273,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,28 +1301,23 @@ 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;
if (network->Matches(NetworkTypePattern::WiFi())) {
content::RecordAction(
@@ -1349,18 +1345,42 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
"Options_NetworkShowDetailsCellularConnected"));
}
}
+
if (!onc_path_to_auto_connect.empty()) {
- auto_connect_ui_data.ParseOncProperty(
- onc_source, onc, onc_path_to_auto_connect);
+ bool auto_connect = false;
+ shill_properties.GetBooleanWithoutPathExpansion(
+ shill::kAutoConnectProperty, &auto_connect);
+
+ scoped_ptr<base::Value> auto_connect_value(
+ new base::FundamentalValue(auto_connect));
+ ::onc::ONCSource auto_connect_onc_source = onc_source;
+ bool auto_connect_recommended =
+ auto_connect_onc_source != ::onc::ONC_SOURCE_NONE &&
+ onc::IsRecommendedValue(onc, onc_path_to_auto_connect);
+ const base::Value* auto_connect_default_value = NULL;
pneubeck2 2014/08/06 07:13:08 nit: drop a comment that this 'default_value' can
stevenjb 2014/08/06 16:29:43 Done.
+ onc->Get(onc_path_to_auto_connect, &auto_connect_default_value);
+
+ // Autoconnect can be controlled by the GlobalNetworkConfiguration of the
+ // ONC policy.
+ if (auto_connect_onc_source != ::onc::ONC_SOURCE_NONE &&
pneubeck2 2014/08/06 07:13:08 This policy applies to all unmanaged networks (net
stevenjb 2014/08/06 16:29:43 Done.
stevenjb 2014/08/06 16:29:44 This took me a while to parse. By "this policy" I
+ onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(
+ network->IsPrivate())) {
+ auto_connect_recommended = false;
+ auto_connect_onc_source = network->IsPrivate()
+ ? ::onc::ONC_SOURCE_USER_POLICY
+ : ::onc::ONC_SOURCE_DEVICE_POLICY;
+ if (auto_connect) {
+ LOG(WARNING) << "Policy prevents autoconnect, but value is True.";
+ auto_connect_value.reset(new base::FundamentalValue(false));
+ }
+ }
+ SetManagedValueDictionary(shill::kAutoConnectProperty,
+ auto_connect_value.get(),
+ auto_connect_onc_source,
+ auto_connect_recommended,
+ auto_connect_default_value,
+ dictionary.get());
}
- bool auto_connect = false;
- shill_properties.GetBooleanWithoutPathExpansion(
- shill::kAutoConnectProperty, &auto_connect);
- SetAutoconnectValueDictionary(network->IsPrivate(),
- onc_source,
- auto_connect,
- auto_connect_ui_data,
- dictionary.get());
// Show details dialog
web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary);

Powered by Google App Engine
This is Rietveld 408576698