Adds thunks for getting platform handles
[chromium-blink-merge.git] / google_apis / gaia / fake_oauth2_token_service.h
blobffe7b6abb31e58ba3ea21b61fd3526b6b5c4a60b
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 ~FakeOAuth2TokenService() override;
25 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
31 // error.
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;
43 protected:
44 // OAuth2TokenService overrides.
45 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 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 bool RefreshTokenIsAvailable(const std::string& account_id) const override;
59 private:
60 struct PendingRequest {
61 PendingRequest();
62 ~PendingRequest();
64 std::string account_id;
65 std::string client_id;
66 std::string client_secret;
67 ScopeSet scopes;
68 base::WeakPtr<RequestImpl> request;
71 // OAuth2TokenService overrides.
72 net::URLRequestContextGetter* GetRequestContext() override;
74 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
75 const std::string& account_id,
76 net::URLRequestContextGetter* getter,
77 OAuth2AccessTokenConsumer* consumer) override;
79 std::set<std::string> account_ids_;
80 std::vector<PendingRequest> pending_requests_;
82 net::URLRequestContextGetter* request_context_; // weak
84 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService);
87 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_