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

Unified Diff: chrome/browser/signin/oauth2_token_service.cc

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/signin/oauth2_token_service.h ('k') | chrome/browser/signin/profile_oauth2_token_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/signin/oauth2_token_service.cc
diff --git a/chrome/browser/signin/oauth2_token_service.cc b/chrome/browser/signin/oauth2_token_service.cc
index 18912441d1211176b833b3995b64f582e4af4ad3..1773871d8a739b911baa5f1cbbe27215f98d1b5c 100644
--- a/chrome/browser/signin/oauth2_token_service.cc
+++ b/chrome/browser/signin/oauth2_token_service.cc
@@ -315,7 +315,6 @@ OAuth2TokenService::OAuth2TokenService() {
}
OAuth2TokenService::~OAuth2TokenService() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// Release all the pending fetchers.
STLDeleteContainerPairSecondPointers(
pending_fetchers_.begin(), pending_fetchers_.end());
@@ -330,7 +329,6 @@ void OAuth2TokenService::RemoveObserver(Observer* observer) {
}
bool OAuth2TokenService::RefreshTokenIsAvailable() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
return !GetRefreshToken().empty();
}
@@ -383,20 +381,34 @@ OAuth2TokenService::StartRequestForClientWithContext(
scoped_ptr<RequestImpl> request(new RequestImpl(consumer));
- std::string refresh_token = GetRefreshToken();
- if (refresh_token.empty()) {
+ if (!RefreshTokenIsAvailable()) {
base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
&RequestImpl::InformConsumer,
request->AsWeakPtr(),
- GoogleServiceAuthError(
- GoogleServiceAuthError::USER_NOT_SIGNED_UP),
+ GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP),
std::string(),
base::Time()));
return request.PassAs<Request>();
}
- if (HasCacheEntry(scopes))
- return StartCacheLookupRequest(scopes, consumer);
+ if (HasCacheEntry(scopes)) {
+ StartCacheLookupRequest(request.get(), scopes, consumer);
+ } else {
+ FetchOAuth2Token(request.get(),
+ getter,
+ client_id,
+ client_secret,
+ scopes);
+ }
+ return request.PassAs<Request>();
+}
+
+void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request,
+ net::URLRequestContextGetter* getter,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const ScopeSet& scopes) {
+ std::string refresh_token = GetRefreshToken();
// If there is already a pending fetcher for |scopes| and |refresh_token|,
// simply register this |request| for those results rather than starting
@@ -406,7 +418,7 @@ OAuth2TokenService::StartRequestForClientWithContext(
pending_fetchers_.find(fetch_parameters);
if (iter != pending_fetchers_.end()) {
iter->second->AddWaitingRequest(request->AsWeakPtr());
- return request.PassAs<Request>();
+ return;
}
pending_fetchers_[fetch_parameters] =
@@ -417,23 +429,20 @@ OAuth2TokenService::StartRequestForClientWithContext(
refresh_token,
scopes,
request->AsWeakPtr());
- return request.PassAs<Request>();
}
-scoped_ptr<OAuth2TokenService::Request>
- OAuth2TokenService::StartCacheLookupRequest(
- const OAuth2TokenService::ScopeSet& scopes,
- OAuth2TokenService::Consumer* consumer) {
+void OAuth2TokenService::StartCacheLookupRequest(
+ RequestImpl* request,
+ const OAuth2TokenService::ScopeSet& scopes,
+ OAuth2TokenService::Consumer* consumer) {
CHECK(HasCacheEntry(scopes));
const CacheEntry* cache_entry = GetCacheEntry(scopes);
- scoped_ptr<RequestImpl> request(new RequestImpl(consumer));
base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
&RequestImpl::InformConsumer,
request->AsWeakPtr(),
GoogleServiceAuthError(GoogleServiceAuthError::NONE),
cache_entry->access_token,
cache_entry->expiration_date));
- return request.PassAs<Request>();
}
void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes,
« no previous file with comments | « chrome/browser/signin/oauth2_token_service.h ('k') | chrome/browser/signin/profile_oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698