forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_oauth2_token_service_delegate.h
65 lines (48 loc) · 2.36 KB
/
fake_oauth2_token_service_delegate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_FAKE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
#define CHROME_BROWSER_SIGNIN_FAKE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
#include "base/memory/linked_ptr.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "net/url_request/url_request_context_getter.h"
class FakeOAuth2TokenServiceDelegate : public OAuth2TokenServiceDelegate {
public:
FakeOAuth2TokenServiceDelegate(net::URLRequestContextGetter* request_context);
~FakeOAuth2TokenServiceDelegate() override;
OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
const std::string& account_id,
net::URLRequestContextGetter* getter,
OAuth2AccessTokenConsumer* consumer) override;
// Overriden to make sure it works on Android.
bool RefreshTokenIsAvailable(const std::string& account_id) const override;
bool RefreshTokenHasError(const std::string& account_id) const override;
std::vector<std::string> GetAccounts() override;
void RevokeAllCredentials() override;
void LoadCredentials(const std::string& primary_account_id) override;
void UpdateCredentials(const std::string& account_id,
const std::string& refresh_token) override;
void RevokeCredentials(const std::string& account_id) override;
net::URLRequestContextGetter* GetRequestContext() const override;
void set_request_context(net::URLRequestContextGetter* request_context) {
request_context_ = request_context;
}
void SetLastErrorForAccount(const std::string& account_id,
const GoogleServiceAuthError& error);
private:
struct AccountInfo {
AccountInfo(const std::string& refresh_token);
const std::string refresh_token;
GoogleServiceAuthError error;
};
void IssueRefreshTokenForUser(const std::string& account_id,
const std::string& token);
std::string GetRefreshToken(const std::string& account_id) const;
// Maps account ids to info.
typedef std::map<std::string, linked_ptr<AccountInfo>> AccountInfoMap;
AccountInfoMap refresh_tokens_;
scoped_refptr<net::URLRequestContextGetter> request_context_;
DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenServiceDelegate);
};
#endif