| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gaia/fake_oauth2_token_service.h" | 5 #include "google_apis/gaia/fake_oauth2_token_service.h" |
| 6 | 6 |
| 7 FakeOAuth2TokenService::PendingRequest::PendingRequest() { | 7 FakeOAuth2TokenService::PendingRequest::PendingRequest() { |
| 8 } | 8 } |
| 9 | 9 |
| 10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() { | 10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) { | 60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) { |
| 61 account_ids_.erase(account_id); | 61 account_ids_.erase(account_id); |
| 62 FireRefreshTokenRevoked(account_id); | 62 FireRefreshTokenRevoked(account_id); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void FakeOAuth2TokenService::IssueAllTokensForAccount( | 65 void FakeOAuth2TokenService::IssueAllTokensForAccount( |
| 66 const std::string& account_id, | 66 const std::string& account_id, |
| 67 const std::string& access_token, | 67 const std::string& access_token, |
| 68 const base::Time& expiration) { | 68 const base::Time& expiration) { |
| 69 | |
| 70 // Walk the requests and notify the callbacks. | 69 // Walk the requests and notify the callbacks. |
| 71 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 70 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
| 72 it != pending_requests_.end(); ++it) { | 71 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
| 72 it != pending_requests_copy.end(); |
| 73 ++it) { |
| 73 if (it->request && (account_id == it->account_id)) { | 74 if (it->request && (account_id == it->account_id)) { |
| 74 it->request->InformConsumer( | 75 it->request->InformConsumer( |
| 75 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration); | 76 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount( | 81 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount( |
| 81 const std::string& account_id, | 82 const std::string& account_id, |
| 82 const GoogleServiceAuthError& auth_error) { | 83 const GoogleServiceAuthError& auth_error) { |
| 83 // Walk the requests and notify the callbacks. | 84 // Walk the requests and notify the callbacks. |
| 84 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 85 // Using a copy to make sure retyring a request does not cause a stack when |
| 85 it != pending_requests_.end(); | 86 // incrementing the iterator. |
| 87 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
| 88 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
| 89 it != pending_requests_copy.end(); |
| 86 ++it) { | 90 ++it) { |
| 87 if (it->request && (account_id == it->account_id)) { | 91 if (it->request && (account_id == it->account_id)) { |
| 88 it->request->InformConsumer(auth_error, std::string(), base::Time()); | 92 it->request->InformConsumer(auth_error, std::string(), base::Time()); |
| 89 } | 93 } |
| 90 } | 94 } |
| 91 } | 95 } |
| 92 | 96 |
| 93 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( | 97 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( |
| 94 const std::string& account_id, | 98 const std::string& account_id, |
| 95 net::URLRequestContextGetter* getter, | 99 net::URLRequestContextGetter* getter, |
| 96 OAuth2AccessTokenConsumer* consumer) { | 100 OAuth2AccessTokenConsumer* consumer) { |
| 97 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus | 101 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus |
| 98 // |CreateAccessTokenFetcher| should never be called. | 102 // |CreateAccessTokenFetcher| should never be called. |
| 99 NOTREACHED(); | 103 NOTREACHED(); |
| 100 return NULL; | 104 return NULL; |
| 101 } | 105 } |
| OLD | NEW |