summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-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
8 files changed, 208 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