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#ifndef GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ 6#define GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ 7 8#include <set> 9#include <string> 10 11#include "base/compiler_specific.h" 12#include "base/memory/weak_ptr.h" 13#include "google_apis/gaia/oauth2_token_service.h" 14 15namespace net { 16class URLRequestContextGetter; 17} 18 19// Do-nothing implementation of OAuth2TokenService. 20class FakeOAuth2TokenService : public OAuth2TokenService { 21 public: 22 FakeOAuth2TokenService(); 23 virtual ~FakeOAuth2TokenService(); 24 25 virtual std::vector<std::string> GetAccounts() OVERRIDE; 26 27 void AddAccount(const std::string& account_id); 28 void RemoveAccount(const std::string& account_id); 29 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); 34 35 void set_request_context(net::URLRequestContextGetter* request_context) { 36 request_context_ = request_context; 37 } 38 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; 47 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; 52 53 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const 54 OVERRIDE; 55 56 private: 57 struct PendingRequest { 58 PendingRequest(); 59 ~PendingRequest(); 60 61 std::string account_id; 62 std::string client_id; 63 std::string client_secret; 64 ScopeSet scopes; 65 base::WeakPtr<RequestImpl> request; 66 }; 67 68 // OAuth2TokenService overrides. 69 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; 70 71 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( 72 const std::string& account_id, 73 net::URLRequestContextGetter* getter, 74 OAuth2AccessTokenConsumer* consumer) OVERRIDE; 75 76 std::set<std::string> account_ids_; 77 std::vector<PendingRequest> pending_requests_; 78 79 net::URLRequestContextGetter* request_context_; // weak 80 81 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); 82}; 83 84#endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ 85