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

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

Issue 15780020: Setup Sync to use OAuth token for managed users. (Closed) Base URL: http://git.chromium.org/chromium/src.git@issue226464a
Patch Set: sync Created 7 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
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/cloud/user_policy_signin_service.h" 5 #include "chrome/browser/policy/cloud/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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/managed_mode/managed_user_service.h"
Joao da Silva 2013/06/12 15:30:29 #ifdef managed mode
Bernhard Bauer 2013/06/12 19:01:39 Done.
13 #include "chrome/browser/policy/browser_policy_connector.h" 14 #include "chrome/browser/policy/browser_policy_connector.h"
14 #include "chrome/browser/policy/cloud/cloud_policy_client.h" 15 #include "chrome/browser/policy/cloud/cloud_policy_client.h"
15 #include "chrome/browser/policy/cloud/cloud_policy_service.h" 16 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
16 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" 17 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
17 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" 18 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
18 #include "chrome/browser/policy/cloud/user_info_fetcher.h" 19 #include "chrome/browser/policy/cloud/user_info_fetcher.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/signin/signin_manager.h" 22 #include "chrome/browser/signin/signin_manager.h"
22 #include "chrome/browser/signin/signin_manager_factory.h" 23 #include "chrome/browser/signin/signin_manager_factory.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 DCHECK_EQ(client, client_); 222 DCHECK_EQ(client, client_);
222 RequestCompleted(); 223 RequestCompleted();
223 } 224 }
224 225
225 UserPolicySigninService::UserPolicySigninService( 226 UserPolicySigninService::UserPolicySigninService(
226 Profile* profile) 227 Profile* profile)
227 : profile_(profile), 228 : profile_(profile),
228 weak_factory_(this) { 229 weak_factory_(this) {
229 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) 230 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin))
230 return; 231 return;
231 232
Joao da Silva 2013/06/12 15:30:29 The managed mode check should be here, and return
Bernhard Bauer 2013/06/12 19:01:39 Done.
232 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. 233 // Initialize/shutdown the UserCloudPolicyManager when the user signs out.
233 registrar_.Add(this, 234 registrar_.Add(this,
234 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 235 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
235 content::Source<Profile>(profile)); 236 content::Source<Profile>(profile));
236 237
237 // Listen for an OAuth token to become available so we can register a client 238 // Listen for an OAuth token to become available so we can register a client
238 // if for some reason the client is not already registered (for example, if 239 // if for some reason the client is not already registered (for example, if
239 // the policy load failed during initial signin). 240 // the policy load failed during initial signin).
240 registrar_.Add(this, 241 registrar_.Add(this,
241 chrome::NOTIFICATION_TOKEN_AVAILABLE, 242 chrome::NOTIFICATION_TOKEN_AVAILABLE,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 ShutdownUserCloudPolicyManager(); 393 ShutdownUserCloudPolicyManager();
393 else 394 else
394 InitializeForSignedInUser(); 395 InitializeForSignedInUser();
395 break; 396 break;
396 } 397 }
397 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { 398 case chrome::NOTIFICATION_TOKEN_AVAILABLE: {
398 const TokenService::TokenAvailableDetails& token_details = 399 const TokenService::TokenAvailableDetails& token_details =
399 *(content::Details<const TokenService::TokenAvailableDetails>( 400 *(content::Details<const TokenService::TokenAvailableDetails>(
400 details).ptr()); 401 details).ptr());
401 if (token_details.service() == 402 if (token_details.service() ==
402 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { 403 GaiaConstants::kGaiaOAuth2LoginRefreshToken &&
404 !ManagedUserService::ProfileIsManaged(profile_)) {
Joao da Silva 2013/06/12 15:30:29 #ifdef after moving
Bernhard Bauer 2013/06/12 19:01:39 Done.
403 SigninManager* signin_manager = 405 SigninManager* signin_manager =
404 SigninManagerFactory::GetForProfile(profile_); 406 SigninManagerFactory::GetForProfile(profile_);
405 std::string username = signin_manager->GetAuthenticatedUsername(); 407 std::string username = signin_manager->GetAuthenticatedUsername();
406 // Should not have GAIA tokens if the user isn't signed in. 408 // Should not have GAIA tokens if the user isn't signed in.
407 DCHECK(!username.empty()); 409 DCHECK(!username.empty());
408 // TokenService now has a refresh token (implying that the user is 410 // TokenService now has a refresh token (implying that the user is
409 // signed in) so initialize the UserCloudPolicyManager. 411 // signed in) so initialize the UserCloudPolicyManager.
410 InitializeForSignedInUser(); 412 InitializeForSignedInUser();
411 } 413 }
412 break; 414 break;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // before UserCloudPolicyManager shuts down the CloudPolicyClient. 584 // before UserCloudPolicyManager shuts down the CloudPolicyClient.
583 registration_helper_.reset(); 585 registration_helper_.reset();
584 StopObserving(); 586 StopObserving();
585 } 587 }
586 588
587 UserCloudPolicyManager* UserPolicySigninService::GetManager() { 589 UserCloudPolicyManager* UserPolicySigninService::GetManager() {
588 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 590 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
589 } 591 }
590 592
591 } // namespace policy 593 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698