Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: google_apis/gaia/fake_oauth2_token_service.cc

Issue 618003002: [GCM] Handling connection events in GCMAccountTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the test failing on a mac Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gaia/fake_oauth2_token_service.cc
diff --git a/google_apis/gaia/fake_oauth2_token_service.cc b/google_apis/gaia/fake_oauth2_token_service.cc
index 44722dd2dd3618ec9c22f3422c3d6abe01ef31cd..adff32d321986d259f5ca8e6a361dcc80bf5a134 100644
--- a/google_apis/gaia/fake_oauth2_token_service.cc
+++ b/google_apis/gaia/fake_oauth2_token_service.cc
@@ -66,10 +66,13 @@ void FakeOAuth2TokenService::IssueAllTokensForAccount(
const std::string& account_id,
const std::string& access_token,
const base::Time& expiration) {
-
// Walk the requests and notify the callbacks.
- for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
- it != pending_requests_.end(); ++it) {
+ // Using a copy of pending requests to make sure a new token request triggered
+ // from the handling code does not invalidate the iterator.
+ std::vector<PendingRequest> pending_requests_copy = pending_requests_;
+ for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin();
+ it != pending_requests_copy.end();
+ ++it) {
if (it->request && (account_id == it->account_id)) {
it->request->InformConsumer(
GoogleServiceAuthError::AuthErrorNone(), access_token, expiration);
@@ -81,8 +84,11 @@ void FakeOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount(
const std::string& account_id,
const GoogleServiceAuthError& auth_error) {
// Walk the requests and notify the callbacks.
- for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
- it != pending_requests_.end();
+ // Using a copy of pending requests to make sure retrying a request in
+ // response to the error does not invalidate the iterator.
+ std::vector<PendingRequest> pending_requests_copy = pending_requests_;
+ for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin();
+ it != pending_requests_copy.end();
++it) {
if (it->request && (account_id == it->account_id)) {
it->request->InformConsumer(auth_error, std::string(), base::Time());
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698