| 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 // Using a copy of pending requests to make sure a new token request triggered |
| 72 it != pending_requests_.end(); ++it) { | 71 // from the handling code does not invalidate the iterator. |
| 72 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
| 73 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
| 74 it != pending_requests_copy.end(); |
| 75 ++it) { |
| 73 if (it->request && (account_id == it->account_id)) { | 76 if (it->request && (account_id == it->account_id)) { |
| 74 it->request->InformConsumer( | 77 it->request->InformConsumer( |
| 75 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration); | 78 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration); |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 80 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount( | 83 void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount( |
| 81 const std::string& account_id, | 84 const std::string& account_id, |
| 82 const GoogleServiceAuthError& auth_error) { | 85 const GoogleServiceAuthError& auth_error) { |
| 83 // Walk the requests and notify the callbacks. | 86 // Walk the requests and notify the callbacks. |
| 84 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 87 // Using a copy of pending requests to make sure retrying a request in |
| 85 it != pending_requests_.end(); | 88 // response to the error does not invalidate the iterator. |
| 89 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
| 90 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
| 91 it != pending_requests_copy.end(); |
| 86 ++it) { | 92 ++it) { |
| 87 if (it->request && (account_id == it->account_id)) { | 93 if (it->request && (account_id == it->account_id)) { |
| 88 it->request->InformConsumer(auth_error, std::string(), base::Time()); | 94 it->request->InformConsumer(auth_error, std::string(), base::Time()); |
| 89 } | 95 } |
| 90 } | 96 } |
| 91 } | 97 } |
| 92 | 98 |
| 93 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( | 99 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( |
| 94 const std::string& account_id, | 100 const std::string& account_id, |
| 95 net::URLRequestContextGetter* getter, | 101 net::URLRequestContextGetter* getter, |
| 96 OAuth2AccessTokenConsumer* consumer) { | 102 OAuth2AccessTokenConsumer* consumer) { |
| 97 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus | 103 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus |
| 98 // |CreateAccessTokenFetcher| should never be called. | 104 // |CreateAccessTokenFetcher| should never be called. |
| 99 NOTREACHED(); | 105 NOTREACHED(); |
| 100 return NULL; | 106 return NULL; |
| 101 } | 107 } |
| OLD | NEW |