summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorpneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-01 15:44:56 +0000
committerpneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-01 15:44:56 +0000
commit7be0abbd8ad0b5d1d5f20dd0145e387006c588c4 (patch)
treeed5b4983cf0f5a5297dffe2b866acdb53132383e /chromeos
parent6118f96b6a4a2e172e6f8ed4f297b8748cd22cd3 (diff)
downloadchromium_src-7be0abbd8ad0b5d1d5f20dd0145e387006c588c4.zip
chromium_src-7be0abbd8ad0b5d1d5f20dd0145e387006c588c4.tar.gz
chromium_src-7be0abbd8ad0b5d1d5f20dd0145e387006c588c4.tar.bz2
Refactor access to the ONC policy for a network.
Instead of relying on a value stored in Shill (namely, onc_source in UIData) and caching that in NetworkState, directly access the new ONC preference in Chrome to check whether a network is managed or not. Proxy settings worked already in that way. With this change internet_options_handler uses the same code path. The only functional change is that a policy indicator will also be visible in the NetworkList of chrome://settings if Ethernet is managed. BUG=126870 (for API changes; network_state_informer.cc, preferences_browsertest.cc) R=bartfab@chromium.org, stevenjb@chromium.org TBR=nkostylev@chromium.org, ygorshenin@chromium.org Review URL: https://codereview.chromium.org/23609047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/network/favorite_state.cc33
-rw-r--r--chromeos/network/favorite_state.h11
-rw-r--r--chromeos/network/network_state.cc30
-rw-r--r--chromeos/network/network_state.h14
-rw-r--r--chromeos/network/network_state_handler.cc11
-rw-r--r--chromeos/network/network_state_handler.h4
-rw-r--r--chromeos/network/network_ui_data.cc4
-rw-r--r--chromeos/network/network_ui_data.h4
8 files changed, 60 insertions, 51 deletions
diff --git a/chromeos/network/favorite_state.cc b/chromeos/network/favorite_state.cc
index 66efe55..f1a2584 100644
--- a/chromeos/network/favorite_state.cc
+++ b/chromeos/network/favorite_state.cc
@@ -5,11 +5,12 @@
#include "chromeos/network/favorite_state.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
-#include "base/values.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_profile_handler.h"
#include "chromeos/network/network_state.h"
+#include "chromeos/network/onc/onc_utils.h"
#include "chromeos/network/shill_property_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
@@ -39,18 +40,36 @@ bool FavoriteState::PropertyChanged(const std::string& key,
return true;
} else if (key == shill::kGuidProperty) {
return GetStringValue(key, value, &guid_);
+ } else if (key == shill::kProxyConfigProperty) {
+ std::string proxy_config_str;
+ if (!value.GetAsString(&proxy_config_str)) {
+ NET_LOG_ERROR("Failed to parse " + key, path());
+ return false;
+ }
+
+ proxy_config_.Clear();
+ if (proxy_config_str.empty())
+ return true;
+
+ scoped_ptr<base::DictionaryValue> proxy_config_dict(
+ onc::ReadDictionaryFromJson(proxy_config_str));
+ if (proxy_config_dict) {
+ // Warning: The DictionaryValue returned from
+ // ReadDictionaryFromJson/JSONParser is an optimized derived class that
+ // doesn't allow releasing ownership of nested values. A Swap in the wrong
+ // order leads to memory access errors.
+ proxy_config_.MergeDictionary(proxy_config_dict.get());
+ } else {
+ NET_LOG_ERROR("Failed to parse " + key, path());
+ }
+ return true;
}
return false;
}
-bool FavoriteState::IsManaged() const {
- return ui_data_.onc_source() == onc::ONC_SOURCE_DEVICE_POLICY ||
- ui_data_.onc_source() == onc::ONC_SOURCE_USER_POLICY;
-}
-
bool FavoriteState::IsPrivate() const {
return !profile_path_.empty() &&
- profile_path_ != NetworkProfileHandler::kSharedProfilePath;
+ profile_path_ != NetworkProfileHandler::kSharedProfilePath;
}
} // namespace chromeos
diff --git a/chromeos/network/favorite_state.h b/chromeos/network/favorite_state.h
index 1eaadf5..9fbe3ea 100644
--- a/chromeos/network/favorite_state.h
+++ b/chromeos/network/favorite_state.h
@@ -5,6 +5,9 @@
#ifndef CHROMEOS_NETWORK_FAVORITE_STATE_H_
#define CHROMEOS_NETWORK_FAVORITE_STATE_H_
+#include <string>
+
+#include "base/values.h"
#include "chromeos/network/managed_state.h"
#include "chromeos/network/network_ui_data.h"
#include "chromeos/network/onc/onc_constants.h"
@@ -32,11 +35,9 @@ class CHROMEOS_EXPORT FavoriteState : public ManagedState {
const std::string& profile_path() const { return profile_path_; }
bool is_favorite() const { return !profile_path_.empty(); }
const NetworkUIData& ui_data() const { return ui_data_; }
+ const base::DictionaryValue& proxy_config() const { return proxy_config_; }
const std::string& guid() const { return guid_; }
- // Returns true if the ONC source is a device or user policy.
- bool IsManaged() const;
-
// Returns true if the network properties are stored in a user profile.
bool IsPrivate() const;
@@ -45,6 +46,10 @@ class CHROMEOS_EXPORT FavoriteState : public ManagedState {
NetworkUIData ui_data_;
std::string guid_;
+ // TODO(pneubeck): Remove this once (Managed)NetworkConfigurationHandler
+ // provides proxy configuration. crbug.com/241775
+ base::DictionaryValue proxy_config_;
+
DISALLOW_COPY_AND_ASSIGN(FavoriteState);
};
diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc
index 3a0a1fb..6c41f41 100644
--- a/chromeos/network/network_state.cc
+++ b/chromeos/network/network_state.cc
@@ -5,10 +5,10 @@
#include "chromeos/network/network_state.h"
#include "base/strings/stringprintf.h"
+#include "base/values.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_profile_handler.h"
#include "chromeos/network/network_util.h"
-#include "chromeos/network/onc/onc_utils.h"
#include "chromeos/network/shill_property_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
@@ -126,29 +126,6 @@ bool NetworkState::PropertyChanged(const std::string& key,
return GetStringValue(key, value, &roaming_);
} else if (key == shill::kSecurityProperty) {
return GetStringValue(key, value, &security_);
- } else if (key == shill::kProxyConfigProperty) {
- std::string proxy_config_str;
- if (!value.GetAsString(&proxy_config_str)) {
- NET_LOG_ERROR("Failed to parse " + key, path());
- return false;
- }
-
- proxy_config_.Clear();
- if (proxy_config_str.empty())
- return true;
-
- scoped_ptr<base::DictionaryValue> proxy_config_dict(
- onc::ReadDictionaryFromJson(proxy_config_str));
- if (proxy_config_dict) {
- // Warning: The DictionaryValue returned from
- // ReadDictionaryFromJson/JSONParser is an optimized derived class that
- // doesn't allow releasing ownership of nested values. A Swap in the wrong
- // order leads to memory access errors.
- proxy_config_.MergeDictionary(proxy_config_dict.get());
- } else {
- NET_LOG_ERROR("Failed to parse " + key, path());
- }
- return true;
} else if (key == shill::kUIDataProperty) {
scoped_ptr<NetworkUIData> new_ui_data =
shill_property_util::GetUIDataFromValue(value);
@@ -253,11 +230,6 @@ bool NetworkState::IsConnectingState() const {
return StateIsConnecting(connection_state_);
}
-bool NetworkState::IsManaged() const {
- return ui_data_.onc_source() == onc::ONC_SOURCE_DEVICE_POLICY ||
- ui_data_.onc_source() == onc::ONC_SOURCE_USER_POLICY;
-}
-
bool NetworkState::IsPrivate() const {
return !profile_path_.empty() &&
profile_path_ != NetworkProfileHandler::kSharedProfilePath;
diff --git a/chromeos/network/network_state.h b/chromeos/network/network_state.h
index 1a7402d..de94a38 100644
--- a/chromeos/network/network_state.h
+++ b/chromeos/network/network_state.h
@@ -8,12 +8,16 @@
#include <string>
#include <vector>
-#include "base/values.h"
#include "chromeos/network/managed_state.h"
#include "chromeos/network/network_ui_data.h"
#include "chromeos/network/onc/onc_constants.h"
#include "url/gurl.h"
+namespace base {
+class DictionaryValue;
+class Value;
+}
+
namespace chromeos {
// Simple class to provide network state information about a network service.
@@ -50,7 +54,6 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
const std::string& error() const { return error_; }
bool connectable() const { return connectable_; }
- const base::DictionaryValue& proxy_config() const { return proxy_config_; }
const NetworkUIData& ui_data() const { return ui_data_; }
// IPConfig Properties. These require an extra call to ShillIPConfigClient,
@@ -83,9 +86,6 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
bool IsConnectedState() const;
bool IsConnectingState() const;
- // Returns true if the ONC source is a device or user policy.
- bool IsManaged() const;
-
// Returns true if the network properties are stored in a user profile.
bool IsPrivate() const;
@@ -123,10 +123,6 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
std::string error_;
bool connectable_;
- // TODO(pneubeck): Remove ProxyConfig once NetworkConfigurationHandler
- // provides proxy configuration. crbug.com/241775
- base::DictionaryValue proxy_config_;
-
// This is convenient to keep cached for now, but shouldn't be necessary;
// avoid using it if possible.
NetworkUIData ui_data_;
diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc
index ce70f3d..3d5ec13 100644
--- a/chromeos/network/network_state_handler.cc
+++ b/chromeos/network/network_state_handler.cc
@@ -188,6 +188,17 @@ const NetworkState* NetworkStateHandler::DefaultNetwork() const {
return network;
}
+const FavoriteState* NetworkStateHandler::DefaultFavoriteNetwork() const {
+ const NetworkState* default_network = DefaultNetwork();
+ if (!default_network)
+ return NULL;
+ const FavoriteState* default_favorite =
+ GetFavoriteState(default_network->path());
+ DCHECK(default_favorite);
+ DCHECK(default_favorite->update_received());
+ return default_favorite;
+}
+
const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
const NetworkTypePattern& type) const {
for (ManagedStateList::const_iterator iter = network_list_.begin();
diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h
index 3223b1e..8043cb3 100644
--- a/chromeos/network/network_state_handler.h
+++ b/chromeos/network/network_state_handler.h
@@ -125,6 +125,10 @@ class CHROMEOS_EXPORT NetworkStateHandler
// This is equivalent to ConnectedNetworkByType(kMatchTypeDefault).
const NetworkState* DefaultNetwork() const;
+ // Returns the FavoriteState associated to DefaultNetwork. Returns NULL if,
+ // and only if, DefaultNetwork returns NULL.
+ const FavoriteState* DefaultFavoriteNetwork() const;
+
// Returns the primary connected network of matching |type|, otherwise NULL.
const NetworkState* ConnectedNetworkByType(
const NetworkTypePattern& type) const;
diff --git a/chromeos/network/network_ui_data.cc b/chromeos/network/network_ui_data.cc
index 8d3e335..2190e86 100644
--- a/chromeos/network/network_ui_data.cc
+++ b/chromeos/network/network_ui_data.cc
@@ -113,6 +113,10 @@ NetworkUIData::NetworkUIData(const base::DictionaryValue& dict) {
NetworkUIData::~NetworkUIData() {
}
+void NetworkUIData::set_user_settings(scoped_ptr<base::DictionaryValue> dict) {
+ user_settings_ = dict.Pass();
+}
+
void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const {
dict->Clear();
diff --git a/chromeos/network/network_ui_data.h b/chromeos/network/network_ui_data.h
index 05abfbc..dd9d40a 100644
--- a/chromeos/network/network_ui_data.h
+++ b/chromeos/network/network_ui_data.h
@@ -64,9 +64,7 @@ class CHROMEOS_EXPORT NetworkUIData {
const base::DictionaryValue* user_settings() const {
return user_settings_.get();
}
- void set_user_settings(scoped_ptr<base::DictionaryValue> dict) {
- user_settings_ = dict.Pass();
- }
+ void set_user_settings(scoped_ptr<base::DictionaryValue> dict);
const std::string& policy_guid() const {
return policy_guid_;
}