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

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

Issue 12310009: Merge 182705 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1410/src/
Patch Set: Created 7 years, 10 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) 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/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 401
402 void UserPolicySigninService::InitializeUserCloudPolicyManager( 402 void UserPolicySigninService::InitializeUserCloudPolicyManager(
403 scoped_ptr<CloudPolicyClient> client) { 403 scoped_ptr<CloudPolicyClient> client) {
404 UserCloudPolicyManager* manager = GetManager(); 404 UserCloudPolicyManager* manager = GetManager();
405 DCHECK(!manager->core()->client()); 405 DCHECK(!manager->core()->client());
406 // If there is no cached DMToken then we can detect this below (or when 406 // If there is no cached DMToken then we can detect this below (or when
407 // the OnInitializationCompleted() callback is invoked). 407 // the OnInitializationCompleted() callback is invoked).
408 manager->Connect(g_browser_process->local_state(), client.Pass()); 408 manager->Connect(g_browser_process->local_state(), client.Pass());
409 DCHECK(manager->core()->service()); 409 DCHECK(manager->core()->service());
410 StartObserving(); 410 StartObserving();
411 ProhibitSignoutIfNeeded();
411 } 412 }
412 413
413 void UserPolicySigninService::InitializeForSignedInUser() { 414 void UserPolicySigninService::InitializeForSignedInUser() {
414 SigninManager* signin_manager = 415 SigninManager* signin_manager =
415 SigninManagerFactory::GetForProfile(profile_); 416 SigninManagerFactory::GetForProfile(profile_);
416 std::string username = signin_manager->GetAuthenticatedUsername(); 417 std::string username = signin_manager->GetAuthenticatedUsername();
417 418
418 if (!ShouldLoadPolicyForUser(username)) { 419 if (!ShouldLoadPolicyForUser(username)) {
419 VLOG(1) << "Policy load not enabled for user: " << username; 420 VLOG(1) << "Policy load not enabled for user: " << username;
420 return; 421 return;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 std::string token = TokenServiceFactory::GetForProfile(profile_)-> 468 std::string token = TokenServiceFactory::GetForProfile(profile_)->
468 GetOAuth2LoginRefreshToken(); 469 GetOAuth2LoginRefreshToken();
469 if (token.empty()) { 470 if (token.empty()) {
470 // No token yet - this class listens for NOTIFICATION_TOKEN_AVAILABLE 471 // No token yet - this class listens for NOTIFICATION_TOKEN_AVAILABLE
471 // and will re-attempt registration once the token is available. 472 // and will re-attempt registration once the token is available.
472 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; 473 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download";
473 return; 474 return;
474 } 475 }
475 RegisterCloudPolicyService(token); 476 RegisterCloudPolicyService(token);
476 } 477 }
478 // If client is registered now, prohibit signout.
479 ProhibitSignoutIfNeeded();
477 } 480 }
478 481
479 void UserPolicySigninService::RegisterCloudPolicyService( 482 void UserPolicySigninService::RegisterCloudPolicyService(
480 std::string login_token) { 483 std::string login_token) {
481 DCHECK(!GetManager()->IsClientRegistered()); 484 DCHECK(!GetManager()->IsClientRegistered());
482 DVLOG(1) << "Fetching new DM Token"; 485 DVLOG(1) << "Fetching new DM Token";
483 // Do nothing if already starting the registration process. 486 // Do nothing if already starting the registration process.
484 if (registration_helper_) 487 if (registration_helper_)
485 return; 488 return;
486 489
487 // Start the process of registering the CloudPolicyClient. Once it completes, 490 // Start the process of registering the CloudPolicyClient. Once it completes,
488 // policy fetch will automatically happen. 491 // policy fetch will automatically happen.
489 registration_helper_.reset( 492 registration_helper_.reset(
490 new CloudPolicyClientRegistrationHelper(profile_->GetRequestContext())); 493 new CloudPolicyClientRegistrationHelper(profile_->GetRequestContext()));
491 registration_helper_->StartRegistration( 494 registration_helper_->StartRegistration(
492 GetManager()->core()->client(), 495 GetManager()->core()->client(),
493 login_token, 496 login_token,
494 base::Bind(&UserPolicySigninService::OnRegistrationComplete, 497 base::Bind(&UserPolicySigninService::OnRegistrationComplete,
495 base::Unretained(this))); 498 base::Unretained(this)));
496 } 499 }
497 500
498 void UserPolicySigninService::OnRegistrationComplete() { 501 void UserPolicySigninService::OnRegistrationComplete() {
502 ProhibitSignoutIfNeeded();
499 registration_helper_.reset(); 503 registration_helper_.reset();
500 } 504 }
501 505
506 void UserPolicySigninService::ProhibitSignoutIfNeeded() {
507 if (GetManager()->IsClientRegistered()) {
508 DVLOG(1) << "User is registered for policy - prohibiting signout";
509 SigninManager* signin_manager =
510 SigninManagerFactory::GetForProfile(profile_);
511 signin_manager->ProhibitSignout();
512 }
513 }
514
502 void UserPolicySigninService::Shutdown() { 515 void UserPolicySigninService::Shutdown() {
503 // Stop any pending registration helper activity. We do this here instead of 516 // Stop any pending registration helper activity. We do this here instead of
504 // in the destructor because we want to shutdown the registration helper 517 // in the destructor because we want to shutdown the registration helper
505 // before UserCloudPolicyManager shuts down the CloudPolicyClient. 518 // before UserCloudPolicyManager shuts down the CloudPolicyClient.
506 registration_helper_.reset(); 519 registration_helper_.reset();
507 StopObserving(); 520 StopObserving();
508 } 521 }
509 522
510 UserCloudPolicyManager* UserPolicySigninService::GetManager() { 523 UserCloudPolicyManager* UserPolicySigninService::GetManager() {
511 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 524 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
512 } 525 }
513 526
514 } // namespace policy 527 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_policy_signin_service.h ('k') | chrome/browser/policy/user_policy_signin_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698