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