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

Side by Side Diff: chrome/browser/signin/signin_manager.cc

Issue 71723002: This is the second CL of several that will eventually replace TokenService with (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years 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
« no previous file with comments | « chrome/browser/signin/signin_manager.h ('k') | chrome/browser/signin/signin_manager_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/signin/signin_manager.h" 5 #include "chrome/browser/signin/signin_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/profiles/profile_io_data.h" 18 #include "chrome/browser/profiles/profile_io_data.h"
19 #include "chrome/browser/signin/about_signin_internals.h" 19 #include "chrome/browser/signin/about_signin_internals.h"
20 #include "chrome/browser/signin/about_signin_internals_factory.h" 20 #include "chrome/browser/signin/about_signin_internals_factory.h"
21 #include "chrome/browser/signin/local_auth.h" 21 #include "chrome/browser/signin/local_auth.h"
22 #include "chrome/browser/signin/profile_oauth2_token_service.h"
23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
22 #include "chrome/browser/signin/signin_global_error.h" 24 #include "chrome/browser/signin/signin_global_error.h"
23 #include "chrome/browser/signin/signin_internals_util.h" 25 #include "chrome/browser/signin/signin_internals_util.h"
24 #include "chrome/browser/signin/signin_manager_cookie_helper.h" 26 #include "chrome/browser/signin/signin_manager_cookie_helper.h"
25 #include "chrome/browser/signin/signin_manager_delegate.h" 27 #include "chrome/browser/signin/signin_manager_delegate.h"
26 #include "chrome/browser/signin/signin_manager_factory.h" 28 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/browser/signin/token_service.h"
28 #include "chrome/browser/signin/token_service_factory.h"
29 #include "chrome/browser/ui/global_error/global_error_service.h" 29 #include "chrome/browser/ui/global_error/global_error_service.h"
30 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 30 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
31 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/render_process_host.h" 35 #include "content/public/browser/render_process_host.h"
36 #include "google_apis/gaia/gaia_auth_fetcher.h" 36 #include "google_apis/gaia/gaia_auth_fetcher.h"
37 #include "google_apis/gaia/gaia_auth_util.h" 37 #include "google_apis/gaia/gaia_auth_util.h"
38 #include "google_apis/gaia/gaia_constants.h" 38 #include "google_apis/gaia/gaia_constants.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 bool SigninManager::HasSigninProcess() const { 115 bool SigninManager::HasSigninProcess() const {
116 return signin_process_id_ != kInvalidProcessId; 116 return signin_process_id_ != kInvalidProcessId;
117 } 117 }
118 118
119 SigninManager::~SigninManager() { 119 SigninManager::~SigninManager() {
120 } 120 }
121 121
122 void SigninManager::InitTokenService() { 122 void SigninManager::InitTokenService() {
123 SigninManagerBase::InitTokenService(); 123 ProfileOAuth2TokenService* token_service =
124 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 124 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
125 if (token_service && !GetAuthenticatedUsername().empty()) 125 if (token_service && !GetAuthenticatedUsername().empty())
126 token_service->LoadTokensFromDB(); 126 token_service->LoadCredentials();
127 } 127 }
128 128
129 std::string SigninManager::SigninTypeToString( 129 std::string SigninManager::SigninTypeToString(
130 SigninManager::SigninType type) { 130 SigninManager::SigninType type) {
131 switch (type) { 131 switch (type) {
132 case SIGNIN_TYPE_NONE: 132 case SIGNIN_TYPE_NONE:
133 return "No Signin"; 133 return "No Signin";
134 case SIGNIN_TYPE_WITH_CREDENTIALS: 134 case SIGNIN_TYPE_WITH_CREDENTIALS:
135 return "Signin with credentials"; 135 return "Signin with credentials";
136 case SIGNIN_TYPE_WITH_OAUTH_CODE: 136 case SIGNIN_TYPE_WITH_OAUTH_CODE:
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 clear_authenticated_username(); 327 clear_authenticated_username();
328 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); 328 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
329 329
330 // Erase (now) stale information from AboutSigninInternals. 330 // Erase (now) stale information from AboutSigninInternals.
331 NotifyDiagnosticsObservers(USERNAME, ""); 331 NotifyDiagnosticsObservers(USERNAME, "");
332 332
333 content::NotificationService::current()->Notify( 333 content::NotificationService::current()->Notify(
334 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 334 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
335 content::Source<Profile>(profile_), 335 content::Source<Profile>(profile_),
336 content::Details<const GoogleServiceSignoutDetails>(&details)); 336 content::Details<const GoogleServiceSignoutDetails>(&details));
337 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 337 ProfileOAuth2TokenService* token_service =
338 token_service->ResetCredentialsInMemory(); 338 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
339 token_service->EraseTokensFromDB(); 339 token_service->RevokeAllCredentials();
340 } 340 }
341 341
342 void SigninManager::Initialize(Profile* profile, PrefService* local_state) { 342 void SigninManager::Initialize(Profile* profile, PrefService* local_state) {
343 SigninManagerBase::Initialize(profile, local_state); 343 SigninManagerBase::Initialize(profile, local_state);
344 344
345 InitTokenService();
346
345 // local_state can be null during unit tests. 347 // local_state can be null during unit tests.
346 if (local_state) { 348 if (local_state) {
347 local_state_pref_registrar_.Init(local_state); 349 local_state_pref_registrar_.Init(local_state);
348 local_state_pref_registrar_.Add( 350 local_state_pref_registrar_.Add(
349 prefs::kGoogleServicesUsernamePattern, 351 prefs::kGoogleServicesUsernamePattern,
350 base::Bind(&SigninManager::OnGoogleServicesUsernamePatternChanged, 352 base::Bind(&SigninManager::OnGoogleServicesUsernamePatternChanged,
351 weak_pointer_factory_.GetWeakPtr())); 353 weak_pointer_factory_.GetWeakPtr()));
352 } 354 }
353 signin_allowed_.Init(prefs::kSigninAllowed, profile_->GetPrefs(), 355 signin_allowed_.Init(prefs::kSigninAllowed, profile_->GetPrefs(),
354 base::Bind(&SigninManager::OnSigninAllowedPrefChanged, 356 base::Bind(&SigninManager::OnSigninAllowedPrefChanged,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } else { 546 } else {
545 // No oauth token or callback, so just complete our pending signin. 547 // No oauth token or callback, so just complete our pending signin.
546 CompletePendingSignin(); 548 CompletePendingSignin();
547 } 549 }
548 } 550 }
549 551
550 void SigninManager::CompletePendingSignin() { 552 void SigninManager::CompletePendingSignin() {
551 DCHECK(!possibly_invalid_username_.empty()); 553 DCHECK(!possibly_invalid_username_.empty());
552 OnSignedIn(possibly_invalid_username_); 554 OnSignedIn(possibly_invalid_username_);
553 555
554 // If we have oauth2 tokens, tell token service about them so it does not 556 DCHECK(!temp_oauth_login_tokens_.refresh_token.empty());
555 // need to fetch them again. Its important that the authenticated name has 557 DCHECK(!GetAuthenticatedUsername().empty());
556 // already been set before sending the oauth2 token to the token service. 558 ProfileOAuth2TokenService* token_service =
557 // Some token service listeners will query the authenticated name when they 559 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
558 // receive the token available notification. 560 token_service->UpdateCredentials(GetAuthenticatedUsername(),
559 if (!temp_oauth_login_tokens_.refresh_token.empty()) { 561 temp_oauth_login_tokens_.refresh_token);
560 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 562 temp_oauth_login_tokens_ = ClientOAuthResult();
561 DCHECK(!GetAuthenticatedUsername().empty());
562 token_service->UpdateCredentialsWithOAuth2(temp_oauth_login_tokens_);
563 temp_oauth_login_tokens_ = ClientOAuthResult();
564 }
565 } 563 }
566 564
567 void SigninManager::OnExternalSigninCompleted(const std::string& username) { 565 void SigninManager::OnExternalSigninCompleted(const std::string& username) {
568 OnSignedIn(username); 566 OnSignedIn(username);
569 } 567 }
570 568
571 void SigninManager::OnSignedIn(const std::string& username) { 569 void SigninManager::OnSignedIn(const std::string& username) {
572 SetAuthenticatedUsername(username); 570 SetAuthenticatedUsername(username);
573 possibly_invalid_username_.clear(); 571 possibly_invalid_username_.clear();
574 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 572 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 617 }
620 } 618 }
621 619
622 void SigninManager::ProhibitSignout(bool prohibit_signout) { 620 void SigninManager::ProhibitSignout(bool prohibit_signout) {
623 prohibit_signout_ = prohibit_signout; 621 prohibit_signout_ = prohibit_signout;
624 } 622 }
625 623
626 bool SigninManager::IsSignoutProhibited() const { 624 bool SigninManager::IsSignoutProhibited() const {
627 return prohibit_signout_; 625 return prohibit_signout_;
628 } 626 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_manager.h ('k') | chrome/browser/signin/signin_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698