1// Copyright 2014 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 "google_apis/gaia/fake_oauth2_token_service.h" 6 7FakeOAuth2TokenService::PendingRequest::PendingRequest() { 8} 9 10FakeOAuth2TokenService::PendingRequest::~PendingRequest() { 11} 12 13FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) { 14} 15 16FakeOAuth2TokenService::~FakeOAuth2TokenService() { 17} 18 19std::vector<std::string> FakeOAuth2TokenService::GetAccounts() { 20 return std::vector<std::string>(account_ids_.begin(), account_ids_.end()); 21} 22 23void FakeOAuth2TokenService::FetchOAuth2Token( 24 RequestImpl* request, 25 const std::string& account_id, 26 net::URLRequestContextGetter* getter, 27 const std::string& client_id, 28 const std::string& client_secret, 29 const ScopeSet& scopes) { 30 PendingRequest pending_request; 31 pending_request.account_id = account_id; 32 pending_request.client_id = client_id; 33 pending_request.client_secret = client_secret; 34 pending_request.scopes = scopes; 35 pending_request.request = request->AsWeakPtr(); 36 pending_requests_.push_back(pending_request); 37} 38 39void FakeOAuth2TokenService::InvalidateOAuth2Token( 40 const std::string& account_id, 41 const std::string& client_id, 42 const ScopeSet& scopes, 43 const std::string& access_token) { 44} 45 46net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() { 47 return request_context_; 48} 49 50bool FakeOAuth2TokenService::RefreshTokenIsAvailable( 51 const std::string& account_id) const { 52 return account_ids_.count(account_id) != 0; 53}; 54 55void FakeOAuth2TokenService::AddAccount(const std::string& account_id) { 56 account_ids_.insert(account_id); 57 FireRefreshTokenAvailable(account_id); 58} 59 60void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) { 61 account_ids_.erase(account_id); 62 FireRefreshTokenRevoked(account_id); 63} 64 65void FakeOAuth2TokenService::IssueAllTokensForAccount( 66 const std::string& account_id, 67 const std::string& access_token, 68 const base::Time& expiration) { 69 70 // Walk the requests and notify the callbacks. 71 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); 72 it != pending_requests_.end(); ++it) { 73 if (it->request && (account_id == it->account_id)) { 74 it->request->InformConsumer( 75 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration); 76 } 77 } 78} 79 80 81OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( 82 const std::string& account_id, 83 net::URLRequestContextGetter* getter, 84 OAuth2AccessTokenConsumer* consumer) { 85 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus 86 // |CreateAccessTokenFetcher| should never be called. 87 NOTREACHED(); 88 return NULL; 89} 90