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

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

Issue 129253003: Revert of Create signin component and componentize TokenWebData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 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/mutable_profile_oauth2_token_service.h" 5 #include "chrome/browser/signin/mutable_profile_oauth2_token_service.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/webdata/web_data_service_factory.h" 8 #include "chrome/browser/webdata/token_web_data.h"
9 #include "components/signin/core/webdata/token_web_data.h"
10 #include "components/webdata/common/web_data_service_base.h" 9 #include "components/webdata/common/web_data_service_base.h"
11 #include "google_apis/gaia/gaia_auth_fetcher.h" 10 #include "google_apis/gaia/gaia_auth_fetcher.h"
12 #include "google_apis/gaia/gaia_constants.h" 11 #include "google_apis/gaia/gaia_constants.h"
13 #include "google_apis/gaia/google_service_auth_error.h" 12 #include "google_apis/gaia/google_service_auth_error.h"
14 #include "net/url_request/url_request_context_getter.h" 13 #include "net/url_request/url_request_context_getter.h"
15 14
16 #if defined(ENABLE_MANAGED_USERS) 15 #if defined(ENABLE_MANAGED_USERS)
17 #include "chrome/browser/managed_mode/managed_user_constants.h" 16 #include "chrome/browser/managed_mode/managed_user_constants.h"
18 #endif 17 #endif
19 18
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService() 75 MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService()
77 : web_data_service_request_(0) { 76 : web_data_service_request_(0) {
78 } 77 }
79 78
80 MutableProfileOAuth2TokenService::~MutableProfileOAuth2TokenService() { 79 MutableProfileOAuth2TokenService::~MutableProfileOAuth2TokenService() {
81 } 80 }
82 81
83 void MutableProfileOAuth2TokenService::Shutdown() { 82 void MutableProfileOAuth2TokenService::Shutdown() {
84 if (web_data_service_request_ != 0) { 83 if (web_data_service_request_ != 0) {
85 scoped_refptr<TokenWebData> token_web_data = 84 scoped_refptr<TokenWebData> token_web_data =
86 WebDataServiceFactory::GetTokenWebDataForProfile( 85 TokenWebData::FromBrowserContext(profile());
87 profile(), Profile::EXPLICIT_ACCESS);
88 DCHECK(token_web_data.get()); 86 DCHECK(token_web_data.get());
89 token_web_data->CancelRequest(web_data_service_request_); 87 token_web_data->CancelRequest(web_data_service_request_);
90 web_data_service_request_ = 0; 88 web_data_service_request_ = 0;
91 } 89 }
92 ProfileOAuth2TokenService::Shutdown(); 90 ProfileOAuth2TokenService::Shutdown();
93 } 91 }
94 92
95 net::URLRequestContextGetter* 93 net::URLRequestContextGetter*
96 MutableProfileOAuth2TokenService::GetRequestContext() { 94 MutableProfileOAuth2TokenService::GetRequestContext() {
97 return profile()->GetRequestContext(); 95 return profile()->GetRequestContext();
98 } 96 }
99 97
100 void MutableProfileOAuth2TokenService::LoadCredentials() { 98 void MutableProfileOAuth2TokenService::LoadCredentials() {
101 DCHECK_EQ(0, web_data_service_request_); 99 DCHECK_EQ(0, web_data_service_request_);
102 100
103 CancelAllRequests(); 101 CancelAllRequests();
104 refresh_tokens().clear(); 102 refresh_tokens().clear();
105 scoped_refptr<TokenWebData> token_web_data = 103 scoped_refptr<TokenWebData> token_web_data =
106 WebDataServiceFactory::GetTokenWebDataForProfile( 104 TokenWebData::FromBrowserContext(profile());
107 profile(), Profile::EXPLICIT_ACCESS);
108 if (token_web_data.get()) 105 if (token_web_data.get())
109 web_data_service_request_ = token_web_data->GetAllTokens(this); 106 web_data_service_request_ = token_web_data->GetAllTokens(this);
110 } 107 }
111 108
112 void MutableProfileOAuth2TokenService::OnWebDataServiceRequestDone( 109 void MutableProfileOAuth2TokenService::OnWebDataServiceRequestDone(
113 WebDataServiceBase::Handle handle, 110 WebDataServiceBase::Handle handle,
114 const WDTypedResult* result) { 111 const WDTypedResult* result) {
115 DCHECK_EQ(web_data_service_request_, handle); 112 DCHECK_EQ(web_data_service_request_, handle);
116 web_data_service_request_ = 0; 113 web_data_service_request_ = 0;
117 114
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 iter != db_tokens.end(); 149 iter != db_tokens.end();
153 ++iter) { 150 ++iter) {
154 std::string prefixed_account_id = iter->first; 151 std::string prefixed_account_id = iter->first;
155 std::string refresh_token = iter->second; 152 std::string refresh_token = iter->second;
156 153
157 if (IsLegacyRefreshTokenId(prefixed_account_id) && !refresh_token.empty()) 154 if (IsLegacyRefreshTokenId(prefixed_account_id) && !refresh_token.empty())
158 old_login_token = refresh_token; 155 old_login_token = refresh_token;
159 156
160 if (IsLegacyServiceId(prefixed_account_id)) { 157 if (IsLegacyServiceId(prefixed_account_id)) {
161 scoped_refptr<TokenWebData> token_web_data = 158 scoped_refptr<TokenWebData> token_web_data =
162 WebDataServiceFactory::GetTokenWebDataForProfile( 159 TokenWebData::FromBrowserContext(profile());
163 profile(), Profile::EXPLICIT_ACCESS);
164 if (token_web_data.get()) 160 if (token_web_data.get())
165 token_web_data->RemoveTokenForService(prefixed_account_id); 161 token_web_data->RemoveTokenForService(prefixed_account_id);
166 } else { 162 } else {
167 DCHECK(!refresh_token.empty()); 163 DCHECK(!refresh_token.empty());
168 std::string account_id = RemoveAccountIdPrefix(prefixed_account_id); 164 std::string account_id = RemoveAccountIdPrefix(prefixed_account_id);
169 refresh_tokens()[account_id].reset( 165 refresh_tokens()[account_id].reset(
170 new AccountInfo(this, account_id, refresh_token)); 166 new AccountInfo(this, account_id, refresh_token));
171 FireRefreshTokenAvailable(account_id); 167 FireRefreshTokenAvailable(account_id);
172 // TODO(fgorski): Notify diagnostic observers. 168 // TODO(fgorski): Notify diagnostic observers.
173 } 169 }
174 } 170 }
175 171
176 if (!old_login_token.empty()) { 172 if (!old_login_token.empty()) {
177 std::string account_id = GetAccountIdForMigratingRefreshToken(); 173 std::string account_id = GetAccountIdForMigratingRefreshToken();
178 174
179 if (refresh_tokens().count(account_id) == 0) 175 if (refresh_tokens().count(account_id) == 0)
180 UpdateCredentials(account_id, old_login_token); 176 UpdateCredentials(account_id, old_login_token);
181 } 177 }
182 178
183 FireRefreshTokensLoaded(); 179 FireRefreshTokensLoaded();
184 } 180 }
185 181
186 void MutableProfileOAuth2TokenService::PersistCredentials( 182 void MutableProfileOAuth2TokenService::PersistCredentials(
187 const std::string& account_id, 183 const std::string& account_id,
188 const std::string& refresh_token) { 184 const std::string& refresh_token) {
189 scoped_refptr<TokenWebData> token_web_data = 185 scoped_refptr<TokenWebData> token_web_data =
190 WebDataServiceFactory::GetTokenWebDataForProfile( 186 TokenWebData::FromBrowserContext(profile());
191 profile(), Profile::EXPLICIT_ACCESS);
192 if (token_web_data.get()) { 187 if (token_web_data.get()) {
193 token_web_data->SetTokenForService(ApplyAccountIdPrefix(account_id), 188 token_web_data->SetTokenForService(ApplyAccountIdPrefix(account_id),
194 refresh_token); 189 refresh_token);
195 } 190 }
196 } 191 }
197 192
198 void MutableProfileOAuth2TokenService::ClearPersistedCredentials( 193 void MutableProfileOAuth2TokenService::ClearPersistedCredentials(
199 const std::string& account_id) { 194 const std::string& account_id) {
200 scoped_refptr<TokenWebData> token_web_data = 195 scoped_refptr<TokenWebData> token_web_data =
201 WebDataServiceFactory::GetTokenWebDataForProfile( 196 TokenWebData::FromBrowserContext(profile());
202 profile(), Profile::EXPLICIT_ACCESS);
203 if (token_web_data.get()) 197 if (token_web_data.get())
204 token_web_data->RemoveTokenForService(ApplyAccountIdPrefix(account_id)); 198 token_web_data->RemoveTokenForService(ApplyAccountIdPrefix(account_id));
205 } 199 }
206 200
207 std::string 201 std::string
208 MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() { 202 MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() {
209 #if defined(ENABLE_MANAGED_USERS) 203 #if defined(ENABLE_MANAGED_USERS)
210 // TODO(bauerb): Make sure that only services that can deal with supervised 204 // TODO(bauerb): Make sure that only services that can deal with supervised
211 // users see the supervised user token. 205 // users see the supervised user token.
212 if (profile()->IsManaged()) 206 if (profile()->IsManaged())
213 return managed_users::kManagedUserPseudoEmail; 207 return managed_users::kManagedUserPseudoEmail;
214 #endif 208 #endif
215 209
216 return GetPrimaryAccountId(); 210 return GetPrimaryAccountId();
217 } 211 }
218 212
219 void MutableProfileOAuth2TokenService::RevokeCredentialsOnServer( 213 void MutableProfileOAuth2TokenService::RevokeCredentialsOnServer(
220 const std::string& refresh_token) { 214 const std::string& refresh_token) {
221 // RevokeServerRefreshToken deletes itself when done. 215 // RevokeServerRefreshToken deletes itself when done.
222 new RevokeServerRefreshToken(refresh_token, GetRequestContext()); 216 new RevokeServerRefreshToken(refresh_token, GetRequestContext());
223 } 217 }
OLDNEW
« no previous file with comments | « chrome/browser/DEPS ('k') | chrome/browser/signin/mutable_profile_oauth2_token_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698