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 "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/policy/browser_policy_connector.h" | 9 #include "chrome/browser/policy/browser_policy_connector.h" |
| 10 #include "chrome/browser/policy/cloud_policy_service.h" | 10 #include "chrome/browser/policy/cloud_policy_service.h" |
| 11 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 11 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
| 12 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" | 12 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/signin/about_signin_internals.h" | |
| 16 #include "chrome/browser/signin/about_signin_internals_factory.h" | |
| 15 #include "chrome/browser/signin/signin_manager.h" | 17 #include "chrome/browser/signin/signin_manager.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/browser/signin/token_service.h" | 19 #include "chrome/browser/signin/token_service.h" |
| 18 #include "chrome/browser/signin/token_service_factory.h" | 20 #include "chrome/browser/signin/token_service_factory.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 23 #include "google_apis/gaia/gaia_constants.h" | 25 #include "google_apis/gaia/gaia_constants.h" |
| 24 #include "google_apis/gaia/gaia_urls.h" | 26 #include "google_apis/gaia/gaia_urls.h" |
| 25 #include "google_apis/gaia/oauth2_access_token_fetcher.h" | 27 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
| 26 | 28 |
| 29 using content::BrowserThread; | |
| 30 | |
| 27 namespace { | 31 namespace { |
| 28 // Various OAuth service scopes required to do CloudPolicyClient registration. | 32 // Various OAuth service scopes required to do CloudPolicyClient registration. |
| 29 const char kServiceScopeChromeOSDeviceManagement[] = | 33 const char kServiceScopeChromeOSDeviceManagement[] = |
| 30 "https://www.googleapis.com/auth/chromeosdevicemanagement"; | 34 "https://www.googleapis.com/auth/chromeosdevicemanagement"; |
| 31 const char kServiceScopeGetUserInfo[] = | 35 const char kServiceScopeGetUserInfo[] = |
| 32 "https://www.googleapis.com/auth/userinfo.email"; | 36 "https://www.googleapis.com/auth/userinfo.email"; |
| 33 | 37 |
| 34 // The key under which the hosted-domain value is stored in the UserInfo | 38 // The key under which the hosted-domain value is stored in the UserInfo |
| 35 // response. | 39 // response. |
| 36 const char kGetHostedDomainKey[] = "hd"; | 40 const char kGetHostedDomainKey[] = "hd"; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 gaia_urls->oauth2_chrome_client_id(), | 283 gaia_urls->oauth2_chrome_client_id(), |
| 280 gaia_urls->oauth2_chrome_client_secret(), | 284 gaia_urls->oauth2_chrome_client_secret(), |
| 281 login_token, | 285 login_token, |
| 282 scopes); | 286 scopes); |
| 283 } | 287 } |
| 284 | 288 |
| 285 void UserPolicySigninService::OnGetTokenFailure( | 289 void UserPolicySigninService::OnGetTokenFailure( |
| 286 const GoogleServiceAuthError& error) { | 290 const GoogleServiceAuthError& error) { |
| 287 DLOG(WARNING) << "Could not fetch access token for " | 291 DLOG(WARNING) << "Could not fetch access token for " |
| 288 << kServiceScopeChromeOSDeviceManagement; | 292 << kServiceScopeChromeOSDeviceManagement; |
| 293 | |
| 294 // TODO(vishwath): This can be removed when refactoring this class to use | |
| 295 // OAuth2TokenService instead. | |
| 296 // Let AboutSigninInternals know about the failed token fetch. | |
| 297 DCHECK(profile_); | |
|
Mattias Nissler (ping if slow)
2012/12/20 09:16:11
Any good reason for this DCHECK? If |profile_| is
| |
| 298 AboutSigninInternalsFactory::GetForProfile(profile_)-> | |
| 299 NotifyTokenReceivedFailure( | |
| 300 signin_internals_util::kUserPolicySigninServiceToken, | |
| 301 error.ToString()); | |
| 302 | |
| 289 oauth2_access_token_fetcher_.reset(); | 303 oauth2_access_token_fetcher_.reset(); |
| 290 // If there was a pending fetch request, let them know the fetch failed. | 304 // If there was a pending fetch request, let them know the fetch failed. |
| 291 NotifyPendingFetchCallback(false); | 305 NotifyPendingFetchCallback(false); |
| 292 } | 306 } |
| 293 | 307 |
| 294 void UserPolicySigninService::OnGetTokenSuccess( | 308 void UserPolicySigninService::OnGetTokenSuccess( |
| 295 const std::string& access_token, | 309 const std::string& access_token, |
| 296 const base::Time& expiration_time) { | 310 const base::Time& expiration_time) { |
| 311 // Pass along the new access token to the CloudPolicyClient. | |
|
Mattias Nissler (ping if slow)
2012/12/20 09:16:11
nit: This comment is stale and probably a merge ar
| |
| 297 oauth_access_token_ = access_token; | 312 oauth_access_token_ = access_token; |
| 298 DVLOG(1) << "Fetched new scoped OAuth token:" << oauth_access_token_; | 313 DVLOG(1) << "Fetched new scoped OAuth token:" << access_token; |
| 314 | |
| 315 // TODO(vishwath): This can be removed when refactoring this class to use | |
| 316 // OAuth2TokenService instead. | |
|
Andrew T Wilson (Slow)
2012/12/21 11:42:29
Remove this comment, as we are not going to refact
| |
| 317 DCHECK(profile_); | |
|
Mattias Nissler (ping if slow)
2012/12/20 09:16:11
same here.
| |
| 318 AboutSigninInternalsFactory::GetForProfile(profile_)-> | |
| 319 NotifyTokenReceivedSuccess( | |
| 320 signin_internals_util::kUserPolicySigninServiceToken, | |
| 321 access_token, | |
| 322 true); | |
| 323 | |
| 299 oauth2_access_token_fetcher_.reset(); | 324 oauth2_access_token_fetcher_.reset(); |
| 300 // Now we've gotten our access token - contact GAIA to see if this is a | 325 // Now we've gotten our access token - contact GAIA to see if this is a |
| 301 // hosted domain. | 326 // hosted domain. |
| 302 user_info_fetcher_.reset(new UserInfoFetcher(this, | 327 user_info_fetcher_.reset(new UserInfoFetcher(this, |
| 303 profile_->GetRequestContext())); | 328 profile_->GetRequestContext())); |
| 304 user_info_fetcher_->Start(oauth_access_token_); | 329 user_info_fetcher_->Start(oauth_access_token_); |
| 305 } | 330 } |
| 306 | 331 |
| 307 void UserPolicySigninService::OnGetUserInfoFailure( | 332 void UserPolicySigninService::OnGetUserInfoFailure( |
| 308 const GoogleServiceAuthError& error) { | 333 const GoogleServiceAuthError& error) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 | 385 |
| 361 void UserPolicySigninService::Shutdown() { | 386 void UserPolicySigninService::Shutdown() { |
| 362 StopObserving(); | 387 StopObserving(); |
| 363 } | 388 } |
| 364 | 389 |
| 365 UserCloudPolicyManager* UserPolicySigninService::GetManager() { | 390 UserCloudPolicyManager* UserPolicySigninService::GetManager() { |
| 366 return UserCloudPolicyManagerFactory::GetForProfile(profile_); | 391 return UserCloudPolicyManagerFactory::GetForProfile(profile_); |
| 367 } | 392 } |
| 368 | 393 |
| 369 } // namespace policy | 394 } // namespace policy |
| OLD | NEW |