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

Side by Side Diff: chrome/browser/policy/user_policy_cache.cc

Issue 7147015: Move user cloud policy to BrowserProcess (was 6979011) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed Mattias' comments Created 9 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/task.h" 13 #include "base/task.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/policy/browser_policy_connector.h"
17 #include "chrome/browser/policy/cloud_policy_provider.h"
15 #include "chrome/browser/policy/configuration_policy_pref_store.h" 18 #include "chrome/browser/policy/configuration_policy_pref_store.h"
16 #include "chrome/browser/policy/policy_map.h" 19 #include "chrome/browser/policy/policy_map.h"
17 #include "chrome/browser/policy/proto/cloud_policy.pb.h" 20 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
18 #include "chrome/browser/policy/proto/device_management_local.pb.h" 21 #include "chrome/browser/policy/proto/device_management_local.pb.h"
19 #include "chrome/browser/policy/proto/old_generic_format.pb.h" 22 #include "chrome/browser/policy/proto/old_generic_format.pb.h"
20 #include "content/browser/browser_thread.h" 23 #include "content/browser/browser_thread.h"
21 #include "policy/configuration_policy_type.h" 24 #include "policy/configuration_policy_type.h"
22 25
23 namespace policy { 26 namespace policy {
24 27
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 137 }
135 138
136 int size = data.size(); 139 int size = data.size();
137 if (file_util::WriteFile(backing_file_path_, data.c_str(), size) != size) { 140 if (file_util::WriteFile(backing_file_path_, data.c_str(), size) != size) {
138 LOG(WARNING) << "Failed to write " << backing_file_path_.value(); 141 LOG(WARNING) << "Failed to write " << backing_file_path_.value();
139 return; 142 return;
140 } 143 }
141 } 144 }
142 145
143 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path) 146 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path)
144 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 147 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
148 first_load_complete_(false) {
145 disk_cache_ = new DiskCache(weak_ptr_factory_.GetWeakPtr(), 149 disk_cache_ = new DiskCache(weak_ptr_factory_.GetWeakPtr(),
146 backing_file_path); 150 backing_file_path);
147 } 151 }
148 152
149 UserPolicyCache::~UserPolicyCache() { 153 UserPolicyCache::~UserPolicyCache() {
150 } 154 }
151 155
152 void UserPolicyCache::Load() { 156 void UserPolicyCache::Load() {
153 disk_cache_->Load(); 157 disk_cache_->Load();
154 } 158 }
(...skipping 20 matching lines...) Expand all
175 void UserPolicyCache::SetUnmanaged() { 179 void UserPolicyCache::SetUnmanaged() {
176 DCHECK(CalledOnValidThread()); 180 DCHECK(CalledOnValidThread());
177 SetUnmanagedInternal(base::Time::NowFromSystemTime()); 181 SetUnmanagedInternal(base::Time::NowFromSystemTime());
178 182
179 em::CachedCloudPolicyResponse cached_policy; 183 em::CachedCloudPolicyResponse cached_policy;
180 cached_policy.set_unmanaged(true); 184 cached_policy.set_unmanaged(true);
181 cached_policy.set_timestamp(base::Time::NowFromSystemTime().ToTimeT()); 185 cached_policy.set_timestamp(base::Time::NowFromSystemTime().ToTimeT());
182 disk_cache_->Store(cached_policy); 186 disk_cache_->Store(cached_policy);
183 } 187 }
184 188
189 bool UserPolicyCache::IsReady() {
190 return initialization_complete() || first_load_complete_;
191 }
192
185 void UserPolicyCache::OnDiskCacheLoaded( 193 void UserPolicyCache::OnDiskCacheLoaded(
186 const em::CachedCloudPolicyResponse& cached_response) { 194 const em::CachedCloudPolicyResponse& cached_response) {
195 first_load_complete_ = true;
187 if (initialization_complete()) 196 if (initialization_complete())
188 return; 197 return;
189 198
190 if (cached_response.unmanaged()) { 199 if (cached_response.unmanaged()) {
191 SetUnmanagedInternal(base::Time::FromTimeT(cached_response.timestamp())); 200 SetUnmanagedInternal(base::Time::FromTimeT(cached_response.timestamp()));
192 } else if (cached_response.has_cloud_policy()) { 201 } else if (cached_response.has_cloud_policy()) {
193 base::Time timestamp; 202 base::Time timestamp;
194 if (SetPolicyInternal(cached_response.cloud_policy(), &timestamp, true)) 203 if (SetPolicyInternal(cached_response.cloud_policy(), &timestamp, true))
195 set_last_policy_refresh_time(timestamp); 204 set_last_policy_refresh_time(timestamp);
196 } 205 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 ++named_value) { 266 ++named_value) {
258 if (named_value->has_value()) { 267 if (named_value->has_value()) {
259 Value* decoded_value = DecodeValue(named_value->value()); 268 Value* decoded_value = DecodeValue(named_value->value());
260 if (decoded_value) 269 if (decoded_value)
261 result.Set(named_value->name(), decoded_value); 270 result.Set(named_value->name(), decoded_value);
262 } 271 }
263 } 272 }
264 // Hack: Let one of the providers do the transformation from DictionaryValue 273 // Hack: Let one of the providers do the transformation from DictionaryValue
265 // to PolicyMap, since they have the required code anyway. 274 // to PolicyMap, since they have the required code anyway.
266 PolicyMapProxy map_proxy(mandatory); 275 PolicyMapProxy map_proxy(mandatory);
267 GetManagedPolicyProvider()->ApplyPolicyValueTree(&result, &map_proxy); 276 g_browser_process->browser_policy_connector()->GetManagedCloudProvider()->
277 ApplyPolicyValueTree(&result, &map_proxy);
268 } 278 }
269 279
270 Value* UserPolicyCache::DecodeIntegerValue( 280 Value* UserPolicyCache::DecodeIntegerValue(
271 google::protobuf::int64 value) const { 281 google::protobuf::int64 value) const {
272 if (value < std::numeric_limits<int>::min() || 282 if (value < std::numeric_limits<int>::min() ||
273 value > std::numeric_limits<int>::max()) { 283 value > std::numeric_limits<int>::max()) {
274 LOG(WARNING) << "Integer value " << value 284 LOG(WARNING) << "Integer value " << value
275 << " out of numeric limits, ignoring."; 285 << " out of numeric limits, ignoring.";
276 return NULL; 286 return NULL;
277 } 287 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return list; 351 return list;
342 } 352 }
343 default: 353 default:
344 NOTREACHED() << "Unhandled value type"; 354 NOTREACHED() << "Unhandled value type";
345 } 355 }
346 356
347 return NULL; 357 return NULL;
348 } 358 }
349 359
350 } // namespace policy 360 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698