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

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

Issue 6312121: Add initial device policy infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup/compile fixes. Created 9 years, 11 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/cloud_policy_cache.cc
diff --git a/chrome/browser/policy/device_management_policy_cache.cc b/chrome/browser/policy/cloud_policy_cache.cc
similarity index 68%
rename from chrome/browser/policy/device_management_policy_cache.cc
rename to chrome/browser/policy/cloud_policy_cache.cc
index ef8e6e196d6c9bc666fcd85230582cd6ac8fb76c..4d75cd545c9e016be56a801067da37ae322f3231 100644
--- a/chrome/browser/policy/device_management_policy_cache.cc
+++ b/chrome/browser/policy/cloud_policy_cache.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/policy/device_management_policy_cache.h"
+#include "chrome/browser/policy/cloud_policy_cache.h"
#include <limits>
#include <string>
@@ -12,6 +12,8 @@
#include "base/task.h"
#include "base/values.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/policy/configuration_policy_pref_store.h"
+#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
@@ -20,6 +22,45 @@ using google::protobuf::RepeatedPtrField;
namespace policy {
+// A thin ConfigurationPolicyProvider implementation sitting on top of
+// CloudPolicyCache for hooking up with ConfigurationPolicyPrefStore.
+class CloudPolicyCache::CloudPolicyProvider
+ : public ConfigurationPolicyProvider {
+ public:
+ CloudPolicyProvider(const PolicyDefinitionList* policy_list,
+ CloudPolicyCache* cache,
+ CloudPolicyCache::PolicyLevel level)
+ : ConfigurationPolicyProvider(policy_list),
+ cache_(cache),
+ level_(level) {}
+ virtual ~CloudPolicyProvider() {}
+
+ virtual bool Provide(ConfigurationPolicyStoreInterface* store) {
+ // TODO(mnissler) handle level once we have support for that in the cache.
+ DecodePolicyValueTree(cache_->policy_.get(), store);
+ return true;
+ }
+
+ virtual bool IsInitializationComplete() const {
+ return cache_->initialization_complete_;
+ }
+
+ virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer) {
+ cache_->observer_list_.AddObserver(observer);
+ }
+ virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) {
+ cache_->observer_list_.RemoveObserver(observer);
+ }
+
+ private:
+ // The underlying policy cache.
+ CloudPolicyCache* cache_;
+ // Policy level this provider will handle.
+ CloudPolicyCache::PolicyLevel level_;
+
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
+};
+
// Saves policy information to a file.
class PersistPolicyTask : public Task {
public:
@@ -62,18 +103,31 @@ void PersistPolicyTask::Run() {
}
}
-DeviceManagementPolicyCache::DeviceManagementPolicyCache(
+CloudPolicyCache::CloudPolicyCache(
const FilePath& backing_file_path)
: backing_file_path_(backing_file_path),
policy_(new DictionaryValue),
- fresh_policy_(false),
+ initialization_complete_(false),
is_device_unmanaged_(false) {
+ managed_policy_provider_.reset(
+ new CloudPolicyProvider(
+ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
+ this,
+ POLICY_LEVEL_MANDATORY));
+ recommended_policy_provider_.reset(
+ new CloudPolicyProvider(
+ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
+ this,
+ POLICY_LEVEL_RECOMMENDED));
}
-DeviceManagementPolicyCache::~DeviceManagementPolicyCache() {}
+CloudPolicyCache::~CloudPolicyCache() {
+ FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
+ observer_list_, OnProviderGoingAway());
+}
-void DeviceManagementPolicyCache::LoadPolicyFromFile() {
- if (!file_util::PathExists(backing_file_path_) || fresh_policy_)
+void CloudPolicyCache::LoadFromFile() {
+ if (!file_util::PathExists(backing_file_path_) || initialization_complete_)
return;
// Read the protobuf from the file.
@@ -99,30 +153,30 @@ void DeviceManagementPolicyCache::LoadPolicyFromFile() {
<< ", file is from the future.";
return;
}
- is_device_unmanaged_ = cached_policy.unmanaged();
// Decode and swap in the new policy information.
scoped_ptr<DictionaryValue> value(DecodePolicy(cached_policy.policy()));
- {
- base::AutoLock lock(lock_);
- if (!fresh_policy_)
- policy_.reset(value.release());
- last_policy_refresh_time_ = timestamp;
- }
+ initialization_complete_ = true;
+ is_device_unmanaged_ = cached_policy.unmanaged();
+ policy_.reset(value.release());
+ last_policy_refresh_time_ = timestamp;
+
+ FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
+ observer_list_, OnUpdatePolicy());
}
-bool DeviceManagementPolicyCache::SetPolicy(
+bool CloudPolicyCache::SetPolicy(
const em::DevicePolicyResponse& policy) {
is_device_unmanaged_ = false;
- DictionaryValue* value = DeviceManagementPolicyCache::DecodePolicy(policy);
+ DictionaryValue* value = CloudPolicyCache::DecodePolicy(policy);
const bool new_policy_differs = !(value->Equals(policy_.get()));
base::Time now(base::Time::NowFromSystemTime());
- {
- base::AutoLock lock(lock_);
- policy_.reset(value);
- fresh_policy_ = true;
- last_policy_refresh_time_ = now;
- }
+ policy_.reset(value);
+ initialization_complete_ = true;
+ last_policy_refresh_time_ = now;
+
+ FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
+ observer_list_, OnUpdatePolicy());
em::DevicePolicyResponse* policy_copy = new em::DevicePolicyResponse;
policy_copy->CopyFrom(policy);
@@ -133,19 +187,23 @@ bool DeviceManagementPolicyCache::SetPolicy(
return new_policy_differs;
}
-DictionaryValue* DeviceManagementPolicyCache::GetPolicy() {
- base::AutoLock lock(lock_);
- return policy_->DeepCopy();
+ConfigurationPolicyProvider* CloudPolicyCache::GetManagedPolicyProvider() {
+ return managed_policy_provider_.get();
danno 2011/02/04 16:01:33 Make this class nonthreadsafe?
Jakob Kummerow 2011/02/14 13:50:34 Done.
+}
+
+ConfigurationPolicyProvider* CloudPolicyCache::GetRecommendedPolicyProvider() {
+ return recommended_policy_provider_.get();
}
-void DeviceManagementPolicyCache::SetDeviceUnmanaged() {
+void CloudPolicyCache::SetDeviceUnmanaged() {
is_device_unmanaged_ = true;
base::Time now(base::Time::NowFromSystemTime());
- {
- base::AutoLock lock(lock_);
- policy_.reset(new DictionaryValue);
- last_policy_refresh_time_ = now;
- }
+ policy_.reset(new DictionaryValue);
+ last_policy_refresh_time_ = now;
+
+ FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
+ observer_list_, OnUpdatePolicy());
+
BrowserThread::PostTask(
BrowserThread::FILE,
FROM_HERE,
@@ -153,7 +211,7 @@ void DeviceManagementPolicyCache::SetDeviceUnmanaged() {
}
// static
-Value* DeviceManagementPolicyCache::DecodeIntegerValue(
+Value* CloudPolicyCache::DecodeIntegerValue(
google::protobuf::int64 value) {
if (value < std::numeric_limits<int>::min() ||
value > std::numeric_limits<int>::max()) {
@@ -166,7 +224,7 @@ Value* DeviceManagementPolicyCache::DecodeIntegerValue(
}
// static
-Value* DeviceManagementPolicyCache::DecodeValue(const em::GenericValue& value) {
+Value* CloudPolicyCache::DecodeValue(const em::GenericValue& value) {
if (!value.has_value_type())
return NULL;
@@ -235,7 +293,7 @@ Value* DeviceManagementPolicyCache::DecodeValue(const em::GenericValue& value) {
}
// static
-DictionaryValue* DeviceManagementPolicyCache::DecodePolicy(
+DictionaryValue* CloudPolicyCache::DecodePolicy(
const em::DevicePolicyResponse& policy) {
DictionaryValue* result = new DictionaryValue;
RepeatedPtrField<em::DevicePolicySetting>::const_iterator setting;
@@ -258,7 +316,7 @@ DictionaryValue* DeviceManagementPolicyCache::DecodePolicy(
++named_value) {
if (named_value->has_value()) {
Value* decoded_value =
- DeviceManagementPolicyCache::DecodeValue(named_value->value());
+ CloudPolicyCache::DecodeValue(named_value->value());
if (decoded_value)
result->Set(named_value->name(), decoded_value);
}

Powered by Google App Engine
This is Rietveld 408576698