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

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

Issue 15734014: Split token-related methods from WebDataService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
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/token_service.h" 5 #include "chrome/browser/signin/token_service.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/signin_manager.h" 12 #include "chrome/browser/signin/signin_manager.h"
13 #include "chrome/browser/signin/signin_manager_factory.h" 13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/browser/webdata/web_data_service.h" 14 #include "chrome/browser/webdata/token_web_data.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "google_apis/gaia/gaia_auth_fetcher.h" 21 #include "google_apis/gaia/gaia_auth_fetcher.h"
22 #include "google_apis/gaia/gaia_constants.h" 22 #include "google_apis/gaia/gaia_constants.h"
23 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
24 24
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 TokenService::~TokenService() { 61 TokenService::~TokenService() {
62 } 62 }
63 63
64 void TokenService::Shutdown() { 64 void TokenService::Shutdown() {
65 if (!source_.empty()) { 65 if (!source_.empty()) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 ResetCredentialsInMemory(); 67 ResetCredentialsInMemory();
68 } 68 }
69 web_data_service_ = NULL; 69 token_web_data_ = NULL;
70 } 70 }
71 71
72 void TokenService::Initialize(const char* const source, 72 void TokenService::Initialize(const char* const source,
73 Profile* profile) { 73 Profile* profile) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 if (!source_.empty()) { 75 if (!source_.empty()) {
76 // Already initialized. 76 // Already initialized.
77 return; 77 return;
78 } 78 }
79 DCHECK(!profile_); 79 DCHECK(!profile_);
80 profile_ = profile; 80 profile_ = profile;
81 getter_ = profile->GetRequestContext(); 81 getter_ = profile->GetRequestContext();
82 // Since the user can create a bookmark in incognito, sync may be running. 82 // Since the user can create a bookmark in incognito, sync may be running.
83 // Thus we have to go for explicit access. 83 // Thus we have to go for explicit access.
84 web_data_service_ = WebDataService::FromBrowserContext(profile); 84 token_web_data_ = TokenWebData::FromBrowserContext(profile);
85 source_ = std::string(source); 85 source_ = std::string(source);
86 86
87 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 87 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
88 // Allow the token service to be cleared from the command line. We rely on 88 // Allow the token service to be cleared from the command line. We rely on
89 // SigninManager::Initialize() being called to clear out the 89 // SigninManager::Initialize() being called to clear out the
90 // kGoogleServicesUsername pref before we call EraseTokensFromDB() as 90 // kGoogleServicesUsername pref before we call EraseTokensFromDB() as
91 // otherwise the system would be in an invalid state. 91 // otherwise the system would be in an invalid state.
92 if (cmd_line->HasSwitch(switches::kClearTokenService)) 92 if (cmd_line->HasSwitch(switches::kClearTokenService))
93 EraseTokensFromDB(); 93 EraseTokensFromDB();
94 94
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 void TokenService::ResetCredentialsInMemory() { 133 void TokenService::ResetCredentialsInMemory() {
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
135 135
136 // Terminate any running fetchers. Callbacks will not return. 136 // Terminate any running fetchers. Callbacks will not return.
137 for (size_t i = 0; i < arraysize(kServices); ++i) { 137 for (size_t i = 0; i < arraysize(kServices); ++i) {
138 fetchers_[i].reset(); 138 fetchers_[i].reset();
139 } 139 }
140 140
141 // Cancel pending loads. Callbacks will not return. 141 // Cancel pending loads. Callbacks will not return.
142 if (token_loading_query_) { 142 if (token_loading_query_) {
143 web_data_service_->CancelRequest(token_loading_query_); 143 token_web_data_->CancelRequest(token_loading_query_);
144 token_loading_query_ = 0; 144 token_loading_query_ = 0;
145 } 145 }
146 146
147 tokens_loaded_ = false; 147 tokens_loaded_ = false;
148 token_map_.clear(); 148 token_map_.clear();
149 credentials_ = GaiaAuthConsumer::ClientLoginResult(); 149 credentials_ = GaiaAuthConsumer::ClientLoginResult();
150 } 150 }
151 151
152 void TokenService::UpdateCredentials( 152 void TokenService::UpdateCredentials(
153 const GaiaAuthConsumer::ClientLoginResult& credentials) { 153 const GaiaAuthConsumer::ClientLoginResult& credentials) {
(...skipping 14 matching lines...) Expand all
168 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(LSID, credentials.lsid)); 168 FOR_DIAGNOSTICS_OBSERVERS(NotifySigninValueChanged(LSID, credentials.lsid));
169 } 169 }
170 170
171 void TokenService::UpdateCredentialsWithOAuth2( 171 void TokenService::UpdateCredentialsWithOAuth2(
172 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { 172 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) {
173 SaveOAuth2Credentials(oauth2_tokens); 173 SaveOAuth2Credentials(oauth2_tokens);
174 } 174 }
175 175
176 void TokenService::LoadTokensFromDB() { 176 void TokenService::LoadTokensFromDB() {
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
178 if (web_data_service_.get()) 178 if (token_web_data_.get())
179 token_loading_query_ = web_data_service_->GetAllTokens(this); 179 token_loading_query_ = token_web_data_->GetAllTokens(this);
180 } 180 }
181 181
182 void TokenService::SaveAuthTokenToDB(const std::string& service, 182 void TokenService::SaveAuthTokenToDB(const std::string& service,
183 const std::string& auth_token) { 183 const std::string& auth_token) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
185 if (web_data_service_.get()) 185 if (token_web_data_.get())
186 web_data_service_->SetTokenForService(service, auth_token); 186 token_web_data_->SetTokenForService(service, auth_token);
187 } 187 }
188 188
189 void TokenService::EraseTokensFromDB() { 189 void TokenService::EraseTokensFromDB() {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
191 if (web_data_service_.get()) 191 if (token_web_data_.get())
192 web_data_service_->RemoveAllTokens(); 192 token_web_data_->RemoveAllTokens();
193 193
194 content::NotificationService::current()->Notify( 194 content::NotificationService::current()->Notify(
195 chrome::NOTIFICATION_TOKENS_CLEARED, 195 chrome::NOTIFICATION_TOKENS_CLEARED,
196 content::Source<TokenService>(this), 196 content::Source<TokenService>(this),
197 content::NotificationService::NoDetails()); 197 content::NotificationService::NoDetails());
198 198
199 // Clear in-memory token values stored by AboutSigninInternals 199 // Clear in-memory token values stored by AboutSigninInternals
200 // Note that although this is clearing in-memory values, it belongs here and 200 // Note that although this is clearing in-memory values, it belongs here and
201 // not in ResetCredentialsInMemory() (which is invoked both on sign out and 201 // not in ResetCredentialsInMemory() (which is invoked both on sign out and
202 // shutdown). 202 // shutdown).
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 457
458 void TokenService::AddSigninDiagnosticsObserver( 458 void TokenService::AddSigninDiagnosticsObserver(
459 SigninDiagnosticsObserver* observer) { 459 SigninDiagnosticsObserver* observer) {
460 signin_diagnostics_observers_.AddObserver(observer); 460 signin_diagnostics_observers_.AddObserver(observer);
461 } 461 }
462 462
463 void TokenService::RemoveSigninDiagnosticsObserver( 463 void TokenService::RemoveSigninDiagnosticsObserver(
464 SigninDiagnosticsObserver* observer) { 464 SigninDiagnosticsObserver* observer) {
465 signin_diagnostics_observers_.RemoveObserver(observer); 465 signin_diagnostics_observers_.RemoveObserver(observer);
466 } 466 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698