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

Unified Diff: chrome/browser/policy/network_configuration_updater.cc

Issue 10377115: Refactored NetworkConfigurationUpdater to read policy from the PolicyService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Invoke callbacks the right way Created 8 years, 7 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/policy/network_configuration_updater.cc
diff --git a/chrome/browser/policy/network_configuration_updater.cc b/chrome/browser/policy/network_configuration_updater.cc
index 152927acee8b481610564f73ef95ee31bc08e6c5..a05b6b0e6edeec054f7aaf47944b4c248ebf1c2a 100644
--- a/chrome/browser/policy/network_configuration_updater.cc
+++ b/chrome/browser/policy/network_configuration_updater.cc
@@ -4,6 +4,10 @@
#include "chrome/browser/policy/network_configuration_updater.h"
+#include <string>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/policy/policy_map.h"
#include "policy/policy_constants.h"
@@ -14,49 +18,48 @@ const char NetworkConfigurationUpdater::kEmptyConfiguration[] =
"{\"NetworkConfigurations\":[],\"Certificates\":[]}";
NetworkConfigurationUpdater::NetworkConfigurationUpdater(
- ConfigurationPolicyProvider* provider,
+ PolicyService* policy_service,
chromeos::NetworkLibrary* network_library)
- : network_library_(network_library) {
+ : policy_change_registrar_(
+ policy_service, POLICY_DOMAIN_CHROME, std::string()),
+ network_library_(network_library) {
DCHECK(network_library_);
- provider_registrar_.Init(provider, this);
- Update();
-}
+ PolicyChangeRegistrar::UpdateCallback device_update_callback =
+ base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration,
+ base::Unretained(this),
+ chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY,
+ &device_network_config_);
+ PolicyChangeRegistrar::UpdateCallback user_update_callback =
+ base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration,
+ base::Unretained(this),
+ chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY,
+ &user_network_config_);
+ policy_change_registrar_.Observe(key::kDeviceOpenNetworkConfiguration,
+ device_update_callback);
Mattias Nissler (ping if slow) 2012/05/14 08:14:25 no need for locals for the callbacks?
Joao da Silva 2012/05/16 09:36:03 Done.
+ policy_change_registrar_.Observe(key::kOpenNetworkConfiguration,
+ user_update_callback);
-NetworkConfigurationUpdater::~NetworkConfigurationUpdater() {}
-
-void NetworkConfigurationUpdater::OnUpdatePolicy(
- ConfigurationPolicyProvider* provider) {
- Update();
+ // Apply the current values immediately.
+ const PolicyMap& policies = policy_service->GetPolicies(POLICY_DOMAIN_CHROME,
+ std::string());
+ device_update_callback.Run(
+ NULL, policies.GetValue(key::kDeviceOpenNetworkConfiguration));
+ user_update_callback.Run(
+ NULL, policies.GetValue(key::kOpenNetworkConfiguration));
}
-void NetworkConfigurationUpdater::Update() {
- ConfigurationPolicyProvider* provider = provider_registrar_.provider();
-
- PolicyMap policy;
- if (!provider->Provide(&policy)) {
- LOG(WARNING) << "Failed to read policy from policy provider.";
- return;
- }
-
- ApplyNetworkConfiguration(policy, key::kDeviceOpenNetworkConfiguration,
- chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY,
- &device_network_config_);
- ApplyNetworkConfiguration(policy, key::kOpenNetworkConfiguration,
- chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY,
- &user_network_config_);
-}
+NetworkConfigurationUpdater::~NetworkConfigurationUpdater() {}
void NetworkConfigurationUpdater::ApplyNetworkConfiguration(
- const PolicyMap& policy_map,
- const char* policy_name,
chromeos::NetworkUIData::ONCSource onc_source,
- std::string* cached_value) {
+ std::string* cached_value,
+ const base::Value* previous,
+ const base::Value* current) {
std::string new_network_config;
- const base::Value* value = policy_map.GetValue(policy_name);
- if (value != NULL) {
+ if (current != NULL) {
// If the policy is not a string, we issue a warning, but still clear the
// network configuration.
- if (!value->GetAsString(&new_network_config))
+ if (!current->GetAsString(&new_network_config))
LOG(WARNING) << "Invalid network configuration.";
}

Powered by Google App Engine
This is Rietveld 408576698