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

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

Issue 186773005: Move SigninAccountIdHelper away from listening to Signin notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/signin/signin_account_id_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_account_id_helper.h" 5 #include "chrome/browser/signin/signin_account_id_helper.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service.h" 9 #include "chrome/browser/signin/profile_oauth2_token_service.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/signin/signin_manager.h"
13 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
14 #include "content/public/browser/notification_service.h"
15 #include "google_apis/gaia/gaia_oauth_client.h" 12 #include "google_apis/gaia/gaia_oauth_client.h"
16 13
17 // TODO(guohui): this class should be moved to a more generic place for reuse. 14 // TODO(guohui): this class should be moved to a more generic place for reuse.
18 class SigninAccountIdHelper::GaiaIdFetcher 15 class SigninAccountIdHelper::GaiaIdFetcher
19 : public OAuth2TokenService::Consumer, 16 : public OAuth2TokenService::Consumer,
20 public gaia::GaiaOAuthClient::Delegate { 17 public gaia::GaiaOAuthClient::Delegate {
21 public: 18 public:
22 GaiaIdFetcher(SigninManagerBase* signin_manager, 19 GaiaIdFetcher(SigninManagerBase* signin_manager,
23 SigninAccountIdHelper* signin_account_id_helper); 20 SigninAccountIdHelper* signin_account_id_helper);
24 virtual ~GaiaIdFetcher(); 21 virtual ~GaiaIdFetcher();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 97 }
101 98
102 void SigninAccountIdHelper::GaiaIdFetcher::OnNetworkError( 99 void SigninAccountIdHelper::GaiaIdFetcher::OnNetworkError(
103 int response_code) { 100 int response_code) {
104 VLOG(1) << "OnNetworkError " << response_code; 101 VLOG(1) << "OnNetworkError " << response_code;
105 } 102 }
106 103
107 SigninAccountIdHelper::SigninAccountIdHelper(SigninManagerBase* signin_manager) 104 SigninAccountIdHelper::SigninAccountIdHelper(SigninManagerBase* signin_manager)
108 : signin_manager_(signin_manager) { 105 : signin_manager_(signin_manager) {
109 DCHECK(signin_manager_); 106 DCHECK(signin_manager_);
110 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 107 signin_manager_->AddObserver(this);
111 content::Source<Profile>(signin_manager_->profile()));
112
113 ProfileOAuth2TokenService* token_service = 108 ProfileOAuth2TokenService* token_service =
114 ProfileOAuth2TokenServiceFactory::GetForProfile( 109 ProfileOAuth2TokenServiceFactory::GetForProfile(
115 signin_manager_->profile()); 110 signin_manager_->profile());
116 std::string primary_email = signin_manager_->GetAuthenticatedAccountId(); 111 std::string primary_email = signin_manager_->GetAuthenticatedAccountId();
117 if (!primary_email.empty() && 112 if (!primary_email.empty() &&
118 token_service->RefreshTokenIsAvailable(primary_email) && 113 token_service->RefreshTokenIsAvailable(primary_email) &&
119 !disable_for_test_) { 114 !disable_for_test_) {
120 id_fetcher_.reset(new GaiaIdFetcher(signin_manager_, this)); 115 id_fetcher_.reset(new GaiaIdFetcher(signin_manager_, this));
121 } 116 }
122 token_service->AddObserver(this); 117 token_service->AddObserver(this);
123 } 118 }
124 119
125 SigninAccountIdHelper::~SigninAccountIdHelper() { 120 SigninAccountIdHelper::~SigninAccountIdHelper() {
121 signin_manager_->RemoveObserver(this);
126 ProfileOAuth2TokenServiceFactory::GetForProfile(signin_manager_->profile())-> 122 ProfileOAuth2TokenServiceFactory::GetForProfile(signin_manager_->profile())->
127 RemoveObserver(this); 123 RemoveObserver(this);
128 } 124 }
129 125
130 void SigninAccountIdHelper::Observe( 126 void SigninAccountIdHelper::GoogleSignedOut(const std::string& username) {
131 int type, 127 signin_manager_->profile()->GetPrefs()->ClearPref(
132 const content::NotificationSource& source, 128 prefs::kGoogleServicesUserAccountId);
133 const content::NotificationDetails& details) {
134 if (type == chrome::NOTIFICATION_GOOGLE_SIGNED_OUT) {
135 signin_manager_->profile()->GetPrefs()->
136 ClearPref(prefs::kGoogleServicesUserAccountId);
137 }
138 } 129 }
139 130
140 void SigninAccountIdHelper::OnRefreshTokenAvailable( 131 void SigninAccountIdHelper::OnRefreshTokenAvailable(
141 const std::string& account_id) { 132 const std::string& account_id) {
142 if (account_id == signin_manager_->GetAuthenticatedAccountId()) { 133 if (account_id == signin_manager_->GetAuthenticatedAccountId()) {
143 std::string current_gaia_id = 134 std::string current_gaia_id =
144 signin_manager_->profile()->GetPrefs()-> 135 signin_manager_->profile()->GetPrefs()->
145 GetString(prefs::kGoogleServicesUserAccountId); 136 GetString(prefs::kGoogleServicesUserAccountId);
146 if (current_gaia_id.empty() && !disable_for_test_) { 137 if (current_gaia_id.empty() && !disable_for_test_) {
147 id_fetcher_.reset(new GaiaIdFetcher(signin_manager_, this)); 138 id_fetcher_.reset(new GaiaIdFetcher(signin_manager_, this));
(...skipping 10 matching lines...) Expand all
158 } 149 }
159 150
160 // static 151 // static
161 bool SigninAccountIdHelper::disable_for_test_ = false; 152 bool SigninAccountIdHelper::disable_for_test_ = false;
162 153
163 // static 154 // static
164 void SigninAccountIdHelper::SetDisableForTest(bool disable_for_test) { 155 void SigninAccountIdHelper::SetDisableForTest(bool disable_for_test) {
165 disable_for_test_ = disable_for_test; 156 disable_for_test_ = disable_for_test;
166 } 157 }
167 158
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_account_id_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698