Chromium Code Reviews| 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..15e8e7298b930a01c5a2cd1de8006765f656a128 100644 |
| --- a/chrome/browser/policy/device_management_policy_cache.cc |
| +++ b/chrome/browser/policy/device_management_policy_cache.cc |
| @@ -25,7 +25,13 @@ 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 +40,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 +67,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 +98,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 +112,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 +128,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 +137,27 @@ 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 |
|
Mattias Nissler (ping if slow)
2010/11/26 10:37:45
Does that mean that when I call SetDeviceUnmanaged
Jakob Kummerow
2010/11/26 11:07:42
Not quite. When the device was unmanaged before, t
|
| + : new em::DevicePolicyResponse()), |
| + now, |
| + is_device_unmanaged_)); |
| +} |
| + |
| // static |
| Value* DeviceManagementPolicyCache::DecodeIntegerValue( |
| google::protobuf::int64 value) { |