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

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

Issue 8499021: UserPolicyCache only becomes ready after policy has been fetched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Actually waits now, rebased Created 9 years, 1 month 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/browser_policy_connector.h" 5 #include "chrome/browser/policy/browser_policy_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 user_cloud_policy_subsystem_-> 224 user_cloud_policy_subsystem_->
225 ScheduleServiceInitialization(delay_milliseconds); 225 ScheduleServiceInitialization(delay_milliseconds);
226 } 226 }
227 #if defined(OS_CHROMEOS) 227 #if defined(OS_CHROMEOS)
228 if (device_cloud_policy_subsystem_.get()) { 228 if (device_cloud_policy_subsystem_.get()) {
229 device_cloud_policy_subsystem_-> 229 device_cloud_policy_subsystem_->
230 ScheduleServiceInitialization(delay_milliseconds); 230 ScheduleServiceInitialization(delay_milliseconds);
231 } 231 }
232 #endif 232 #endif
233 } 233 }
234 void BrowserPolicyConnector::InitializeUserPolicy( 234 bool BrowserPolicyConnector::InitializeUserPolicy(
235 const std::string& user_name) { 235 const std::string& user_name) {
236 // Throw away the old backend. 236 // Throw away the old backend.
237 user_cloud_policy_subsystem_.reset(); 237 user_cloud_policy_subsystem_.reset();
238 user_policy_token_cache_.reset(); 238 user_policy_token_cache_.reset();
239 user_data_store_.reset(); 239 user_data_store_.reset();
240 token_service_ = NULL; 240 token_service_ = NULL;
241 registrar_.RemoveAll(); 241 registrar_.RemoveAll();
242 242
243 CommandLine* command_line = CommandLine::ForCurrentProcess(); 243 CommandLine* command_line = CommandLine::ForCurrentProcess();
244 bool need_fetch = false;
244 245
245 FilePath policy_dir; 246 FilePath policy_dir;
246 PathService::Get(chrome::DIR_USER_DATA, &policy_dir); 247 PathService::Get(chrome::DIR_USER_DATA, &policy_dir);
247 #if defined(OS_CHROMEOS) 248 #if defined(OS_CHROMEOS)
248 policy_dir = policy_dir.Append( 249 policy_dir = policy_dir.Append(
249 command_line->GetSwitchValuePath(switches::kLoginProfile)); 250 command_line->GetSwitchValuePath(switches::kLoginProfile));
250 #endif 251 #endif
251 252
252 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 253 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
253 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); 254 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir);
255 CloudPolicyDataStore::UserAffiliation affiliation =
256 GetUserAffiliation(user_name);
257 need_fetch = affiliation == CloudPolicyDataStore::USER_AFFILIATION_MANAGED;
258
254 UserPolicyCache* user_policy_cache = 259 UserPolicyCache* user_policy_cache =
255 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); 260 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile),
261 need_fetch);
256 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); 262 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
257 user_policy_token_cache_.reset( 263 user_policy_token_cache_.reset(
258 new UserPolicyTokenCache(user_data_store_.get(), 264 new UserPolicyTokenCache(user_data_store_.get(),
259 policy_cache_dir.Append(kTokenCacheFile))); 265 policy_cache_dir.Append(kTokenCacheFile)));
260 266
261 // Prepending user caches meaning they will take precedence of device policy 267 // Prepending user caches meaning they will take precedence of device policy
262 // caches. 268 // caches.
263 managed_cloud_provider_->PrependCache(user_policy_cache); 269 managed_cloud_provider_->PrependCache(user_policy_cache);
264 recommended_cloud_provider_->PrependCache(user_policy_cache); 270 recommended_cloud_provider_->PrependCache(user_policy_cache);
265 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( 271 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem(
266 user_data_store_.get(), 272 user_data_store_.get(),
267 user_policy_cache)); 273 user_policy_cache));
268 274
269 // Initiate the DM-Token load. 275 // Initiate the DM-Token load.
270 user_policy_token_cache_->Load(); 276 user_policy_token_cache_->Load();
271 277
272 user_data_store_->set_user_name(user_name); 278 user_data_store_->set_user_name(user_name);
273 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); 279 user_data_store_->set_user_affiliation(affiliation);
274 280
281 int64 delay = need_fetch ? 0 : kServiceInitializationStartupDelay;
275 user_cloud_policy_subsystem_->CompleteInitialization( 282 user_cloud_policy_subsystem_->CompleteInitialization(
276 prefs::kUserPolicyRefreshRate, 283 prefs::kUserPolicyRefreshRate,
277 kServiceInitializationStartupDelay); 284 delay);
278 } 285 }
286 return need_fetch;
279 } 287 }
280 288
281 void BrowserPolicyConnector::SetUserPolicyTokenService( 289 void BrowserPolicyConnector::SetUserPolicyTokenService(
282 TokenService* token_service) { 290 TokenService* token_service) {
283 token_service_ = token_service; 291 token_service_ = token_service;
284 registrar_.Add(this, 292 registrar_.Add(this,
285 chrome::NOTIFICATION_TOKEN_AVAILABLE, 293 chrome::NOTIFICATION_TOKEN_AVAILABLE,
286 content::Source<TokenService>(token_service_)); 294 content::Source<TokenService>(token_service_));
287 295
288 if (token_service_->HasTokenForService( 296 if (token_service_->HasTokenForService(
289 GaiaConstants::kDeviceManagementService)) { 297 GaiaConstants::kDeviceManagementService)) {
290 user_data_store_->SetGaiaToken(token_service_->GetTokenForService( 298 user_data_store_->SetGaiaToken(token_service_->GetTokenForService(
291 GaiaConstants::kDeviceManagementService)); 299 GaiaConstants::kDeviceManagementService));
292 } 300 }
293 } 301 }
294 302
295 void BrowserPolicyConnector::RegisterForUserPolicy( 303 void BrowserPolicyConnector::RegisterForUserPolicy(
296 const std::string& oauth_token) { 304 const std::string& oauth_token) {
297 if (user_data_store_.get()) 305 if (oauth_token.empty()) {
298 user_data_store_->SetOAuthToken(oauth_token); 306 // An attempt to fetch the dm service oauth token has failed. Notify
307 // the user policy cache of this, so that a potential blocked login
308 // proceeds without waiting for user policy.
309 if (user_cloud_policy_subsystem_.get()) {
310 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()->
311 SetFetchingDone();
312 }
313 } else {
314 if (user_data_store_.get())
315 user_data_store_->SetOAuthToken(oauth_token);
316 }
299 } 317 }
300 318
301 const CloudPolicyDataStore* 319 const CloudPolicyDataStore*
302 BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() const { 320 BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() const {
303 #if defined(OS_CHROMEOS) 321 #if defined(OS_CHROMEOS)
304 return device_data_store_.get(); 322 return device_data_store_.get();
305 #else 323 #else
306 return NULL; 324 return NULL;
307 #endif 325 #endif
308 } 326 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); 488 config_dir_path.Append(FILE_PATH_LITERAL("recommended")));
471 } else { 489 } else {
472 return NULL; 490 return NULL;
473 } 491 }
474 #else 492 #else
475 return NULL; 493 return NULL;
476 #endif 494 #endif
477 } 495 }
478 496
479 } // namespace policy 497 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698