Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_signin_service.h" | 5 #include "chrome/browser/policy/user_policy_signin_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 // TokenService should not yet have loaded its tokens since this happens in | 250 // TokenService should not yet have loaded its tokens since this happens in |
| 251 // the background after PKS initialization - so this service should always be | 251 // the background after PKS initialization - so this service should always be |
| 252 // created before the oauth token is available. | 252 // created before the oauth token is available. |
| 253 DCHECK(!TokenServiceFactory::GetForProfile(profile_)->HasOAuthLoginToken()); | 253 DCHECK(!TokenServiceFactory::GetForProfile(profile_)->HasOAuthLoginToken()); |
| 254 | 254 |
| 255 // Register a listener to be called back once the current profile has finished | 255 // Register a listener to be called back once the current profile has finished |
| 256 // initializing, so we can startup the UserCloudPolicyManager. | 256 // initializing, so we can startup the UserCloudPolicyManager. |
| 257 registrar_.Add(this, | 257 registrar_.Add(this, |
| 258 chrome::NOTIFICATION_PROFILE_ADDED, | 258 chrome::NOTIFICATION_PROFILE_ADDED, |
| 259 content::Source<Profile>(profile)); | 259 content::Source<Profile>(profile)); |
| 260 | |
| 261 // Register a listener for the import finished notification in a first run | |
| 262 // scenario, which indicates the profile is ready to be further initialized. | |
| 263 registrar_.Add(this, | |
| 264 chrome::NOTIFICATION_IMPORT_FINISHED, | |
| 265 content::Source<Profile>(profile)); | |
| 260 } | 266 } |
| 261 | 267 |
| 262 UserPolicySigninService::~UserPolicySigninService() {} | 268 UserPolicySigninService::~UserPolicySigninService() {} |
| 263 | 269 |
| 264 void UserPolicySigninService::RegisterPolicyClient( | 270 void UserPolicySigninService::RegisterPolicyClient( |
| 265 const std::string& username, | 271 const std::string& username, |
| 266 const std::string& oauth2_refresh_token, | 272 const std::string& oauth2_refresh_token, |
| 267 const PolicyRegistrationCallback& callback) { | 273 const PolicyRegistrationCallback& callback) { |
| 268 DCHECK(!username.empty()); | 274 DCHECK(!username.empty()); |
| 269 DCHECK(!oauth2_refresh_token.empty()); | 275 DCHECK(!oauth2_refresh_token.empty()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 // Manager should be fully initialized by now. | 350 // Manager should be fully initialized by now. |
| 345 DCHECK(manager); | 351 DCHECK(manager); |
| 346 DCHECK(manager->core()->service()); | 352 DCHECK(manager->core()->service()); |
| 347 manager->core()->service()->AddObserver(this); | 353 manager->core()->service()->AddObserver(this); |
| 348 } | 354 } |
| 349 | 355 |
| 350 void UserPolicySigninService::Observe( | 356 void UserPolicySigninService::Observe( |
| 351 int type, | 357 int type, |
| 352 const content::NotificationSource& source, | 358 const content::NotificationSource& source, |
| 353 const content::NotificationDetails& details) { | 359 const content::NotificationDetails& details) { |
| 360 // If an import process is running, wait for NOTIFICATION_IMPORT_FINISHED | |
| 361 // before potentially creating the SigninManager. Its dependencies can access | |
| 362 // databases that the import process is also accessing, causing conflicts. | |
| 363 // Note that the profile manager is NULL in unit tests. | |
| 364 if (g_browser_process->profile_manager() && | |
| 365 g_browser_process->profile_manager()->will_import()) { | |
| 366 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_ADDED, type); | |
|
Bernhard Bauer
2013/03/26 12:29:32
Wait, doesn't this DCHECK fail when we get *any* o
Joao da Silva
2013/03/26 12:52:00
will_import() signals that the first run import wi
Bernhard Bauer
2013/03/26 14:18:22
Well, I ran into this with a local build that trie
Joao da Silva
2013/03/26 14:35:27
IIUC, that would only be a problem if you do that
| |
| 367 return; | |
| 368 } | |
| 369 | |
| 354 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, | 370 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, |
| 355 // skip initialization. | 371 // skip initialization. |
| 356 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) { | 372 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) { |
| 357 DVLOG(1) << "Skipping initialization for tests due to missing components."; | 373 DVLOG(1) << "Skipping initialization for tests due to missing components."; |
| 358 return; | 374 return; |
| 359 } | 375 } |
| 360 | 376 |
| 361 switch (type) { | 377 switch (type) { |
| 362 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | 378 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: |
| 363 ShutdownUserCloudPolicyManager(); | 379 ShutdownUserCloudPolicyManager(); |
| 364 break; | 380 break; |
| 381 case chrome::NOTIFICATION_IMPORT_FINISHED: | |
| 365 case chrome::NOTIFICATION_PROFILE_ADDED: { | 382 case chrome::NOTIFICATION_PROFILE_ADDED: { |
| 366 // A new profile has been loaded - if it's signed in, then initialize the | 383 // A new profile has been loaded - if it's signed in, then initialize the |
| 367 // UCPM, otherwise shut down the UCPM (which deletes any cached policy | 384 // UCPM, otherwise shut down the UCPM (which deletes any cached policy |
| 368 // data). This must be done here instead of at constructor time because | 385 // data). This must be done here instead of at constructor time because |
| 369 // the Profile is not fully initialized when this object is constructed | 386 // the Profile is not fully initialized when this object is constructed |
| 370 // (DoFinalInit() has not yet been called, so ProfileIOData and | 387 // (DoFinalInit() has not yet been called, so ProfileIOData and |
| 371 // SSLConfigServiceManager have not been created yet). | 388 // SSLConfigServiceManager have not been created yet). |
| 372 // TODO(atwilson): Switch to using a timer instead, to avoid contention | 389 // TODO(atwilson): Switch to using a timer instead, to avoid contention |
| 373 // with other services at startup (http://crbug.com/165468). | 390 // with other services at startup (http://crbug.com/165468). |
| 374 SigninManager* signin_manager = | 391 SigninManager* signin_manager = |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 // before UserCloudPolicyManager shuts down the CloudPolicyClient. | 552 // before UserCloudPolicyManager shuts down the CloudPolicyClient. |
| 536 registration_helper_.reset(); | 553 registration_helper_.reset(); |
| 537 StopObserving(); | 554 StopObserving(); |
| 538 } | 555 } |
| 539 | 556 |
| 540 UserCloudPolicyManager* UserPolicySigninService::GetManager() { | 557 UserCloudPolicyManager* UserPolicySigninService::GetManager() { |
| 541 return UserCloudPolicyManagerFactory::GetForProfile(profile_); | 558 return UserCloudPolicyManagerFactory::GetForProfile(profile_); |
| 542 } | 559 } |
| 543 | 560 |
| 544 } // namespace policy | 561 } // namespace policy |
| OLD | NEW |