[chromedriver] Don't evaluate document.readyState if we already know it is loading.
[chromium-blink-merge.git] / google_apis / gaia / fake_oauth2_token_service.cc
blob55b5cd58a1e5fabf05f79b8114995d4054a844d2
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()
14 : OAuth2TokenService(new FakeOAuth2TokenServiceDelegate(nullptr)) {
17 FakeOAuth2TokenService::~FakeOAuth2TokenService() {
20 void FakeOAuth2TokenService::FetchOAuth2Token(
21 RequestImpl* request,
22 const std::string& account_id,
23 net::URLRequestContextGetter* getter,
24 const std::string& client_id,
25 const std::string& client_secret,
26 const ScopeSet& scopes) {
27 PendingRequest pending_request;
28 pending_request.account_id = account_id;
29 pending_request.client_id = client_id;
30 pending_request.client_secret = client_secret;
31 pending_request.scopes = scopes;
32 pending_request.request = request->AsWeakPtr();
33 pending_requests_.push_back(pending_request);
36 void FakeOAuth2TokenService::InvalidateAccessTokenImpl(
37 const std::string& account_id,
38 const std::string& client_id,
39 const ScopeSet& scopes,
40 const std::string& access_token) {
43 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) {
44 GetDelegate()->UpdateCredentials(account_id, "fake_refresh_token");
47 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) {
48 GetDelegate()->RevokeCredentials(account_id);
51 void FakeOAuth2TokenService::IssueAllTokensForAccount(
52 const std::string& account_id,
53 const std::string& access_token,
54 const base::Time& expiration) {
55 // Walk the requests and notify the callbacks.
56 // Using a copy of pending requests to make sure a new token request triggered
57 // from the handling code does not invalidate the iterator.
58 std::vector<PendingRequest> pending_requests_copy = pending_requests_;
59 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin();
60 it != pending_requests_copy.end();
61 ++it) {
62 if (it->request && (account_id == it->account_id)) {
63 it->request->InformConsumer(
64 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration);
69 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount(
70 const std::string& account_id,
71 const GoogleServiceAuthError& auth_error) {
72 // Walk the requests and notify the callbacks.
73 // Using a copy of pending requests to make sure retrying a request in
74 // response to the error does not invalidate the iterator.
75 std::vector<PendingRequest> pending_requests_copy = pending_requests_;
76 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin();
77 it != pending_requests_copy.end();
78 ++it) {
79 if (it->request && (account_id == it->account_id)) {
80 it->request->InformConsumer(auth_error, std::string(), base::Time());
85 FakeOAuth2TokenServiceDelegate*
86 FakeOAuth2TokenService::GetFakeOAuth2TokenServiceDelegate() {
87 return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate());