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/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 Loading... | |
| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 DCHECK_EQ(client, client_); | 225 DCHECK_EQ(client, client_); |
| 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 |
|
Joao da Silva
2013/06/12 19:56:13
Really, the check should be here :-) Note the chec
Bernhard Bauer
2013/06/13 09:45:05
Urr, yes, sorry. I didn't pay much attention and m
| |
| 232 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. | 236 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. |
| 233 registrar_.Add(this, | 237 registrar_.Add(this, |
| 234 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 238 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 235 content::Source<Profile>(profile)); | 239 content::Source<Profile>(profile)); |
| 236 | 240 |
| 237 // Listen for an OAuth token to become available so we can register a client | 241 // 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 | 242 // if for some reason the client is not already registered (for example, if |
| 239 // the policy load failed during initial signin). | 243 // the policy load failed during initial signin). |
| 240 registrar_.Add(this, | 244 registrar_.Add(this, |
| 241 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 245 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 return; | 368 return; |
| 365 } | 369 } |
| 366 | 370 |
| 367 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, | 371 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, |
| 368 // skip initialization. | 372 // skip initialization. |
| 369 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) { | 373 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) { |
| 370 DVLOG(1) << "Skipping initialization for tests due to missing components."; | 374 DVLOG(1) << "Skipping initialization for tests due to missing components."; |
| 371 return; | 375 return; |
| 372 } | 376 } |
| 373 | 377 |
| 378 #if defined(ENABLE_MANAGED_USERS) | |
| 379 if (ManagedUserService::ProfileIsManaged(profile_)) | |
| 380 return; | |
| 381 #endif | |
| 382 | |
| 374 switch (type) { | 383 switch (type) { |
| 375 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | 384 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: |
| 376 ShutdownUserCloudPolicyManager(); | 385 ShutdownUserCloudPolicyManager(); |
| 377 break; | 386 break; |
| 378 case chrome::NOTIFICATION_IMPORT_FINISHED: | 387 case chrome::NOTIFICATION_IMPORT_FINISHED: |
| 379 case chrome::NOTIFICATION_PROFILE_ADDED: { | 388 case chrome::NOTIFICATION_PROFILE_ADDED: { |
| 380 // A new profile has been loaded - if it's signed in, then initialize the | 389 // A new profile has been loaded - if it's signed in, then initialize the |
| 381 // UCPM, otherwise shut down the UCPM (which deletes any cached policy | 390 // UCPM, otherwise shut down the UCPM (which deletes any cached policy |
| 382 // data). This must be done here instead of at constructor time because | 391 // data). This must be done here instead of at constructor time because |
| 383 // the Profile is not fully initialized when this object is constructed | 392 // the Profile is not fully initialized when this object is constructed |
| 384 // (DoFinalInit() has not yet been called, so ProfileIOData and | 393 // (DoFinalInit() has not yet been called, so ProfileIOData and |
| 385 // SSLConfigServiceManager have not been created yet). | 394 // SSLConfigServiceManager have not been created yet). |
| 386 // TODO(atwilson): Switch to using a timer instead, to avoid contention | 395 // TODO(atwilson): Switch to using a timer instead, to avoid contention |
| 387 // with other services at startup (http://crbug.com/165468). | 396 // with other services at startup (http://crbug.com/165468). |
| 388 SigninManager* signin_manager = | 397 SigninManager* signin_manager = |
| 389 SigninManagerFactory::GetForProfile(profile_); | 398 SigninManagerFactory::GetForProfile(profile_); |
| 390 std::string username = signin_manager->GetAuthenticatedUsername(); | 399 std::string username = signin_manager->GetAuthenticatedUsername(); |
| 391 if (username.empty()) | 400 if (username.empty()) |
| 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 Loading... | |
| 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 |
| OLD | NEW |