summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 15:59:05 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 15:59:05 +0000
commit3e58a3a59bd6ba6429193af10630ad35c98af248 (patch)
tree19e561531e3f633a1550cf986d844f71a10b79fa
parent68793e7203736161f2298d089d873fb4c96f6776 (diff)
downloadchromium_src-3e58a3a59bd6ba6429193af10630ad35c98af248.zip
chromium_src-3e58a3a59bd6ba6429193af10630ad35c98af248.tar.gz
chromium_src-3e58a3a59bd6ba6429193af10630ad35c98af248.tar.bz2
Add ManagedModePolicyProvider and extension API to get and set policies.
BUG=128318 TEST=none Review URL: https://chromiumcodereview.appspot.com/10510006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142720 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_function_registry.cc2
-rw-r--r--chrome/browser/extensions/extension_managed_mode_api.cc35
-rw-r--r--chrome/browser/extensions/extension_managed_mode_api.h23
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc5
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider.cc104
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider.h63
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider_factory.cc33
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider_factory.h36
-rw-r--r--chrome/browser/policy/managed_mode_policy_provider_unittest.cc168
-rw-r--r--chrome/browser/prefs/testing_pref_store.cc3
-rw-r--r--chrome/browser/prefs/testing_pref_store.h3
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc11
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/chrome_constants.cc2
-rw-r--r--chrome/common/chrome_constants.h1
-rw-r--r--chrome/common/extensions/api/managed_mode_private.json52
17 files changed, 537 insertions, 9 deletions
diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc
index a0ec4ba..85311a8 100644
--- a/chrome/browser/extensions/extension_function_registry.cc
+++ b/chrome/browser/extensions/extension_function_registry.cc
@@ -295,6 +295,8 @@ void ExtensionFunctionRegistry::ResetFunctions() {
// Managed mode.
RegisterFunction<GetManagedModeFunction>();
RegisterFunction<EnterManagedModeFunction>();
+ RegisterFunction<GetPolicyFunction>();
+ RegisterFunction<SetPolicyFunction>();
// Management.
RegisterFunction<GetAllExtensionsFunction>();
diff --git a/chrome/browser/extensions/extension_managed_mode_api.cc b/chrome/browser/extensions/extension_managed_mode_api.cc
index 0e747d5..efa05f8 100644
--- a/chrome/browser/extensions/extension_managed_mode_api.cc
+++ b/chrome/browser/extensions/extension_managed_mode_api.cc
@@ -20,6 +20,11 @@
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_details.h"
+#if defined(ENABLE_CONFIGURATION_POLICY)
+#include "chrome/browser/policy/managed_mode_policy_provider.h"
+#include "chrome/browser/policy/managed_mode_policy_provider_factory.h"
+#endif
+
namespace {
// Event that is fired when we enter or leave managed mode.
@@ -91,3 +96,33 @@ void EnterManagedModeFunction::SendResult(bool success) {
result_.reset(result.release());
SendResponse(true);
}
+
+GetPolicyFunction::~GetPolicyFunction() { }
+
+bool GetPolicyFunction::RunImpl() {
+ std::string key;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key));
+#if defined(ENABLE_CONFIGURATION_POLICY)
+ policy::ManagedModePolicyProvider* policy_provider =
+ ManagedModePolicyProviderFactory::GetForProfile(profile_);
+ const base::Value* policy = policy_provider->GetPolicy(key);
+ if (policy)
+ result_.reset(policy->DeepCopy());
+#endif
+ return true;
+}
+
+SetPolicyFunction::~SetPolicyFunction() { }
+
+bool SetPolicyFunction::RunImpl() {
+ std::string key;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key));
+ base::Value* value = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &value));
+#if defined(ENABLE_CONFIGURATION_POLICY)
+ policy::ManagedModePolicyProvider* policy_provider =
+ ManagedModePolicyProviderFactory::GetForProfile(profile_);
+ policy_provider->SetPolicy(key, value);
+#endif
+ return true;
+}
diff --git a/chrome/browser/extensions/extension_managed_mode_api.h b/chrome/browser/extensions/extension_managed_mode_api.h
index 75695d5..1020189 100644
--- a/chrome/browser/extensions/extension_managed_mode_api.h
+++ b/chrome/browser/extensions/extension_managed_mode_api.h
@@ -60,4 +60,27 @@ class EnterManagedModeFunction : public AsyncExtensionFunction {
void SendResult(bool success);
};
+
+class GetPolicyFunction : public SyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION_NAME("managedModePrivate.getPolicy")
+
+ protected:
+ virtual ~GetPolicyFunction();
+
+ // ExtensionFunction:
+ virtual bool RunImpl() OVERRIDE;
+};
+
+class SetPolicyFunction : public SyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION_NAME("managedModePrivate.setPolicy")
+
+ protected:
+ virtual ~SetPolicyFunction();
+
+ // ExtensionFunction:
+ virtual bool RunImpl() OVERRIDE;
+};
+
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGED_MODE_API_H_
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 82d1bc5..080c5c9 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.cc
@@ -17,6 +17,8 @@
#include "chrome/browser/policy/cloud_policy_subsystem.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/device_management_service.h"
+#include "chrome/browser/policy/managed_mode_policy_provider.h"
+#include "chrome/browser/policy/managed_mode_policy_provider_factory.h"
#include "chrome/browser/policy/policy_service_impl.h"
#include "chrome/browser/policy/user_cloud_policy_manager.h"
#include "chrome/browser/policy/user_policy_cache.h"
@@ -171,6 +173,9 @@ PolicyService* BrowserPolicyConnector::CreatePolicyService(
if (profile) {
if (user_cloud_policy_manager_.get())
providers.push_back(user_cloud_policy_manager_.get());
+
+ providers.push_back(
+ ManagedModePolicyProviderFactory::GetForProfile(profile));
} else {
providers.push_back(&user_cloud_policy_provider_);
}
diff --git a/chrome/browser/policy/managed_mode_policy_provider.cc b/chrome/browser/policy/managed_mode_policy_provider.cc
new file mode 100644
index 0000000..e052167
--- /dev/null
+++ b/chrome/browser/policy/managed_mode_policy_provider.cc
@@ -0,0 +1,104 @@
+// Copyright (c) 2012 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/managed_mode_policy_provider.h"
+
+#include "chrome/browser/policy/policy_bundle.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/json_pref_store.h"
+#include "chrome/common/chrome_constants.h"
+#include "content/public/browser/browser_thread.h"
+#include "policy/policy_constants.h"
+
+using content::BrowserThread;
+
+namespace policy {
+
+// static
+const char ManagedModePolicyProvider::kPolicies[] = "policies";
+
+// static
+ManagedModePolicyProvider* ManagedModePolicyProvider::Create(Profile* profile) {
+ JsonPrefStore* pref_store =
+ new JsonPrefStore(profile->GetPath().Append(
+ chrome::kManagedModePolicyFilename),
+ BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::FILE));
+ return new ManagedModePolicyProvider(pref_store);
+}
+
+ManagedModePolicyProvider::ManagedModePolicyProvider(
+ PersistentPrefStore* pref_store)
+ : store_(pref_store) {
+ store_->AddObserver(this);
+ store_->ReadPrefsAsync(NULL);
+}
+
+ManagedModePolicyProvider::~ManagedModePolicyProvider() {
+ store_->RemoveObserver(this);
+}
+
+const base::Value* ManagedModePolicyProvider::GetPolicy(
+ const std::string& key) const {
+ base::DictionaryValue* dict = GetCachedPolicy();
+ base::Value* value = NULL;
+ dict->GetWithoutPathExpansion(key, &value);
+ return value;
+}
+
+void ManagedModePolicyProvider::SetPolicy(const std::string& key,
+ const base::Value* value) {
+ base::DictionaryValue* dict = GetCachedPolicy();
+ dict->SetWithoutPathExpansion(key, value->DeepCopy());
+ store_->ReportValueChanged(kPolicies);
+ UpdatePolicyFromCache();
+}
+
+void ManagedModePolicyProvider::RefreshPolicies() {
+ UpdatePolicyFromCache();
+}
+
+bool ManagedModePolicyProvider::IsInitializationComplete() const {
+ return store_->IsInitializationComplete();
+}
+
+void ManagedModePolicyProvider::OnPrefValueChanged(const std::string& key) {}
+
+void ManagedModePolicyProvider::OnInitializationCompleted(bool success) {
+ DCHECK(success);
+ UpdatePolicyFromCache();
+}
+
+base::DictionaryValue* ManagedModePolicyProvider::GetCachedPolicy() const {
+ base::Value* value = NULL;
+ base::DictionaryValue* dict = NULL;
+ PrefStore::ReadResult result = store_->GetMutableValue(kPolicies, &value);
+ switch (result) {
+ case PrefStore::READ_NO_VALUE: {
+ dict = new base::DictionaryValue;
+ store_->SetValue(kPolicies, dict);
+ break;
+ }
+ case PrefStore::READ_OK: {
+ bool success = value->GetAsDictionary(&dict);
+ DCHECK(success);
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+
+ return dict;
+}
+
+void ManagedModePolicyProvider::UpdatePolicyFromCache() {
+ scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle);
+ PolicyMap* policy_map =
+ &policy_bundle->Get(POLICY_DOMAIN_CHROME, std::string());
+ policy_map->LoadFrom(GetCachedPolicy(),
+ POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
+ UpdatePolicy(policy_bundle.Pass());
+}
+
+} // namespace policy
diff --git a/chrome/browser/policy/managed_mode_policy_provider.h b/chrome/browser/policy/managed_mode_policy_provider.h
new file mode 100644
index 0000000..c1d3d48
--- /dev/null
+++ b/chrome/browser/policy/managed_mode_policy_provider.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 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_MANAGED_MODE_POLICY_PROVIDER_H_
+#define CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/policy/configuration_policy_provider.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "chrome/common/persistent_pref_store.h"
+
+class Profile;
+
+namespace policy {
+
+// This class sets policies that are defined by a local user via "Managed Mode".
+// It offers methods to set and read policies, and persists them on disk in
+// JSON format.
+class ManagedModePolicyProvider
+ : public ProfileKeyedService,
+ public ConfigurationPolicyProvider,
+ public PrefStore::Observer {
+ public:
+ // The dictionary key under which we store the policy dictionary. Public for
+ // testing.
+ static const char kPolicies[];
+
+ // Creates a new ManagedModePolicyProvider that caches its policies in a JSON
+ // file inside the profile folder.
+ static ManagedModePolicyProvider* Create(Profile* profile);
+
+ // Use this constructor to inject a different PrefStore (e.g. for testing).
+ explicit ManagedModePolicyProvider(PersistentPrefStore* store);
+ virtual ~ManagedModePolicyProvider();
+
+ // Returns the stored value for a policy with the given |key|, or NULL if no
+ // such policy is defined.
+ const base::Value* GetPolicy(const std::string& key) const;
+ // Sets the policy with the given |key| to a copy of the given |value|.
+ void SetPolicy(const std::string& key, const base::Value* value);
+
+ // ConfigurationPolicyProvider implementation:
+ virtual void RefreshPolicies() OVERRIDE;
+ virtual bool IsInitializationComplete() const OVERRIDE;
+
+ // PrefStore::Observer implementation:
+ virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
+ virtual void OnInitializationCompleted(bool success) OVERRIDE;
+
+ private:
+ base::DictionaryValue* GetCachedPolicy() const;
+ void UpdatePolicyFromCache();
+
+ // Used for persisting policies. Unlike other PrefStores, this one is not
+ // hooked up to the PrefService.
+ scoped_refptr<PersistentPrefStore> store_;
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_H_
diff --git a/chrome/browser/policy/managed_mode_policy_provider_factory.cc b/chrome/browser/policy/managed_mode_policy_provider_factory.cc
new file mode 100644
index 0000000..32ea83a
--- /dev/null
+++ b/chrome/browser/policy/managed_mode_policy_provider_factory.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2012 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/managed_mode_policy_provider_factory.h"
+
+#include "chrome/browser/policy/managed_mode_policy_provider.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+
+using policy::ManagedModePolicyProvider;
+
+// static
+ManagedModePolicyProviderFactory*
+ ManagedModePolicyProviderFactory::GetInstance() {
+ return Singleton<ManagedModePolicyProviderFactory>::get();
+}
+
+// static
+ManagedModePolicyProvider*
+ ManagedModePolicyProviderFactory::GetForProfile(Profile* profile) {
+ return static_cast<ManagedModePolicyProvider*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+ManagedModePolicyProviderFactory::ManagedModePolicyProviderFactory()
+ : ProfileKeyedServiceFactory("ManagedModePolicyProvider",
+ ProfileDependencyManager::GetInstance()) {}
+ManagedModePolicyProviderFactory::~ManagedModePolicyProviderFactory() {}
+
+ProfileKeyedService* ManagedModePolicyProviderFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return ManagedModePolicyProvider::Create(profile);
+}
diff --git a/chrome/browser/policy/managed_mode_policy_provider_factory.h b/chrome/browser/policy/managed_mode_policy_provider_factory.h
new file mode 100644
index 0000000..3c9f2e1
--- /dev/null
+++ b/chrome/browser/policy/managed_mode_policy_provider_factory.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 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_MANAGED_MODE_POLICY_PROVIDER_FACTORY_H_
+#define CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_FACTORY_H_
+#pragma once
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+class Profile;
+
+namespace policy {
+class ManagedModePolicyProvider;
+}
+
+class ManagedModePolicyProviderFactory : public ProfileKeyedServiceFactory {
+ public:
+ static ManagedModePolicyProviderFactory* GetInstance();
+
+ static policy::ManagedModePolicyProvider* GetForProfile(Profile* profile);
+
+ private:
+ friend struct DefaultSingletonTraits<ManagedModePolicyProviderFactory>;
+
+ ManagedModePolicyProviderFactory();
+ virtual ~ManagedModePolicyProviderFactory();
+
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(ManagedModePolicyProviderFactory);
+};
+
+#endif // CHROME_BROWSER_POLICY_MANAGED_MODE_POLICY_PROVIDER_FACTORY_H_
diff --git a/chrome/browser/policy/managed_mode_policy_provider_unittest.cc b/chrome/browser/policy/managed_mode_policy_provider_unittest.cc
new file mode 100644
index 0000000..59353e5
--- /dev/null
+++ b/chrome/browser/policy/managed_mode_policy_provider_unittest.cc
@@ -0,0 +1,168 @@
+// Copyright (c) 2012 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/configuration_policy_provider_test.h"
+#include "chrome/browser/policy/managed_mode_policy_provider.h"
+#include "chrome/browser/policy/policy_bundle.h"
+#include "chrome/browser/policy/policy_map.h"
+#include "chrome/browser/prefs/testing_pref_store.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace policy {
+
+namespace {
+
+class TestHarness : public PolicyProviderTestHarness {
+ public:
+ TestHarness();
+ virtual ~TestHarness();
+
+ static PolicyProviderTestHarness* Create();
+
+ virtual void SetUp() OVERRIDE;
+
+ // PolicyProviderTestHarness implementation:
+ virtual ConfigurationPolicyProvider* CreateProvider(
+ const PolicyDefinitionList* policy_definition_list) OVERRIDE;
+
+ virtual void InstallEmptyPolicy() OVERRIDE;
+ virtual void InstallStringPolicy(const std::string& policy_name,
+ const std::string& policy_value) OVERRIDE;
+ virtual void InstallIntegerPolicy(const std::string& policy_name,
+ int policy_value) OVERRIDE;
+ virtual void InstallBooleanPolicy(const std::string& policy_name,
+ bool policy_value) OVERRIDE;
+ virtual void InstallStringListPolicy(
+ const std::string& policy_name,
+ const base::ListValue* policy_value) OVERRIDE;
+ virtual void InstallDictionaryPolicy(
+ const std::string& policy_name,
+ const base::DictionaryValue* policy_value) OVERRIDE;
+
+ private:
+ void InstallPolicy(const std::string& policy_name, base::Value* policy_value);
+
+ scoped_refptr<TestingPrefStore> pref_store_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestHarness);
+};
+
+TestHarness::TestHarness()
+ : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER),
+ pref_store_(new TestingPrefStore) {}
+
+TestHarness::~TestHarness() {}
+
+// static
+PolicyProviderTestHarness* TestHarness::Create() {
+ return new TestHarness();
+}
+
+void TestHarness::SetUp() {
+}
+
+ConfigurationPolicyProvider* TestHarness::CreateProvider(
+ const PolicyDefinitionList* policy_definition_list) {
+ return new ManagedModePolicyProvider(pref_store_);
+}
+
+void TestHarness::InstallEmptyPolicy() {}
+
+void TestHarness::InstallStringPolicy(const std::string& policy_name,
+ const std::string& policy_value) {
+ InstallPolicy(policy_name, base::Value::CreateStringValue(policy_value));
+}
+
+void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
+ int policy_value) {
+ InstallPolicy(policy_name, base::Value::CreateIntegerValue(policy_value));
+}
+
+void TestHarness::InstallBooleanPolicy(const std::string& policy_name,
+ bool policy_value) {
+ InstallPolicy(policy_name, base::Value::CreateBooleanValue(policy_value));
+}
+
+void TestHarness::InstallStringListPolicy(const std::string& policy_name,
+ const base::ListValue* policy_value) {
+ InstallPolicy(policy_name, policy_value->DeepCopy());
+}
+
+void TestHarness::InstallDictionaryPolicy(
+ const std::string& policy_name,
+ const base::DictionaryValue* policy_value) {
+ InstallPolicy(policy_name, policy_value->DeepCopy());
+}
+
+void TestHarness::InstallPolicy(const std::string& policy_name,
+ base::Value* policy_value) {
+ base::DictionaryValue* cached_policy = NULL;
+ base::Value* value = NULL;
+ PrefStore::ReadResult result =
+ pref_store_->GetMutableValue(ManagedModePolicyProvider::kPolicies,
+ &value);
+ switch (result) {
+ case PrefStore::READ_NO_VALUE:
+ cached_policy = new base::DictionaryValue;
+ pref_store_->SetValue(ManagedModePolicyProvider::kPolicies,
+ cached_policy);
+ break;
+ case PrefStore::READ_OK:
+ ASSERT_TRUE(value->GetAsDictionary(&cached_policy));
+ break;
+ default:
+ FAIL() << "Invalid result reading policy: " << result;
+ return;
+ }
+ cached_policy->SetWithoutPathExpansion(policy_name, policy_value);
+}
+
+} // namespace
+
+// Instantiate abstract test case for basic policy reading tests.
+INSTANTIATE_TEST_CASE_P(
+ ManagedModePolicyProviderTest,
+ ConfigurationPolicyProviderTest,
+ testing::Values(TestHarness::Create));
+
+class ManagedModePolicyProviderAPITest : public PolicyTestBase {
+ protected:
+ ManagedModePolicyProviderAPITest()
+ : pref_store_(new TestingPrefStore),
+ provider_(pref_store_) {}
+ virtual ~ManagedModePolicyProviderAPITest() {}
+
+ scoped_refptr<TestingPrefStore> pref_store_;
+ ManagedModePolicyProvider provider_;
+};
+
+const char kPolicyKey[] = "TestingPolicy";
+
+TEST_F(ManagedModePolicyProviderAPITest, Empty) {
+ EXPECT_FALSE(provider_.GetPolicy(kPolicyKey));
+
+ const PolicyBundle kEmptyBundle;
+ EXPECT_TRUE(provider_.policies().Equals(kEmptyBundle));
+}
+
+TEST_F(ManagedModePolicyProviderAPITest, SetPolicy) {
+ base::StringValue policy_value("PolicyValue");
+ provider_.SetPolicy(kPolicyKey, &policy_value);
+
+ EXPECT_TRUE(base::Value::Equals(&policy_value,
+ provider_.GetPolicy(kPolicyKey)));
+
+ PolicyBundle expected_bundle;
+ PolicyMap* policy_map =
+ &expected_bundle.Get(POLICY_DOMAIN_CHROME, std::string());
+ policy_map->Set(kPolicyKey, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ policy_value.DeepCopy());
+ EXPECT_TRUE(provider_.policies().Equals(expected_bundle));
+
+ // A newly-created provider should have the same policies.
+ ManagedModePolicyProvider new_provider(pref_store_);
+ EXPECT_TRUE(new_provider.policies().Equals(expected_bundle));
+}
+
+} // namespace policy
diff --git a/chrome/browser/prefs/testing_pref_store.cc b/chrome/browser/prefs/testing_pref_store.cc
index 3b95a44..59952e6 100644
--- a/chrome/browser/prefs/testing_pref_store.cc
+++ b/chrome/browser/prefs/testing_pref_store.cc
@@ -9,7 +9,6 @@
TestingPrefStore::TestingPrefStore()
: read_only_(true),
- prefs_written_(false),
init_complete_(false) {
}
@@ -65,14 +64,12 @@ PersistentPrefStore::PrefReadError TestingPrefStore::GetReadError() const {
}
PersistentPrefStore::PrefReadError TestingPrefStore::ReadPrefs() {
- prefs_.Clear();
NotifyInitializationCompleted();
return PersistentPrefStore::PREF_READ_ERROR_NONE;
}
void TestingPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate_raw) {
scoped_ptr<ReadErrorDelegate> error_delegate(error_delegate_raw);
- prefs_.Clear();
NotifyInitializationCompleted();
}
diff --git a/chrome/browser/prefs/testing_pref_store.h b/chrome/browser/prefs/testing_pref_store.h
index 0254a62..752392e 100644
--- a/chrome/browser/prefs/testing_pref_store.h
+++ b/chrome/browser/prefs/testing_pref_store.h
@@ -74,9 +74,6 @@ class TestingPrefStore : public PersistentPrefStore {
// Flag that indicates if the PrefStore is read-only
bool read_only_;
- // Flag that indicates if the method WritePrefs was called.
- bool prefs_written_;
-
// Whether initialization has been completed.
bool init_complete_;
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index f25df77..8bba6df 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -48,10 +48,16 @@
#include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
#include "chrome/browser/user_style_sheet_watcher_factory.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
+
+#if defined(ENABLE_CONFIGURATION_POLICY)
+#include "chrome/browser/policy/managed_mode_policy_provider_factory.h"
+#endif
+
#if defined(USE_AURA)
#include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h"
#endif
-#include "chrome/browser/webdata/web_data_service_factory.h"
+
#ifndef NDEBUG
#include "base/command_line.h"
#include "base/file_util.h"
@@ -206,6 +212,9 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
GlobalErrorServiceFactory::GetInstance();
GoogleURLTrackerFactory::GetInstance();
HistoryServiceFactory::GetInstance();
+#if defined(ENABLE_CONFIGURATION_POLICY)
+ ManagedModePolicyProviderFactory::GetInstance();
+#endif
NTPResourceCacheFactory::GetInstance();
PasswordStoreFactory::GetInstance();
PersonalDataManagerFactory::GetInstance();
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 4a5d7fe..1590f8c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1646,6 +1646,10 @@
'browser/policy/enterprise_install_attributes.h',
'browser/policy/enterprise_metrics.cc',
'browser/policy/enterprise_metrics.h',
+ 'browser/policy/managed_mode_policy_provider.cc',
+ 'browser/policy/managed_mode_policy_provider.h',
+ 'browser/policy/managed_mode_policy_provider_factory.cc',
+ 'browser/policy/managed_mode_policy_provider_factory.h',
'browser/policy/network_configuration_updater.cc',
'browser/policy/network_configuration_updater.h',
'browser/policy/policy_bundle.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 1034949..2b0531e 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1386,6 +1386,7 @@
'browser/policy/logging_work_scheduler.cc',
'browser/policy/logging_work_scheduler.h',
'browser/policy/logging_work_scheduler_unittest.cc',
+ 'browser/policy/managed_mode_policy_provider_unittest.cc',
'browser/policy/mock_cloud_policy_client.cc',
'browser/policy/mock_cloud_policy_client.h',
'browser/policy/mock_cloud_policy_store.cc',
diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc
index 6cfd0b3..3a2fc34 100644
--- a/chrome/common/chrome_constants.cc
+++ b/chrome/common/chrome_constants.cc
@@ -161,6 +161,8 @@ const FilePath::CharType kJumpListIconDirname[] = FPL("JumpListIcons");
const FilePath::CharType kWebAppDirname[] = FPL("Web Applications");
const FilePath::CharType kServiceStateFileName[] = FPL("Service State");
const FilePath::CharType kReadmeFilename[] = FPL("README");
+const FilePath::CharType kManagedModePolicyFilename[] =
+ FPL("Managed Mode Settings");
#if defined(OS_CHROMEOS)
const FilePath::CharType kGDataCacheDirname[] = FPL("GCache");
diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h
index 133f235..d099ed7 100644
--- a/chrome/common/chrome_constants.h
+++ b/chrome/common/chrome_constants.h
@@ -87,6 +87,7 @@ extern const FilePath::CharType kJumpListIconDirname[];
extern const FilePath::CharType kWebAppDirname[];
extern const FilePath::CharType kServiceStateFileName[];
extern const FilePath::CharType kReadmeFilename[];
+extern const FilePath::CharType kManagedModePolicyFilename[];
#if defined(OS_CHROMEOS)
extern const FilePath::CharType kGDataCacheDirname[];
diff --git a/chrome/common/extensions/api/managed_mode_private.json b/chrome/common/extensions/api/managed_mode_private.json
index e02dcfb..8c5a63b 100644
--- a/chrome/common/extensions/api/managed_mode_private.json
+++ b/chrome/common/extensions/api/managed_mode_private.json
@@ -18,7 +18,7 @@
"optional": true,
"parameters": [
{
- "name": "result",
+ "name": "result",
"type": "object",
"description": "The result of the attempt to enter managed mode.",
"properties": {
@@ -55,6 +55,54 @@
]
}
]
+ },
+ {
+ "name": "setPolicy",
+ "type": "function",
+ "description": "Sets a policy.",
+ "parameters": [
+ {
+ "name": "key",
+ "type": "string",
+ "description": "Policy key."
+ },
+ {
+ "name": "value",
+ "type": "any",
+ "description": "Policy value."
+ },
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "parameters": []
+ }
+ ]
+ },
+ {
+ "name": "getPolicy",
+ "type": "function",
+ "description": "Gets a policy value.",
+ "parameters": [
+ {
+ "name": "key",
+ "type": "string",
+ "description": "Policy key."
+ },
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "parameters": [
+ {
+ "name": "value",
+ "type": "any",
+ "description": "Policy value or null if no policy is set.",
+ "optional": true
+ }
+ ]
+ }
+ ]
}
],
"events": [
@@ -76,4 +124,4 @@
}
]
}
-]
+] \ No newline at end of file