When enabling new profile management programmatically, make sure to set the
[chromium-blink-merge.git] / google_apis / gaia / fake_oauth2_token_service.h
blob3bdb67500a96739511fca9a4375f95237c4db699
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_
8 #include <set>
9 #include <string>
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
15 namespace net {
16 class URLRequestContextGetter;
19 // Do-nothing implementation of OAuth2TokenService.
20 class FakeOAuth2TokenService : public OAuth2TokenService {
21 public:
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.
31 void IssueAllTokensForAccount(const std::string& account_id,
32 const std::string& access_token,
33 const base::Time& expiration);
35 void set_request_context(net::URLRequestContextGetter* request_context) {
36 request_context_ = request_context;
39 protected:
40 // OAuth2TokenService overrides.
41 virtual void FetchOAuth2Token(RequestImpl* request,
42 const std::string& account_id,
43 net::URLRequestContextGetter* getter,
44 const std::string& client_id,
45 const std::string& client_secret,
46 const ScopeSet& scopes) OVERRIDE;
48 virtual void InvalidateOAuth2Token(const std::string& account_id,
49 const std::string& client_id,
50 const ScopeSet& scopes,
51 const std::string& access_token) OVERRIDE;
53 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const
54 OVERRIDE;
56 private:
57 struct PendingRequest {
58 PendingRequest();
59 ~PendingRequest();
61 std::string account_id;
62 std::string client_id;
63 std::string client_secret;
64 ScopeSet scopes;
65 base::WeakPtr<RequestImpl> request;
68 // OAuth2TokenService overrides.
69 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
71 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
72 const std::string& account_id,
73 net::URLRequestContextGetter* getter,
74 OAuth2AccessTokenConsumer* consumer) OVERRIDE;
76 std::set<std::string> account_ids_;
77 std::vector<PendingRequest> pending_requests_;
79 net::URLRequestContextGetter* request_context_; // weak
81 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService);
84 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_