Roll BoringSSL.
[chromium-blink-merge.git] / google_apis / gaia / fake_oauth2_token_service.cc
blob44722dd2dd3618ec9c22f3422c3d6abe01ef31cd
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 #include "google_apis/gaia/fake_oauth2_token_service.h"
7 FakeOAuth2TokenService::PendingRequest::PendingRequest() {
10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() {
13 FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) {
16 FakeOAuth2TokenService::~FakeOAuth2TokenService() {
19 std::vector<std::string> FakeOAuth2TokenService::GetAccounts() {
20 return std::vector<std::string>(account_ids_.begin(), account_ids_.end());
23 void FakeOAuth2TokenService::FetchOAuth2Token(
24 RequestImpl* request,
25 const std::string& account_id,
26 net::URLRequestContextGetter* getter,
27 const std::string& client_id,
28 const std::string& client_secret,
29 const ScopeSet& scopes) {
30 PendingRequest pending_request;
31 pending_request.account_id = account_id;
32 pending_request.client_id = client_id;
33 pending_request.client_secret = client_secret;
34 pending_request.scopes = scopes;
35 pending_request.request = request->AsWeakPtr();
36 pending_requests_.push_back(pending_request);
39 void FakeOAuth2TokenService::InvalidateOAuth2Token(
40 const std::string& account_id,
41 const std::string& client_id,
42 const ScopeSet& scopes,
43 const std::string& access_token) {
46 net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() {
47 return request_context_;
50 bool FakeOAuth2TokenService::RefreshTokenIsAvailable(
51 const std::string& account_id) const {
52 return account_ids_.count(account_id) != 0;
55 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) {
56 account_ids_.insert(account_id);
57 FireRefreshTokenAvailable(account_id);
60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) {
61 account_ids_.erase(account_id);
62 FireRefreshTokenRevoked(account_id);
65 void FakeOAuth2TokenService::IssueAllTokensForAccount(
66 const std::string& account_id,
67 const std::string& access_token,
68 const base::Time& expiration) {
70 // Walk the requests and notify the callbacks.
71 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
72 it != pending_requests_.end(); ++it) {
73 if (it->request && (account_id == it->account_id)) {
74 it->request->InformConsumer(
75 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration);
80 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount(
81 const std::string& account_id,
82 const GoogleServiceAuthError& auth_error) {
83 // Walk the requests and notify the callbacks.
84 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
85 it != pending_requests_.end();
86 ++it) {
87 if (it->request && (account_id == it->account_id)) {
88 it->request->InformConsumer(auth_error, std::string(), base::Time());
93 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher(
94 const std::string& account_id,
95 net::URLRequestContextGetter* getter,
96 OAuth2AccessTokenConsumer* consumer) {
97 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus
98 // |CreateAccessTokenFetcher| should never be called.
99 NOTREACHED();
100 return NULL;