• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
PendingRequest()7 FakeOAuth2TokenService::PendingRequest::PendingRequest() {
8 }
9 
~PendingRequest()10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() {
11 }
12 
FakeOAuth2TokenService()13 FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) {
14 }
15 
~FakeOAuth2TokenService()16 FakeOAuth2TokenService::~FakeOAuth2TokenService() {
17 }
18 
GetAccounts()19 std::vector<std::string> FakeOAuth2TokenService::GetAccounts() {
20   return std::vector<std::string>(account_ids_.begin(), account_ids_.end());
21 }
22 
FetchOAuth2Token(RequestImpl * request,const std::string & account_id,net::URLRequestContextGetter * getter,const std::string & client_id,const std::string & client_secret,const ScopeSet & scopes)23 void 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 
InvalidateOAuth2Token(const std::string & account_id,const std::string & client_id,const ScopeSet & scopes,const std::string & access_token)39 void 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 
GetRequestContext()46 net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() {
47   return request_context_;
48 }
49 
RefreshTokenIsAvailable(const std::string & account_id) const50 bool FakeOAuth2TokenService::RefreshTokenIsAvailable(
51     const std::string& account_id) const {
52   return account_ids_.count(account_id) != 0;
53 };
54 
AddAccount(const std::string & account_id)55 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) {
56   account_ids_.insert(account_id);
57   FireRefreshTokenAvailable(account_id);
58 }
59 
RemoveAccount(const std::string & account_id)60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) {
61   account_ids_.erase(account_id);
62   FireRefreshTokenRevoked(account_id);
63 }
64 
IssueAllTokensForAccount(const std::string & account_id,const std::string & access_token,const base::Time & expiration)65 void 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 
IssueErrorForAllPendingRequestsForAccount(const std::string & account_id,const GoogleServiceAuthError & auth_error)80 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount(
81     const std::string& account_id,
82     const GoogleServiceAuthError& auth_error) {
83   // Walk the requests and notify the callbacks.
84   for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
85        it != pending_requests_.end();
86        ++it) {
87     if (it->request && (account_id == it->account_id)) {
88       it->request->InformConsumer(auth_error, std::string(), base::Time());
89     }
90   }
91 }
92 
CreateAccessTokenFetcher(const std::string & account_id,net::URLRequestContextGetter * getter,OAuth2AccessTokenConsumer * consumer)93 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher(
94     const std::string& account_id,
95     net::URLRequestContextGetter* getter,
96     OAuth2AccessTokenConsumer* consumer) {
97   // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus
98   // |CreateAccessTokenFetcher| should never be called.
99   NOTREACHED();
100   return NULL;
101 }
102