1 // Copyright 2015 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 CHROME_BROWSER_SIGNIN_FAKE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
6 #define CHROME_BROWSER_SIGNIN_FAKE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
8 #include "base/memory/linked_ptr.h"
9 #include "google_apis/gaia/google_service_auth_error.h"
10 #include "google_apis/gaia/oauth2_token_service_delegate.h"
11 #include "net/url_request/url_request_context_getter.h"
13 class FakeOAuth2TokenServiceDelegate
: public OAuth2TokenServiceDelegate
{
15 FakeOAuth2TokenServiceDelegate(net::URLRequestContextGetter
* request_context
);
16 ~FakeOAuth2TokenServiceDelegate() override
;
18 OAuth2AccessTokenFetcher
* CreateAccessTokenFetcher(
19 const std::string
& account_id
,
20 net::URLRequestContextGetter
* getter
,
21 OAuth2AccessTokenConsumer
* consumer
) override
;
23 // Overriden to make sure it works on Android.
24 bool RefreshTokenIsAvailable(const std::string
& account_id
) const override
;
25 bool RefreshTokenHasError(const std::string
& account_id
) const override
;
27 std::vector
<std::string
> GetAccounts() override
;
28 void RevokeAllCredentials() override
;
30 void LoadCredentials(const std::string
& primary_account_id
) override
;
32 void UpdateCredentials(const std::string
& account_id
,
33 const std::string
& refresh_token
) override
;
34 void RevokeCredentials(const std::string
& account_id
) override
;
36 net::URLRequestContextGetter
* GetRequestContext() const override
;
38 void set_request_context(net::URLRequestContextGetter
* request_context
) {
39 request_context_
= request_context
;
42 void SetLastErrorForAccount(const std::string
& account_id
,
43 const GoogleServiceAuthError
& error
);
47 AccountInfo(const std::string
& refresh_token
);
49 const std::string refresh_token
;
50 GoogleServiceAuthError error
;
53 void IssueRefreshTokenForUser(const std::string
& account_id
,
54 const std::string
& token
);
55 std::string
GetRefreshToken(const std::string
& account_id
) const;
57 // Maps account ids to info.
58 typedef std::map
<std::string
, linked_ptr
<AccountInfo
>> AccountInfoMap
;
59 AccountInfoMap refresh_tokens_
;
61 scoped_refptr
<net::URLRequestContextGetter
> request_context_
;
63 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenServiceDelegate
);