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.
5 #ifndef GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_
6 #define GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
16 class URLRequestContextGetter
;
19 // Do-nothing implementation of OAuth2TokenService.
20 class FakeOAuth2TokenService
: public OAuth2TokenService
{
22 FakeOAuth2TokenService();
23 virtual ~FakeOAuth2TokenService();
25 virtual std::vector
<std::string
> GetAccounts() OVERRIDE
;
27 void AddAccount(const std::string
& account_id
);
28 void RemoveAccount(const std::string
& account_id
);
30 // Helper routines to issue tokens for pending requests or complete them with
32 void IssueAllTokensForAccount(const std::string
& account_id
,
33 const std::string
& access_token
,
34 const base::Time
& expiration
);
35 void IssueErrorForAllPendingRequestsForAccount(
36 const std::string
& account_id
,
37 const GoogleServiceAuthError
& auth_error
);
39 void set_request_context(net::URLRequestContextGetter
* request_context
) {
40 request_context_
= request_context
;
44 // OAuth2TokenService overrides.
45 virtual void FetchOAuth2Token(RequestImpl
* request
,
46 const std::string
& account_id
,
47 net::URLRequestContextGetter
* getter
,
48 const std::string
& client_id
,
49 const std::string
& client_secret
,
50 const ScopeSet
& scopes
) OVERRIDE
;
52 virtual void InvalidateOAuth2Token(const std::string
& account_id
,
53 const std::string
& client_id
,
54 const ScopeSet
& scopes
,
55 const std::string
& access_token
) OVERRIDE
;
57 virtual bool RefreshTokenIsAvailable(const std::string
& account_id
) const
61 struct PendingRequest
{
65 std::string account_id
;
66 std::string client_id
;
67 std::string client_secret
;
69 base::WeakPtr
<RequestImpl
> request
;
72 // OAuth2TokenService overrides.
73 virtual net::URLRequestContextGetter
* GetRequestContext() OVERRIDE
;
75 virtual OAuth2AccessTokenFetcher
* CreateAccessTokenFetcher(
76 const std::string
& account_id
,
77 net::URLRequestContextGetter
* getter
,
78 OAuth2AccessTokenConsumer
* consumer
) OVERRIDE
;
80 std::set
<std::string
> account_ids_
;
81 std::vector
<PendingRequest
> pending_requests_
;
83 net::URLRequestContextGetter
* request_context_
; // weak
85 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService
);
88 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_