OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/policy/device_policy_cache.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/task.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 12 #include "chrome/browser/policy/policy_map.h" |
| 13 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 14 #include "chrome/browser/policy/proto/device_management_constants.h" |
| 15 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
| 16 #include "content/browser/browser_thread.h" |
| 17 #include "policy/configuration_policy_type.h" |
| 18 |
| 19 using google::protobuf::RepeatedPtrField; |
| 20 |
| 21 namespace policy { |
| 22 |
| 23 DevicePolicyCache::DevicePolicyCache() |
| 24 : signed_settings_helper_(chromeos::SignedSettingsHelper::Get()) { |
| 25 } |
| 26 |
| 27 DevicePolicyCache::DevicePolicyCache( |
| 28 chromeos::SignedSettingsHelper* signed_settings_helper) |
| 29 : signed_settings_helper_(signed_settings_helper) { |
| 30 } |
| 31 |
| 32 DevicePolicyCache::~DevicePolicyCache() { |
| 33 signed_settings_helper_->CancelCallback(this); |
| 34 } |
| 35 |
| 36 void DevicePolicyCache::Load() { |
| 37 // TODO(jkummerow): check if we're unmanaged; if so, set is_unmanaged_ = true |
| 38 // and return immediately. |
| 39 |
| 40 signed_settings_helper_->StartRetrievePolicyOp(this); |
| 41 } |
| 42 |
| 43 void DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { |
| 44 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); |
| 45 signed_settings_helper_->StartStorePolicyOp(policy, this); |
| 46 } |
| 47 |
| 48 void DevicePolicyCache::SetUnmanaged() { |
| 49 LOG(WARNING) << "Tried to set DevicePolicyCache to 'unmanaged'!"; |
| 50 // This is not supported for DevicePolicyCache. |
| 51 } |
| 52 |
| 53 void DevicePolicyCache::OnRetrievePolicyCompleted( |
| 54 chromeos::SignedSettings::ReturnCode code, |
| 55 const em::PolicyFetchResponse& policy) { |
| 56 DCHECK(CalledOnValidThread()); |
| 57 if (code != chromeos::SignedSettings::SUCCESS) { |
| 58 // TODO(jkummerow): We can't really do anything about this error, but |
| 59 // we may want to notify the user that something is wrong. |
| 60 return; |
| 61 } |
| 62 SetPolicyInternal(policy, NULL, false); |
| 63 } |
| 64 |
| 65 void DevicePolicyCache::OnStorePolicyCompleted( |
| 66 chromeos::SignedSettings::ReturnCode code) { |
| 67 DCHECK(CalledOnValidThread()); |
| 68 if (code != chromeos::SignedSettings::SUCCESS) { |
| 69 // TODO(jkummerow): We can't really do anything about this error, but |
| 70 // we may want to notify the user that something is wrong. |
| 71 return; |
| 72 } |
| 73 Load(); |
| 74 } |
| 75 |
| 76 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, |
| 77 PolicyMap* mandatory, |
| 78 PolicyMap* recommended) { |
| 79 em::ChromeDeviceSettingsProto policy; |
| 80 if (!policy.ParseFromString(policy_data.policy_value())) { |
| 81 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; |
| 82 return false; |
| 83 } |
| 84 DecodeDevicePolicy(policy, mandatory, recommended); |
| 85 return true; |
| 86 } |
| 87 |
| 88 // static |
| 89 void DevicePolicyCache::DecodeDevicePolicy( |
| 90 const em::ChromeDeviceSettingsProto& policy, |
| 91 PolicyMap* mandatory, |
| 92 PolicyMap* recommended) { |
| 93 // TODO(jkummerow): Implement this when there are consumers for |
| 94 // device-policy-set values in g_browser_process->local_state(). |
| 95 } |
| 96 |
| 97 } // namespace policy |
OLD | NEW |