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

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

Issue 5331008: Persist 'this device is not managed' information (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build on Windows Created 10 years, 1 month 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/device_management_policy_cache.cc
diff --git a/chrome/browser/policy/device_management_policy_cache.cc b/chrome/browser/policy/device_management_policy_cache.cc
index 2cc2bc5220c3ed7d08859fab69a1e0af969b3f28..81af0f4eb616829ffe1219aaebd74fcae0b33f2f 100644
--- a/chrome/browser/policy/device_management_policy_cache.cc
+++ b/chrome/browser/policy/device_management_policy_cache.cc
@@ -25,7 +25,12 @@ class PersistPolicyTask : public Task {
public:
PersistPolicyTask(const FilePath& path,
const em::DevicePolicyResponse* policy,
- const base::Time& timestamp);
+ const base::Time& timestamp,
+ const bool is_device_unmanaged)
+ : path_(path),
+ policy_(policy),
+ timestamp_(timestamp),
+ is_device_unmanaged_(is_device_unmanaged) {}
private:
// Task override.
@@ -34,20 +39,16 @@ class PersistPolicyTask : public Task {
const FilePath path_;
scoped_ptr<const em::DevicePolicyResponse> policy_;
const base::Time timestamp_;
+ const bool is_device_unmanaged_;
};
-PersistPolicyTask::PersistPolicyTask(const FilePath& path,
- const em::DevicePolicyResponse* policy,
- const base::Time& timestamp)
- : path_(path),
- policy_(policy),
- timestamp_(timestamp) {
-}
-
void PersistPolicyTask::Run() {
std::string data;
em::CachedDevicePolicyResponse cached_policy;
- cached_policy.mutable_policy()->CopyFrom(*policy_);
+ if (policy_.get())
+ cached_policy.mutable_policy()->CopyFrom(*policy_);
+ if (is_device_unmanaged_)
+ cached_policy.set_unmanaged(true);
cached_policy.set_timestamp(timestamp_.ToInternalValue());
if (!cached_policy.SerializeToString(&data)) {
LOG(WARNING) << "Failed to serialize policy data";
@@ -65,7 +66,8 @@ DeviceManagementPolicyCache::DeviceManagementPolicyCache(
const FilePath& backing_file_path)
: backing_file_path_(backing_file_path),
policy_(new DictionaryValue),
- fresh_policy_(false) {
+ fresh_policy_(false),
+ is_device_unmanaged_(false) {
}
void DeviceManagementPolicyCache::LoadPolicyFromFile() {
@@ -95,6 +97,7 @@ 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()));
@@ -108,9 +111,10 @@ void DeviceManagementPolicyCache::LoadPolicyFromFile() {
bool DeviceManagementPolicyCache::SetPolicy(
const em::DevicePolicyResponse& policy) {
+ is_device_unmanaged_ = false;
DictionaryValue* value = DeviceManagementPolicyCache::DecodePolicy(policy);
const bool new_policy_differs = !(value->Equals(policy_.get()));
- base::Time now(base::Time::Now());
+ base::Time now(base::Time::NowFromSystemTime());
{
AutoLock lock(lock_);
policy_.reset(value);
@@ -123,8 +127,7 @@ bool DeviceManagementPolicyCache::SetPolicy(
BrowserThread::PostTask(
BrowserThread::FILE,
FROM_HERE,
- new PersistPolicyTask(backing_file_path_, policy_copy,
- base::Time::NowFromSystemTime()));
+ new PersistPolicyTask(backing_file_path_, policy_copy, now, false));
return new_policy_differs;
}
@@ -133,6 +136,28 @@ DictionaryValue* DeviceManagementPolicyCache::GetPolicy() {
return static_cast<DictionaryValue*>(policy_->DeepCopy());
}
+void DeviceManagementPolicyCache::SetDeviceUnmanaged(bool is_device_unmanaged) {
+ if (is_device_unmanaged_ == is_device_unmanaged)
+ return;
+
+ is_device_unmanaged_ = is_device_unmanaged;
+ base::Time now(base::Time::NowFromSystemTime());
+ DictionaryValue* empty = new DictionaryValue();
+ {
+ AutoLock lock(lock_);
+ policy_.reset(empty);
+ last_policy_refresh_time_ = now;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ new PersistPolicyTask(backing_file_path_,
+ (is_device_unmanaged ? NULL
+ : new em::DevicePolicyResponse()),
+ now,
+ is_device_unmanaged_));
+}
+
// static
Value* DeviceManagementPolicyCache::DecodeIntegerValue(
google::protobuf::int64 value) {
« no previous file with comments | « chrome/browser/policy/device_management_policy_cache.h ('k') | chrome/browser/policy/device_management_policy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698