summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-04 19:28:23 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-04 19:28:23 +0000
commitb17406480669e684467c9d1e76f26b063a3460e4 (patch)
tree335dbfdd039ed6dd9bc2b1a359e42ca78a20d985
parentc4256317556535beaecbb1ea068de068b5b080eb (diff)
downloadchromium_src-b17406480669e684467c9d1e76f26b063a3460e4.zip
chromium_src-b17406480669e684467c9d1e76f26b063a3460e4.tar.gz
chromium_src-b17406480669e684467c9d1e76f26b063a3460e4.tar.bz2
Wire up policy with NetworkLibrary.
On receiving new ONC configuration from policy, push it to NetworkLibrary to be loaded. BUG=chromium-os:19411 TEST=unit tests. Review URL: http://codereview.chromium.org/8460010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108694 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc6
-rw-r--r--chrome/browser/policy/browser_policy_connector.h3
-rw-r--r--chrome/browser/policy/configuration_policy_provider.cc4
-rw-r--r--chrome/browser/policy/configuration_policy_provider.h6
-rw-r--r--chrome/browser/policy/mock_configuration_policy_provider.h3
-rw-r--r--chrome/browser/policy/network_configuration_updater.cc63
-rw-r--r--chrome/browser/policy/network_configuration_updater.h59
-rw-r--r--chrome/browser/policy/network_configuration_updater_unittest.cc66
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--chrome/chrome_tests.gypi2
10 files changed, 214 insertions, 2 deletions
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 911fb4f..9c04330 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/policy/cloud_policy_subsystem.h"
#include "chrome/browser/policy/configuration_policy_pref_store.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
+#include "chrome/browser/policy/network_configuration_updater.h"
#include "chrome/browser/policy/policy_error_map.h"
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/user_policy_cache.h"
@@ -355,6 +356,11 @@ BrowserPolicyConnector::BrowserPolicyConnector()
#if defined(OS_CHROMEOS)
InitializeDevicePolicy();
+
+ network_configuration_updater_.reset(
+ new NetworkConfigurationUpdater(
+ managed_cloud_provider_.get(),
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary()));
#endif
policy_handlers_.reset(ConfigurationPolicyHandler::CreateHandlerList());
}
diff --git a/chrome/browser/policy/browser_policy_connector.h b/chrome/browser/policy/browser_policy_connector.h
index 9e95ec16..289ae06 100644
--- a/chrome/browser/policy/browser_policy_connector.h
+++ b/chrome/browser/policy/browser_policy_connector.h
@@ -26,6 +26,7 @@ namespace policy {
class CloudPolicyProvider;
class CloudPolicySubsystem;
class ConfigurationPolicyProvider;
+class NetworkConfigurationUpdater;
class PolicyErrorMap;
class PolicyMap;
class UserPolicyTokenCache;
@@ -164,6 +165,8 @@ class BrowserPolicyConnector : public content::NotificationObserver {
scoped_ptr<CloudPolicyDataStore> device_data_store_;
scoped_ptr<CloudPolicySubsystem> device_cloud_policy_subsystem_;
scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
+
+ scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
#endif
scoped_ptr<UserPolicyTokenCache> user_policy_token_cache_;
diff --git a/chrome/browser/policy/configuration_policy_provider.cc b/chrome/browser/policy/configuration_policy_provider.cc
index 47df5df..903916a 100644
--- a/chrome/browser/policy/configuration_policy_provider.cc
+++ b/chrome/browser/policy/configuration_policy_provider.cc
@@ -8,6 +8,10 @@
namespace policy {
+ConfigurationPolicyProvider::Observer::~Observer() {}
+
+void ConfigurationPolicyProvider::Observer::OnProviderGoingAway() {}
+
// Class ConfigurationPolicyProvider.
ConfigurationPolicyProvider::ConfigurationPolicyProvider(
diff --git a/chrome/browser/policy/configuration_policy_provider.h b/chrome/browser/policy/configuration_policy_provider.h
index 3eb0a7d..efe93cd 100644
--- a/chrome/browser/policy/configuration_policy_provider.h
+++ b/chrome/browser/policy/configuration_policy_provider.h
@@ -27,9 +27,9 @@ class ConfigurationPolicyProvider {
public:
class Observer {
public:
- virtual ~Observer() {}
+ virtual ~Observer();
virtual void OnUpdatePolicy() = 0;
- virtual void OnProviderGoingAway() = 0;
+ virtual void OnProviderGoingAway();
};
explicit ConfigurationPolicyProvider(const PolicyDefinitionList* policy_list);
@@ -103,6 +103,8 @@ class ConfigurationPolicyObserverRegistrar
virtual void OnUpdatePolicy();
virtual void OnProviderGoingAway();
+ ConfigurationPolicyProvider* provider() { return provider_; }
+
private:
ConfigurationPolicyProvider* provider_;
ConfigurationPolicyProvider::Observer* observer_;
diff --git a/chrome/browser/policy/mock_configuration_policy_provider.h b/chrome/browser/policy/mock_configuration_policy_provider.h
index cab4be6..6f5c9f9 100644
--- a/chrome/browser/policy/mock_configuration_policy_provider.h
+++ b/chrome/browser/policy/mock_configuration_policy_provider.h
@@ -27,6 +27,9 @@ class MockConfigurationPolicyProvider : public ConfigurationPolicyProvider {
virtual bool ProvideInternal(PolicyMap* policies) OVERRIDE;
virtual bool IsInitializationComplete() const OVERRIDE;
+ // Make public for tests.
+ using ConfigurationPolicyProvider::NotifyPolicyUpdated;
+
private:
PolicyMap policy_map_;
diff --git a/chrome/browser/policy/network_configuration_updater.cc b/chrome/browser/policy/network_configuration_updater.cc
new file mode 100644
index 0000000..6615173
--- /dev/null
+++ b/chrome/browser/policy/network_configuration_updater.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/policy/network_configuration_updater.h"
+
+#include "chrome/browser/chromeos/cros/network_library.h"
+#include "chrome/browser/policy/policy_map.h"
+#include "policy/policy_constants.h"
+
+namespace policy {
+
+NetworkConfigurationUpdater::NetworkConfigurationUpdater(
+ ConfigurationPolicyProvider* provider,
+ chromeos::NetworkLibrary* network_library)
+ : network_library_(network_library) {
+ DCHECK(network_library_);
+ provider_registrar_.Init(provider, this);
+ Update();
+}
+
+NetworkConfigurationUpdater::~NetworkConfigurationUpdater() {}
+
+void NetworkConfigurationUpdater::OnUpdatePolicy() {
+ Update();
+}
+
+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, kPolicyDeviceOpenNetworkConfiguration,
+ &device_network_config_);
+ ApplyNetworkConfiguration(policy, kPolicyOpenNetworkConfiguration,
+ &user_network_config_);
+}
+
+void NetworkConfigurationUpdater::ApplyNetworkConfiguration(
+ const PolicyMap& policy_map,
+ ConfigurationPolicyType policy_type,
+ std::string* cached_value) {
+ std::string new_network_config;
+ const base::Value* value = policy_map.Get(policy_type);
+ if (value != NULL) {
+ // If the policy is not a string, we issue a warning, but still clear the
+ // network configuration.
+ if (!value->GetAsString(&new_network_config))
+ LOG(WARNING) << "Invalid network configuration.";
+ }
+
+ if (*cached_value != new_network_config) {
+ *cached_value = new_network_config;
+ if (!network_library_->LoadOncNetworks(new_network_config))
+ LOG(WARNING) << "Network library failed to load ONC configuration.";
+ }
+}
+
+} // namespace policy
diff --git a/chrome/browser/policy/network_configuration_updater.h b/chrome/browser/policy/network_configuration_updater.h
new file mode 100644
index 0000000..2953468
--- /dev/null
+++ b/chrome/browser/policy/network_configuration_updater.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
+#define CHROME_BROWSER_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/policy/configuration_policy_provider.h"
+
+namespace chromeos {
+class NetworkLibrary;
+}
+
+namespace policy {
+
+class PolicyMap;
+
+// Keeps track of the network configuration policy settings and updates the
+// network definitions whenever the configuration changes.
+class NetworkConfigurationUpdater
+ : public ConfigurationPolicyProvider::Observer {
+ public:
+ NetworkConfigurationUpdater(ConfigurationPolicyProvider* provider,
+ chromeos::NetworkLibrary* network_library);
+ virtual ~NetworkConfigurationUpdater();
+
+ // ConfigurationPolicyProvider::Observer:
+ virtual void OnUpdatePolicy() OVERRIDE;
+
+ private:
+ // Grabs network configuration from policy and applies it.
+ void Update();
+
+ // Extracts ONC string from |policy_map| and pushes the configuration to
+ // |network_library_| if it's different from |*cached_value| (which is
+ // updated).
+ void ApplyNetworkConfiguration(const PolicyMap& policy_map,
+ ConfigurationPolicyType policy_type,
+ std::string* cached_value);
+
+ // Wraps the provider we read network configuration from.
+ ConfigurationPolicyObserverRegistrar provider_registrar_;
+
+ // Network library to write network configuration to.
+ chromeos::NetworkLibrary* network_library_;
+
+ // Current settings.
+ std::string device_network_config_;
+ std::string user_network_config_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdater);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
diff --git a/chrome/browser/policy/network_configuration_updater_unittest.cc b/chrome/browser/policy/network_configuration_updater_unittest.cc
new file mode 100644
index 0000000..001631d
--- /dev/null
+++ b/chrome/browser/policy/network_configuration_updater_unittest.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/policy/network_configuration_updater.h"
+
+#include "chrome/browser/chromeos/cros/mock_network_library.h"
+#include "chrome/browser/policy/mock_configuration_policy_provider.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::Mock;
+using testing::Return;
+
+namespace policy {
+
+static const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
+
+class NetworkConfigurationUpdaterTest
+ : public testing::TestWithParam<ConfigurationPolicyType> {
+ protected:
+ chromeos::MockNetworkLibrary network_library_;
+ MockConfigurationPolicyProvider provider_;
+};
+
+TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) {
+ provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC));
+
+ EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC))
+ .WillRepeatedly(Return(true));
+
+ NetworkConfigurationUpdater updater(&provider_, &network_library_);
+ Mock::VerifyAndClearExpectations(&network_library_);
+}
+
+TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
+ NetworkConfigurationUpdater updater(&provider_, &network_library_);
+
+ // We should update if policy changes.
+ EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC))
+ .WillOnce(Return(true));
+ provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC));
+ provider_.NotifyPolicyUpdated();
+ Mock::VerifyAndClearExpectations(&network_library_);
+
+ // No update if the set the same value again.
+ EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC))
+ .Times(0);
+ provider_.NotifyPolicyUpdated();
+ Mock::VerifyAndClearExpectations(&network_library_);
+
+ // Another update is expected if the policy goes away.
+ EXPECT_CALL(network_library_, LoadOncNetworks(""))
+ .WillOnce(Return(true));
+ provider_.RemovePolicy(GetParam());
+ provider_.NotifyPolicyUpdated();
+ Mock::VerifyAndClearExpectations(&network_library_);
+}
+
+INSTANTIATE_TEST_CASE_P(
+ NetworkConfigurationUpdaterTestInstance,
+ NetworkConfigurationUpdaterTest,
+ testing::Values(kPolicyDeviceOpenNetworkConfiguration,
+ kPolicyOpenNetworkConfiguration));
+
+} // namespace policy
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 238ef59..978c959 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1815,6 +1815,8 @@
'browser/policy/file_based_policy_loader.h',
'browser/policy/file_based_policy_provider.cc',
'browser/policy/file_based_policy_provider.h',
+ 'browser/policy/network_configuration_updater.cc',
+ 'browser/policy/network_configuration_updater.h',
'browser/policy/policy_error_map.cc',
'browser/policy/policy_error_map.h',
'browser/policy/policy_notifier.cc',
@@ -4059,6 +4061,8 @@
['exclude', 'browser/policy/device_policy_cache.h'],
['exclude', 'browser/policy/enterprise_install_attributes.cc'],
['exclude', 'browser/policy/enterprise_install_attributes.h'],
+ ['exclude', 'browser/policy/network_configuration_updater.cc'],
+ ['exclude', 'browser/policy/network_configuration_updater.h'],
['exclude', 'browser/policy/proto/chrome_device_policy.pb.cc'],
['exclude', 'browser/policy/proto/chrome_device_policy.pb.h'],
['exclude', 'browser/renderer_host/offline_resource_handler.cc'],
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 11f8c6f..46993a3 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1477,6 +1477,7 @@
'browser/policy/mock_configuration_policy_reader.h',
'browser/policy/mock_device_management_backend.cc',
'browser/policy/mock_device_management_backend.h',
+ 'browser/policy/network_configuration_updater_unittest.cc',
'browser/policy/policy_map_unittest.cc',
'browser/policy/policy_path_parser_unittest.cc',
'browser/policy/testing_cloud_policy_subsystem.cc',
@@ -2041,6 +2042,7 @@
['exclude', '^browser/oom_priority_manager_unittest.cc'],
['exclude', '^browser/policy/device_policy_cache_unittest.cc'],
['exclude', '^browser/policy/enterprise_install_attributes_unittest.cc' ],
+ ['exclude', '^browser/policy/network_configuration_updater_unittest.cc' ],
['exclude', '^browser/ui/webui/chromeos/imageburner/'],
['exclude', '^browser/ui/webui/chromeos/login'],
['exclude', '^browser/ui/webui/options/chromeos/'],