android_profile_oauth2_token_service.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 3// found in the LICENSE file. 4 5#include "chrome/browser/signin/android_profile_oauth2_token_service.h" 6 7#include "base/bind.h" 8#include "chrome/browser/sync/profile_sync_service_android.h" 9#include "content/public/browser/browser_thread.h" 10#include "net/url_request/url_request_context_getter.h" 11 12AndroidProfileOAuth2TokenService::AndroidProfileOAuth2TokenService( 13 net::URLRequestContextGetter* getter) 14 : ProfileOAuth2TokenService(getter) { 15} 16 17AndroidProfileOAuth2TokenService::~AndroidProfileOAuth2TokenService() { 18} 19 20scoped_ptr<OAuth2TokenService::Request> 21 AndroidProfileOAuth2TokenService::StartRequest( 22 const OAuth2TokenService::ScopeSet& scopes, 23 OAuth2TokenService::Consumer* consumer) { 24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 25 26 if (HasCacheEntry(scopes)) 27 return StartCacheLookupRequest(scopes, consumer); 28 29 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); 30 DCHECK_EQ(scopes.size(), 1U); 31 std::vector<std::string> scope_list(scopes.begin(), scopes.end()); 32 ProfileSyncServiceAndroid* sync_service = 33 ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid(); 34 sync_service->FetchOAuth2Token( 35 scope_list.front(), 36 base::Bind(&OAuth2TokenService::InformConsumer, 37 request->AsWeakPtr())); 38 return request.PassAs<Request>(); 39} 40 41void AndroidProfileOAuth2TokenService::InvalidateToken( 42 const ScopeSet& scopes, 43 const std::string& invalid_token) { 44 OAuth2TokenService::InvalidateToken(scopes, invalid_token); 45 46 DCHECK_EQ(scopes.size(), 1U); 47 std::vector<std::string> scope_list(scopes.begin(), scopes.end()); 48 ProfileSyncServiceAndroid* sync_service = 49 ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid(); 50 sync_service->InvalidateOAuth2Token( 51 scope_list.front(), 52 invalid_token); 53} 54 55bool AndroidProfileOAuth2TokenService::ShouldCacheForRefreshToken( 56 TokenService *token_service, 57 const std::string& refresh_token) { 58 // The parent class skips caching if the TokenService login token is stale, 59 // but on Android the user is always logged in to exactly one profile, so 60 // this concept doesn't exist and we can simply always cache. 61 return true; 62} 63