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 "components/signin/core/browser/gaia_cookie_manager_service.h" | 5 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "components/signin/core/browser/signin_metrics.h" | 16 #include "components/signin/core/browser/signin_metrics.h" |
17 #include "google_apis/gaia/gaia_auth_fetcher.h" | 17 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" |
18 #include "google_apis/gaia/gaia_constants.h" | 19 #include "google_apis/gaia/gaia_constants.h" |
19 #include "google_apis/gaia/gaia_urls.h" | 20 #include "google_apis/gaia/gaia_urls.h" |
20 #include "google_apis/gaia/oauth2_token_service.h" | 21 #include "google_apis/gaia/oauth2_token_service.h" |
21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
22 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
23 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
24 #include "net/url_request/url_fetcher_delegate.h" | 25 #include "net/url_request/url_fetcher_delegate.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 ADD_ACCOUNT, | 66 ADD_ACCOUNT, |
66 LOG_OUT_ALL_ACCOUNTS, | 67 LOG_OUT_ALL_ACCOUNTS, |
67 LOG_OUT_ONE_ACCOUNT, | 68 LOG_OUT_ONE_ACCOUNT, |
68 LIST_ACCOUNTS | 69 LIST_ACCOUNTS |
69 }; | 70 }; |
70 | 71 |
71 } // namespace | 72 } // namespace |
72 | 73 |
73 GaiaCookieManagerService::GaiaCookieRequest::GaiaCookieRequest( | 74 GaiaCookieManagerService::GaiaCookieRequest::GaiaCookieRequest( |
74 GaiaCookieRequestType request_type, | 75 GaiaCookieRequestType request_type, |
75 const std::string& account_id, | 76 const std::string& account_id) |
76 const GaiaCookieManagerService::ListAccountsCallback& | |
77 list_accounts_callback) | |
78 : request_type_(request_type), | 77 : request_type_(request_type), |
79 account_id_(account_id), | 78 account_id_(account_id) {} |
80 list_accounts_callback_(list_accounts_callback) {} | |
81 | 79 |
82 GaiaCookieManagerService::GaiaCookieRequest::~GaiaCookieRequest() { | 80 GaiaCookieManagerService::GaiaCookieRequest::~GaiaCookieRequest() { |
83 } | 81 } |
84 | 82 |
85 // static | 83 // static |
86 GaiaCookieManagerService::GaiaCookieRequest | 84 GaiaCookieManagerService::GaiaCookieRequest |
87 GaiaCookieManagerService::GaiaCookieRequest::CreateAddAccountRequest( | 85 GaiaCookieManagerService::GaiaCookieRequest::CreateAddAccountRequest( |
88 const std::string& account_id) { | 86 const std::string& account_id) { |
89 return GaiaCookieManagerService::GaiaCookieRequest( | 87 return GaiaCookieManagerService::GaiaCookieRequest( |
90 GaiaCookieManagerService::GaiaCookieRequestType::ADD_ACCOUNT, | 88 GaiaCookieManagerService::GaiaCookieRequestType::ADD_ACCOUNT, account_id); |
91 account_id, | |
92 GaiaCookieManagerService::ListAccountsCallback()); | |
93 } | 89 } |
94 | 90 |
95 // static | 91 // static |
96 GaiaCookieManagerService::GaiaCookieRequest | 92 GaiaCookieManagerService::GaiaCookieRequest |
97 GaiaCookieManagerService::GaiaCookieRequest::CreateLogOutRequest() { | 93 GaiaCookieManagerService::GaiaCookieRequest::CreateLogOutRequest() { |
98 return GaiaCookieManagerService::GaiaCookieRequest( | 94 return GaiaCookieManagerService::GaiaCookieRequest( |
99 GaiaCookieManagerService::GaiaCookieRequestType::LOG_OUT, | 95 GaiaCookieManagerService::GaiaCookieRequestType::LOG_OUT, std::string()); |
100 std::string(), | |
101 GaiaCookieManagerService::ListAccountsCallback()); | |
102 } | 96 } |
103 | 97 |
104 GaiaCookieManagerService::GaiaCookieRequest | 98 GaiaCookieManagerService::GaiaCookieRequest |
105 GaiaCookieManagerService::GaiaCookieRequest::CreateListAccountsRequest( | 99 GaiaCookieManagerService::GaiaCookieRequest::CreateListAccountsRequest() { |
106 const GaiaCookieManagerService::ListAccountsCallback& | |
107 list_accounts_callback) { | |
108 return GaiaCookieManagerService::GaiaCookieRequest( | 100 return GaiaCookieManagerService::GaiaCookieRequest( |
109 GaiaCookieManagerService::GaiaCookieRequestType::LIST_ACCOUNTS, | 101 GaiaCookieManagerService::GaiaCookieRequestType::LIST_ACCOUNTS, |
110 std::string(), | 102 std::string()); |
111 list_accounts_callback); | |
112 } | 103 } |
113 | 104 |
114 GaiaCookieManagerService::ExternalCcResultFetcher::ExternalCcResultFetcher( | 105 GaiaCookieManagerService::ExternalCcResultFetcher::ExternalCcResultFetcher( |
115 GaiaCookieManagerService* helper) | 106 GaiaCookieManagerService* helper) |
116 : helper_(helper) { | 107 : helper_(helper) { |
117 DCHECK(helper_); | 108 DCHECK(helper_); |
118 } | 109 } |
119 | 110 |
120 GaiaCookieManagerService::ExternalCcResultFetcher::~ExternalCcResultFetcher() { | 111 GaiaCookieManagerService::ExternalCcResultFetcher::~ExternalCcResultFetcher() { |
121 CleanupTransientState(); | 112 CleanupTransientState(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 GaiaCookieManagerService::GaiaCookieManagerService( | 279 GaiaCookieManagerService::GaiaCookieManagerService( |
289 OAuth2TokenService* token_service, | 280 OAuth2TokenService* token_service, |
290 const std::string& source, | 281 const std::string& source, |
291 SigninClient* signin_client) | 282 SigninClient* signin_client) |
292 : token_service_(token_service), | 283 : token_service_(token_service), |
293 signin_client_(signin_client), | 284 signin_client_(signin_client), |
294 external_cc_result_fetcher_(this), | 285 external_cc_result_fetcher_(this), |
295 gaia_auth_fetcher_backoff_(&kBackoffPolicy), | 286 gaia_auth_fetcher_backoff_(&kBackoffPolicy), |
296 gaia_auth_fetcher_retries_(0), | 287 gaia_auth_fetcher_retries_(0), |
297 source_(source), | 288 source_(source), |
298 external_cc_result_fetched_(false) { | 289 external_cc_result_fetched_(false), |
| 290 list_accounts_fetched_once_(false) { |
299 } | 291 } |
300 | 292 |
301 GaiaCookieManagerService::~GaiaCookieManagerService() { | 293 GaiaCookieManagerService::~GaiaCookieManagerService() { |
302 CancelAll(); | 294 CancelAll(); |
303 DCHECK(requests_.empty()); | 295 DCHECK(requests_.empty()); |
304 } | 296 } |
305 | 297 |
| 298 void GaiaCookieManagerService::Init() { |
| 299 cookie_changed_subscription_ = signin_client_->AddCookieChangedCallback( |
| 300 GaiaUrls::GetInstance()->google_url(), |
| 301 "APISID", |
| 302 base::Bind(&GaiaCookieManagerService::OnCookieChanged, |
| 303 base::Unretained(this))); |
| 304 } |
| 305 |
| 306 void GaiaCookieManagerService::Shutdown() { |
| 307 cookie_changed_subscription_.reset(); |
| 308 } |
| 309 |
306 void GaiaCookieManagerService::AddAccountToCookie( | 310 void GaiaCookieManagerService::AddAccountToCookie( |
307 const std::string& account_id) { | 311 const std::string& account_id) { |
| 312 if (!signin_client_->AreSigninCookiesAllowed()) { |
| 313 SignalComplete(account_id, |
| 314 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); |
| 315 return; |
| 316 } |
| 317 |
308 DCHECK(!account_id.empty()); | 318 DCHECK(!account_id.empty()); |
309 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id; | 319 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id; |
310 requests_.push_back(GaiaCookieRequest::CreateAddAccountRequest(account_id)); | 320 requests_.push_back(GaiaCookieRequest::CreateAddAccountRequest(account_id)); |
311 if (requests_.size() == 1) | 321 if (requests_.size() == 1) |
312 StartFetchingUbertoken(); | 322 StartFetchingUbertoken(); |
313 } | 323 } |
314 | 324 |
315 void GaiaCookieManagerService::ListAccounts( | 325 bool GaiaCookieManagerService::ListAccounts( |
316 const ListAccountsCallback& callback) { | 326 std::vector<std::pair<std::string,bool> >* accounts) { |
317 // Not implemented yet. | 327 DCHECK(accounts); |
318 NOTREACHED(); | 328 accounts->clear(); |
319 | 329 |
320 // TODO(mlerman): Once this service listens to all GAIA cookie changes, cache | 330 // There is a fetch currently executing (the results being provided in the |
321 // the results of ListAccounts, and return them here if the GAIA cookie | 331 // parameter don't align with the fetches that have been started), or the list |
322 // hasn't changed since the last call. | 332 // of accounts haven't been fetched even once. |
| 333 if (!requests_.empty()) |
| 334 return false; |
323 | 335 |
324 // If there's a GAIA call being executed, wait for it to complete. If it was | 336 if (!list_accounts_fetched_once_) { |
325 // another /ListAccounts then we'll use the results it caches. | 337 gaia_auth_fetcher_retries_ = 0; |
326 if (gaia_auth_fetcher_) | 338 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); |
327 return; | 339 StartFetchingListAccounts(); |
| 340 return false; |
| 341 } |
328 | 342 |
329 VLOG(1) << "GaiaCookieManagerService::ListAccounts"; | 343 accounts->assign(listed_accounts_.begin(), listed_accounts_.end()); |
330 gaia_auth_fetcher_.reset( | 344 return true; |
331 new GaiaAuthFetcher(this, source_, | |
332 signin_client_->GetURLRequestContext())); | |
333 gaia_auth_fetcher_->StartListAccounts(); | |
334 } | 345 } |
335 | 346 |
336 void GaiaCookieManagerService::LogOutAllAccounts() { | 347 void GaiaCookieManagerService::LogOutAllAccounts() { |
337 VLOG(1) << "GaiaCookieManagerService::LogOutAllAccounts"; | 348 VLOG(1) << "GaiaCookieManagerService::LogOutAllAccounts"; |
338 | 349 |
339 bool log_out_queued = false; | 350 bool log_out_queued = false; |
340 if (!requests_.empty()) { | 351 if (!requests_.empty()) { |
341 // Track requests to keep; all other unstarted requests will be removed. | 352 // Track requests to keep; all other unstarted requests will be removed. |
342 std::vector<GaiaCookieRequest> requests_to_keep; | 353 std::vector<GaiaCookieRequest> requests_to_keep; |
343 | 354 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 398 } |
388 | 399 |
389 void GaiaCookieManagerService::CancelAll() { | 400 void GaiaCookieManagerService::CancelAll() { |
390 VLOG(1) << "GaiaCookieManagerService::CancelAll"; | 401 VLOG(1) << "GaiaCookieManagerService::CancelAll"; |
391 gaia_auth_fetcher_.reset(); | 402 gaia_auth_fetcher_.reset(); |
392 uber_token_fetcher_.reset(); | 403 uber_token_fetcher_.reset(); |
393 requests_.clear(); | 404 requests_.clear(); |
394 gaia_auth_fetcher_timer_.Stop(); | 405 gaia_auth_fetcher_timer_.Stop(); |
395 } | 406 } |
396 | 407 |
| 408 // It is unknown if the cookie was changed because of processing initiated by |
| 409 // this class or other (such as the user clearing all cookies or a cookie being |
| 410 // evicted). |
| 411 void GaiaCookieManagerService::OnCookieChanged( |
| 412 const net::CanonicalCookie& cookie, |
| 413 bool removed) { |
| 414 DCHECK_EQ("APISID", cookie.Name()); |
| 415 DCHECK_EQ(GaiaUrls::GetInstance()->google_url().host(), cookie.Domain()); |
| 416 gaia_auth_fetcher_retries_ = 0; |
| 417 if (requests_.empty()) { |
| 418 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); |
| 419 StartFetchingListAccounts(); |
| 420 } else { |
| 421 // Remove all pending ListAccount calls; for efficiency, only call |
| 422 // after all pending requests are processed. |
| 423 // Track requests to keep; all other unstarted requests will be removed. |
| 424 std::vector<GaiaCookieRequest> requests_to_keep; |
| 425 |
| 426 // Check all pending, non-executing requests. |
| 427 for (auto it = requests_.begin() + 1; it != requests_.end(); ++it) { |
| 428 // Keep all requests except for LIST_ACCOUNTS. |
| 429 if (it->request_type() != GaiaCookieRequestType::LIST_ACCOUNTS) |
| 430 requests_to_keep.push_back(*it); |
| 431 } |
| 432 |
| 433 // Remove all but the executing request. Re-add all requests being kept. |
| 434 if (requests_.size() > 1) { |
| 435 requests_.erase(requests_.begin() + 1, requests_.end()); |
| 436 requests_.insert( |
| 437 requests_.end(), requests_to_keep.begin(), requests_to_keep.end()); |
| 438 } |
| 439 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); |
| 440 } |
| 441 } |
| 442 |
397 void GaiaCookieManagerService::SignalComplete( | 443 void GaiaCookieManagerService::SignalComplete( |
398 const std::string& account_id, | 444 const std::string& account_id, |
399 const GoogleServiceAuthError& error) { | 445 const GoogleServiceAuthError& error) { |
400 // Its possible for the observer to delete |this| object. Don't access | 446 // Its possible for the observer to delete |this| object. Don't access |
401 // access any members after this calling the observer. This method should | 447 // access any members after this calling the observer. This method should |
402 // be the last call in any other method. | 448 // be the last call in any other method. |
403 FOR_EACH_OBSERVER(Observer, observer_list_, | 449 FOR_EACH_OBSERVER(Observer, observer_list_, |
404 OnAddAccountToCookieCompleted(account_id, error)); | 450 OnAddAccountToCookieCompleted(account_id, error)); |
405 } | 451 } |
406 | 452 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 << " account=" << requests_.front().account_id() | 485 << " account=" << requests_.front().account_id() |
440 << " error=" << error.ToString(); | 486 << " error=" << error.ToString(); |
441 const std::string account_id = requests_.front().account_id(); | 487 const std::string account_id = requests_.front().account_id(); |
442 HandleNextRequest(); | 488 HandleNextRequest(); |
443 SignalComplete(account_id, error); | 489 SignalComplete(account_id, error); |
444 } | 490 } |
445 | 491 |
446 void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { | 492 void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { |
447 VLOG(1) << "MergeSession successful account=" | 493 VLOG(1) << "MergeSession successful account=" |
448 << requests_.front().account_id(); | 494 << requests_.front().account_id(); |
| 495 DCHECK(requests_.front().request_type() == |
| 496 GaiaCookieRequestType::ADD_ACCOUNT); |
449 const std::string account_id = requests_.front().account_id(); | 497 const std::string account_id = requests_.front().account_id(); |
450 HandleNextRequest(); | 498 HandleNextRequest(); |
451 SignalComplete(account_id, GoogleServiceAuthError::AuthErrorNone()); | 499 SignalComplete(account_id, GoogleServiceAuthError::AuthErrorNone()); |
452 | 500 |
453 gaia_auth_fetcher_backoff_.InformOfRequest(true); | 501 gaia_auth_fetcher_backoff_.InformOfRequest(true); |
454 uber_token_ = std::string(); | 502 uber_token_ = std::string(); |
455 } | 503 } |
456 | 504 |
457 void GaiaCookieManagerService::OnMergeSessionFailure( | 505 void GaiaCookieManagerService::OnMergeSessionFailure( |
458 const GoogleServiceAuthError& error) { | 506 const GoogleServiceAuthError& error) { |
| 507 DCHECK(requests_.front().request_type() == |
| 508 GaiaCookieRequestType::ADD_ACCOUNT); |
459 VLOG(1) << "Failed MergeSession" | 509 VLOG(1) << "Failed MergeSession" |
460 << " account=" << requests_.front().account_id() | 510 << " account=" << requests_.front().account_id() |
461 << " error=" << error.ToString(); | 511 << " error=" << error.ToString(); |
462 | |
463 if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && | 512 if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && |
464 IsTransientError(error)) { | 513 IsTransientError(error)) { |
465 gaia_auth_fetcher_backoff_.InformOfRequest(false); | 514 gaia_auth_fetcher_backoff_.InformOfRequest(false); |
466 gaia_auth_fetcher_timer_.Start( | 515 gaia_auth_fetcher_timer_.Start( |
467 FROM_HERE, gaia_auth_fetcher_backoff_.GetTimeUntilRelease(), this, | 516 FROM_HERE, gaia_auth_fetcher_backoff_.GetTimeUntilRelease(), this, |
468 &GaiaCookieManagerService::StartFetchingMergeSession); | 517 &GaiaCookieManagerService::StartFetchingMergeSession); |
469 return; | 518 return; |
470 } | 519 } |
471 | 520 |
472 uber_token_ = std::string(); | 521 uber_token_ = std::string(); |
473 const std::string account_id = requests_.front().account_id(); | 522 const std::string account_id = requests_.front().account_id(); |
474 HandleNextRequest(); | 523 HandleNextRequest(); |
475 SignalComplete(account_id, error); | 524 SignalComplete(account_id, error); |
476 } | 525 } |
477 | 526 |
| 527 void GaiaCookieManagerService::OnListAccountsSuccess(const std::string& data) { |
| 528 VLOG(1) << "ListAccounts successful"; |
| 529 DCHECK(requests_.front().request_type() == |
| 530 GaiaCookieRequestType::LIST_ACCOUNTS); |
| 531 gaia_auth_fetcher_backoff_.InformOfRequest(true); |
| 532 |
| 533 if (!gaia::ParseListAccountsData(data, &listed_accounts_)) { |
| 534 listed_accounts_.clear(); |
| 535 OnListAccountsFailure(GoogleServiceAuthError( |
| 536 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); |
| 537 return; |
| 538 } |
| 539 |
| 540 list_accounts_fetched_once_ = true; |
| 541 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 542 OnGaiaAccountsInCookieUpdated( |
| 543 listed_accounts_, |
| 544 GoogleServiceAuthError(GoogleServiceAuthError::NONE))); |
| 545 HandleNextRequest(); |
| 546 } |
| 547 |
| 548 void GaiaCookieManagerService::OnListAccountsFailure( |
| 549 const GoogleServiceAuthError& error) { |
| 550 VLOG(1) << "ListAccounts failed"; |
| 551 DCHECK(requests_.front().request_type() == |
| 552 GaiaCookieRequestType::LIST_ACCOUNTS); |
| 553 if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && |
| 554 IsTransientError(error)) { |
| 555 gaia_auth_fetcher_backoff_.InformOfRequest(false); |
| 556 gaia_auth_fetcher_timer_.Start( |
| 557 FROM_HERE, gaia_auth_fetcher_backoff_.GetTimeUntilRelease(), this, |
| 558 &GaiaCookieManagerService::StartFetchingListAccounts); |
| 559 return; |
| 560 } |
| 561 |
| 562 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 563 OnGaiaAccountsInCookieUpdated(listed_accounts_, error)); |
| 564 HandleNextRequest(); |
| 565 } |
| 566 |
478 void GaiaCookieManagerService::StartFetchingUbertoken() { | 567 void GaiaCookieManagerService::StartFetchingUbertoken() { |
479 VLOG(1) << "GaiaCookieManagerService::StartFetching account_id=" | 568 VLOG(1) << "GaiaCookieManagerService::StartFetching account_id=" |
480 << requests_.front().account_id(); | 569 << requests_.front().account_id(); |
481 uber_token_fetcher_.reset( | 570 uber_token_fetcher_.reset( |
482 new UbertokenFetcher(token_service_, this, source_, | 571 new UbertokenFetcher(token_service_, this, source_, |
483 signin_client_->GetURLRequestContext())); | 572 signin_client_->GetURLRequestContext())); |
484 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); | 573 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); |
485 } | 574 } |
486 | 575 |
487 void GaiaCookieManagerService::StartFetchingMergeSession() { | 576 void GaiaCookieManagerService::StartFetchingMergeSession() { |
488 DCHECK(!uber_token_.empty()); | 577 DCHECK(!uber_token_.empty()); |
489 gaia_auth_fetcher_.reset( | 578 gaia_auth_fetcher_.reset( |
490 new GaiaAuthFetcher(this, source_, | 579 new GaiaAuthFetcher(this, source_, |
491 signin_client_->GetURLRequestContext())); | 580 signin_client_->GetURLRequestContext())); |
492 | 581 |
493 gaia_auth_fetcher_->StartMergeSession(uber_token_, | 582 gaia_auth_fetcher_->StartMergeSession(uber_token_, |
494 external_cc_result_fetcher_.GetExternalCcResult()); | 583 external_cc_result_fetcher_.GetExternalCcResult()); |
495 } | 584 } |
496 | 585 |
| 586 void GaiaCookieManagerService::StartFetchingListAccounts() { |
| 587 VLOG(1) << "GaiaCookieManagerService::ListAccounts"; |
| 588 gaia_auth_fetcher_.reset( |
| 589 new GaiaAuthFetcher(this, source_, |
| 590 signin_client_->GetURLRequestContext())); |
| 591 gaia_auth_fetcher_->StartListAccounts(); |
| 592 } |
| 593 |
497 void GaiaCookieManagerService::OnURLFetchComplete( | 594 void GaiaCookieManagerService::OnURLFetchComplete( |
498 const net::URLFetcher* source) { | 595 const net::URLFetcher* source) { |
499 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); | 596 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); |
500 VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete"; | 597 VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete"; |
501 HandleNextRequest(); | 598 HandleNextRequest(); |
502 } | 599 } |
503 | 600 |
504 void GaiaCookieManagerService::HandleNextRequest() { | 601 void GaiaCookieManagerService::HandleNextRequest() { |
505 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest"; | 602 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest"; |
506 requests_.pop_front(); | 603 if (requests_.front().request_type() == |
| 604 GaiaCookieRequestType::LIST_ACCOUNTS) { |
| 605 // This and any directly subsequent list accounts would return the same. |
| 606 while (!requests_.empty() && requests_.front().request_type() == |
| 607 GaiaCookieRequestType::LIST_ACCOUNTS) { |
| 608 requests_.pop_front(); |
| 609 } |
| 610 } else { |
| 611 // Pop the completed request. |
| 612 requests_.pop_front(); |
| 613 } |
| 614 |
507 gaia_auth_fetcher_.reset(); | 615 gaia_auth_fetcher_.reset(); |
| 616 gaia_auth_fetcher_retries_ = 0; |
508 if (requests_.empty()) { | 617 if (requests_.empty()) { |
509 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more"; | 618 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more"; |
510 uber_token_fetcher_.reset(); | 619 uber_token_fetcher_.reset(); |
511 } else { | 620 } else { |
512 switch (requests_.front().request_type()) { | 621 switch (requests_.front().request_type()) { |
513 case GaiaCookieRequestType::ADD_ACCOUNT: | 622 case GaiaCookieRequestType::ADD_ACCOUNT: |
514 StartFetchingUbertoken(); | 623 StartFetchingUbertoken(); |
515 break; | 624 break; |
516 case GaiaCookieRequestType::LOG_OUT: | 625 case GaiaCookieRequestType::LOG_OUT: |
517 StartLogOutUrlFetch(); | 626 StartLogOutUrlFetch(); |
518 break; | 627 break; |
519 case GaiaCookieRequestType::LIST_ACCOUNTS: | 628 case GaiaCookieRequestType::LIST_ACCOUNTS: |
| 629 uber_token_fetcher_.reset(); |
| 630 StartFetchingListAccounts(); |
520 break; | 631 break; |
521 }; | 632 }; |
522 } | 633 } |
523 } | 634 } |
OLD | NEW |