| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/user_policy_cache.h" | 5 #include "chrome/browser/policy/user_policy_cache.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/policy/browser_policy_connector.h" |
| 15 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 14 #include "chrome/browser/policy/policy_map.h" | 16 #include "chrome/browser/policy/policy_map.h" |
| 15 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 17 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 16 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 18 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
| 17 #include "chrome/browser/policy/proto/old_generic_format.pb.h" | 19 #include "chrome/browser/policy/proto/old_generic_format.pb.h" |
| 18 #include "policy/configuration_policy_type.h" | 20 #include "policy/configuration_policy_type.h" |
| 19 | 21 |
| 20 namespace policy { | 22 namespace policy { |
| 21 | 23 |
| 22 // Decodes a CloudPolicySettings object into two maps with mandatory and | 24 // Decodes a CloudPolicySettings object into two maps with mandatory and |
| 23 // recommended settings, respectively. The implementation is generated code | 25 // recommended settings, respectively. The implementation is generated code |
| 24 // in policy/cloud_policy_generated.cc. | 26 // in policy/cloud_policy_generated.cc. |
| 25 void DecodePolicy(const em::CloudPolicySettings& policy, | 27 void DecodePolicy(const em::CloudPolicySettings& policy, |
| 26 PolicyMap* mandatory, PolicyMap* recommended); | 28 PolicyMap* mandatory, PolicyMap* recommended); |
| 27 | 29 |
| 28 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path) | 30 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path) |
| 29 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 31 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 32 first_load_complete_(false) { |
| 30 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), | 33 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), |
| 31 backing_file_path); | 34 backing_file_path); |
| 32 } | 35 } |
| 33 | 36 |
| 34 UserPolicyCache::~UserPolicyCache() { | 37 UserPolicyCache::~UserPolicyCache() { |
| 35 } | 38 } |
| 36 | 39 |
| 37 void UserPolicyCache::Load() { | 40 void UserPolicyCache::Load() { |
| 38 disk_cache_->Load(); | 41 disk_cache_->Load(); |
| 39 } | 42 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 60 void UserPolicyCache::SetUnmanaged() { | 63 void UserPolicyCache::SetUnmanaged() { |
| 61 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 62 SetUnmanagedInternal(base::Time::NowFromSystemTime()); | 65 SetUnmanagedInternal(base::Time::NowFromSystemTime()); |
| 63 | 66 |
| 64 em::CachedCloudPolicyResponse cached_policy; | 67 em::CachedCloudPolicyResponse cached_policy; |
| 65 cached_policy.set_unmanaged(true); | 68 cached_policy.set_unmanaged(true); |
| 66 cached_policy.set_timestamp(base::Time::NowFromSystemTime().ToTimeT()); | 69 cached_policy.set_timestamp(base::Time::NowFromSystemTime().ToTimeT()); |
| 67 disk_cache_->Store(cached_policy); | 70 disk_cache_->Store(cached_policy); |
| 68 } | 71 } |
| 69 | 72 |
| 73 bool UserPolicyCache::IsReady() { |
| 74 return initialization_complete() || first_load_complete_; |
| 75 } |
| 76 |
| 70 void UserPolicyCache::OnDiskCacheLoaded( | 77 void UserPolicyCache::OnDiskCacheLoaded( |
| 71 const em::CachedCloudPolicyResponse& cached_response) { | 78 const em::CachedCloudPolicyResponse& cached_response) { |
| 79 first_load_complete_ = true; |
| 72 if (initialization_complete()) | 80 if (initialization_complete()) |
| 73 return; | 81 return; |
| 74 | 82 |
| 75 if (cached_response.unmanaged()) { | 83 if (cached_response.unmanaged()) { |
| 76 SetUnmanagedInternal(base::Time::FromTimeT(cached_response.timestamp())); | 84 SetUnmanagedInternal(base::Time::FromTimeT(cached_response.timestamp())); |
| 77 } else if (cached_response.has_cloud_policy()) { | 85 } else if (cached_response.has_cloud_policy()) { |
| 78 base::Time timestamp; | 86 base::Time timestamp; |
| 79 if (SetPolicyInternal(cached_response.cloud_policy(), ×tamp, true)) | 87 if (SetPolicyInternal(cached_response.cloud_policy(), ×tamp, true)) |
| 80 set_last_policy_refresh_time(timestamp); | 88 set_last_policy_refresh_time(timestamp); |
| 81 } | 89 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 ++named_value) { | 150 ++named_value) { |
| 143 if (named_value->has_value()) { | 151 if (named_value->has_value()) { |
| 144 Value* decoded_value = DecodeValue(named_value->value()); | 152 Value* decoded_value = DecodeValue(named_value->value()); |
| 145 if (decoded_value) | 153 if (decoded_value) |
| 146 result.Set(named_value->name(), decoded_value); | 154 result.Set(named_value->name(), decoded_value); |
| 147 } | 155 } |
| 148 } | 156 } |
| 149 // Hack: Let one of the providers do the transformation from DictionaryValue | 157 // Hack: Let one of the providers do the transformation from DictionaryValue |
| 150 // to PolicyMap, since they have the required code anyway. | 158 // to PolicyMap, since they have the required code anyway. |
| 151 PolicyMapProxy map_proxy(mandatory); | 159 PolicyMapProxy map_proxy(mandatory); |
| 152 GetManagedPolicyProvider()->ApplyPolicyValueTree(&result, &map_proxy); | 160 g_browser_process->browser_policy_connector()->GetManagedCloudProvider()-> |
| 161 ApplyPolicyValueTree(&result, &map_proxy); |
| 153 } | 162 } |
| 154 | 163 |
| 155 Value* UserPolicyCache::DecodeIntegerValue( | 164 Value* UserPolicyCache::DecodeIntegerValue( |
| 156 google::protobuf::int64 value) const { | 165 google::protobuf::int64 value) const { |
| 157 if (value < std::numeric_limits<int>::min() || | 166 if (value < std::numeric_limits<int>::min() || |
| 158 value > std::numeric_limits<int>::max()) { | 167 value > std::numeric_limits<int>::max()) { |
| 159 LOG(WARNING) << "Integer value " << value | 168 LOG(WARNING) << "Integer value " << value |
| 160 << " out of numeric limits, ignoring."; | 169 << " out of numeric limits, ignoring."; |
| 161 return NULL; | 170 return NULL; |
| 162 } | 171 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 return list; | 235 return list; |
| 227 } | 236 } |
| 228 default: | 237 default: |
| 229 NOTREACHED() << "Unhandled value type"; | 238 NOTREACHED() << "Unhandled value type"; |
| 230 } | 239 } |
| 231 | 240 |
| 232 return NULL; | 241 return NULL; |
| 233 } | 242 } |
| 234 | 243 |
| 235 } // namespace policy | 244 } // namespace policy |
| OLD | NEW |