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/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"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
29 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
30 #include "google_apis/gaia/gaia_constants.h" 30 #include "google_apis/gaia/gaia_constants.h"
31 #include "google_apis/gaia/gaia_urls.h" 31 #include "google_apis/gaia/gaia_urls.h"
32 #include "google_apis/gaia/oauth2_access_token_consumer.h" 32 #include "google_apis/gaia/oauth2_access_token_consumer.h"
33 #include "google_apis/gaia/oauth2_access_token_fetcher.h" 33 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
34 34
35 #if defined(ENABLE_MANAGED_USERS)
36 #include "chrome/browser/managed_mode/managed_user_service.h"
37 #endif
38
35 namespace em = enterprise_management; 39 namespace em = enterprise_management;
36 40
37 namespace { 41 namespace {
38 42
39 const char kServiceScopeGetUserInfo[] = 43 const char kServiceScopeGetUserInfo[] =
40 "https://www.googleapis.com/auth/userinfo.email"; 44 "https://www.googleapis.com/auth/userinfo.email";
41 45
42 // The key under which the hosted-domain value is stored in the UserInfo 46 // The key under which the hosted-domain value is stored in the UserInfo
43 // response. 47 // response.
44 const char kGetHostedDomainKey[] = "hd"; 48 const char kGetHostedDomainKey[] = "hd";
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 RequestCompleted(); 226 RequestCompleted();
223 } 227 }
224 228
225 UserPolicySigninService::UserPolicySigninService( 229 UserPolicySigninService::UserPolicySigninService(
226 Profile* profile) 230 Profile* profile)
227 : profile_(profile), 231 : profile_(profile),
228 weak_factory_(this) { 232 weak_factory_(this) {
229 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) 233 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin))
230 return; 234 return;
231 235
236 #if defined(ENABLE_MANAGED_USERS)
237 if (ManagedUserService::ProfileIsManaged(profile_))
Bernhard Bauer 2013/06/17 14:23:53 Hm, turns out this doesn't work with newly created
Joao da Silva 2013/06/17 14:26:02 sgtm. Also registrar_.RemoveAll() then.
Bernhard Bauer 2013/06/17 14:36:10 Done.
238 return;
239 #endif
240
232 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. 241 // Initialize/shutdown the UserCloudPolicyManager when the user signs out.
233 registrar_.Add(this, 242 registrar_.Add(this,
234 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 243 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
235 content::Source<Profile>(profile)); 244 content::Source<Profile>(profile));
236 245
237 // Listen for an OAuth token to become available so we can register a client 246 // 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 247 // if for some reason the client is not already registered (for example, if
239 // the policy load failed during initial signin). 248 // the policy load failed during initial signin).
240 registrar_.Add(this, 249 registrar_.Add(this,
241 chrome::NOTIFICATION_TOKEN_AVAILABLE, 250 chrome::NOTIFICATION_TOKEN_AVAILABLE,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 ShutdownUserCloudPolicyManager(); 401 ShutdownUserCloudPolicyManager();
393 else 402 else
394 InitializeForSignedInUser(); 403 InitializeForSignedInUser();
395 break; 404 break;
396 } 405 }
397 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { 406 case chrome::NOTIFICATION_TOKEN_AVAILABLE: {
398 const TokenService::TokenAvailableDetails& token_details = 407 const TokenService::TokenAvailableDetails& token_details =
399 *(content::Details<const TokenService::TokenAvailableDetails>( 408 *(content::Details<const TokenService::TokenAvailableDetails>(
400 details).ptr()); 409 details).ptr());
401 if (token_details.service() == 410 if (token_details.service() ==
402 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { 411 GaiaConstants::kGaiaOAuth2LoginRefreshToken) {
403 SigninManager* signin_manager = 412 SigninManager* signin_manager =
404 SigninManagerFactory::GetForProfile(profile_); 413 SigninManagerFactory::GetForProfile(profile_);
405 std::string username = signin_manager->GetAuthenticatedUsername(); 414 std::string username = signin_manager->GetAuthenticatedUsername();
406 // Should not have GAIA tokens if the user isn't signed in. 415 // Should not have GAIA tokens if the user isn't signed in.
407 DCHECK(!username.empty()); 416 DCHECK(!username.empty());
408 // TokenService now has a refresh token (implying that the user is 417 // TokenService now has a refresh token (implying that the user is
409 // signed in) so initialize the UserCloudPolicyManager. 418 // signed in) so initialize the UserCloudPolicyManager.
410 InitializeForSignedInUser(); 419 InitializeForSignedInUser();
411 } 420 }
412 break; 421 break;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // before UserCloudPolicyManager shuts down the CloudPolicyClient. 591 // before UserCloudPolicyManager shuts down the CloudPolicyClient.
583 registration_helper_.reset(); 592 registration_helper_.reset();
584 StopObserving(); 593 StopObserving();
585 } 594 }
586 595
587 UserCloudPolicyManager* UserPolicySigninService::GetManager() { 596 UserCloudPolicyManager* UserPolicySigninService::GetManager() {
588 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 597 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
589 } 598 }
590 599
591 } // namespace policy 600 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_user_service.cc ('k') | chrome/browser/sync/profile_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698