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

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: Undo change to SigninTracker Created 7 years, 1 month 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
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 // local_state can be null during unit tests. 345 // local_state can be null during unit tests.
346 if (local_state) { 346 if (local_state) {
347 local_state_pref_registrar_.Init(local_state); 347 local_state_pref_registrar_.Init(local_state);
348 local_state_pref_registrar_.Add( 348 local_state_pref_registrar_.Add(
349 prefs::kGoogleServicesUsernamePattern, 349 prefs::kGoogleServicesUsernamePattern,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } else { 544 } else {
545 // No oauth token or callback, so just complete our pending signin. 545 // No oauth token or callback, so just complete our pending signin.
546 CompletePendingSignin(); 546 CompletePendingSignin();
547 } 547 }
548 } 548 }
549 549
550 void SigninManager::CompletePendingSignin() { 550 void SigninManager::CompletePendingSignin() {
551 DCHECK(!possibly_invalid_username_.empty()); 551 DCHECK(!possibly_invalid_username_.empty());
552 OnSignedIn(possibly_invalid_username_); 552 OnSignedIn(possibly_invalid_username_);
553 553
554 // If we have oauth2 tokens, tell token service about them so it does not 554 DCHECK(!temp_oauth_login_tokens_.refresh_token.empty());
555 // need to fetch them again. Its important that the authenticated name has 555 ProfileOAuth2TokenService* token_service =
556 // already been set before sending the oauth2 token to the token service. 556 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
557 // Some token service listeners will query the authenticated name when they 557 token_service->UpdateCredentials(GetAuthenticatedUsername(),
558 // receive the token available notification. 558 temp_oauth_login_tokens_.refresh_token);
559 if (!temp_oauth_login_tokens_.refresh_token.empty()) { 559 temp_oauth_login_tokens_ = ClientOAuthResult();
560 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
561 DCHECK(!GetAuthenticatedUsername().empty());
fgorski 2013/11/13 20:36:48 Do we no longer care about this DCHECK, or was it
Roger Tawa OOO till Jul 10th 2013/11/13 20:56:12 No, good to have the check. Put it back in.
562 token_service->UpdateCredentialsWithOAuth2(temp_oauth_login_tokens_);
563 temp_oauth_login_tokens_ = ClientOAuthResult();
564 }
565 } 560 }
566 561
567 void SigninManager::OnExternalSigninCompleted(const std::string& username) { 562 void SigninManager::OnExternalSigninCompleted(const std::string& username) {
568 OnSignedIn(username); 563 OnSignedIn(username);
569 } 564 }
570 565
571 void SigninManager::OnSignedIn(const std::string& username) { 566 void SigninManager::OnSignedIn(const std::string& username) {
572 SetAuthenticatedUsername(username); 567 SetAuthenticatedUsername(username);
573 possibly_invalid_username_.clear(); 568 possibly_invalid_username_.clear();
574 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 569 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 614 }
620 } 615 }
621 616
622 void SigninManager::ProhibitSignout(bool prohibit_signout) { 617 void SigninManager::ProhibitSignout(bool prohibit_signout) {
623 prohibit_signout_ = prohibit_signout; 618 prohibit_signout_ = prohibit_signout;
624 } 619 }
625 620
626 bool SigninManager::IsSignoutProhibited() const { 621 bool SigninManager::IsSignoutProhibited() const {
627 return prohibit_signout_; 622 return prohibit_signout_;
628 } 623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698