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