| 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" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 420 } |
| 421 | 421 |
| 422 void GaiaCookieManagerService::CancelAll() { | 422 void GaiaCookieManagerService::CancelAll() { |
| 423 VLOG(1) << "GaiaCookieManagerService::CancelAll"; | 423 VLOG(1) << "GaiaCookieManagerService::CancelAll"; |
| 424 gaia_auth_fetcher_.reset(); | 424 gaia_auth_fetcher_.reset(); |
| 425 uber_token_fetcher_.reset(); | 425 uber_token_fetcher_.reset(); |
| 426 requests_.clear(); | 426 requests_.clear(); |
| 427 fetcher_timer_.Stop(); | 427 fetcher_timer_.Stop(); |
| 428 } | 428 } |
| 429 | 429 |
| 430 // It is unknown if the cookie was changed because of processing initiated by | |
| 431 // this class or other (such as the user clearing all cookies or a cookie being | |
| 432 // evicted). | |
| 433 void GaiaCookieManagerService::OnCookieChanged( | 430 void GaiaCookieManagerService::OnCookieChanged( |
| 434 const net::CanonicalCookie& cookie, | 431 const net::CanonicalCookie& cookie, |
| 435 bool removed) { | 432 bool removed) { |
| 436 DCHECK_EQ("APISID", cookie.Name()); | 433 DCHECK_EQ("APISID", cookie.Name()); |
| 437 DCHECK_EQ(GaiaUrls::GetInstance()->google_url().host(), cookie.Domain()); | 434 DCHECK_EQ(GaiaUrls::GetInstance()->google_url().host(), cookie.Domain()); |
| 435 // Ignore changes to the cookie while requests are pending. These changes |
| 436 // are caused by the service itself as it adds accounts. A side effects is |
| 437 // that any changes to the gaia cookie outside of this class, while requests |
| 438 // are pending, will be lost. However, trying to process these changes could |
| 439 // cause an endless loop (see crbug.com/516070). |
| 438 if (requests_.empty()) { | 440 if (requests_.empty()) { |
| 439 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); | 441 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); |
| 440 fetcher_retries_ = 0; | 442 fetcher_retries_ = 0; |
| 441 signin_client_->DelayNetworkCall( | 443 signin_client_->DelayNetworkCall( |
| 442 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, | 444 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, |
| 443 base::Unretained(this))); | 445 base::Unretained(this))); |
| 444 } else { | |
| 445 // Remove all pending ListAccount calls; for efficiency, only call | |
| 446 // after all pending requests are processed. | |
| 447 // Track requests to keep; all other unstarted requests will be removed. | |
| 448 std::vector<GaiaCookieRequest> requests_to_keep; | |
| 449 | |
| 450 // Check all pending, non-executing requests. | |
| 451 for (auto it = requests_.begin() + 1; it != requests_.end(); ++it) { | |
| 452 // Keep all requests except for LIST_ACCOUNTS. | |
| 453 if (it->request_type() != GaiaCookieRequestType::LIST_ACCOUNTS) | |
| 454 requests_to_keep.push_back(*it); | |
| 455 } | |
| 456 | |
| 457 // Remove all but the executing request. Re-add all requests being kept. | |
| 458 if (requests_.size() > 1) { | |
| 459 requests_.erase(requests_.begin() + 1, requests_.end()); | |
| 460 requests_.insert( | |
| 461 requests_.end(), requests_to_keep.begin(), requests_to_keep.end()); | |
| 462 } | |
| 463 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); | |
| 464 } | 446 } |
| 465 } | 447 } |
| 466 | 448 |
| 467 void GaiaCookieManagerService::SignalComplete( | 449 void GaiaCookieManagerService::SignalComplete( |
| 468 const std::string& account_id, | 450 const std::string& account_id, |
| 469 const GoogleServiceAuthError& error) { | 451 const GoogleServiceAuthError& error) { |
| 470 // Its possible for the observer to delete |this| object. Don't access | 452 // Its possible for the observer to delete |this| object. Don't access |
| 471 // access any members after this calling the observer. This method should | 453 // access any members after this calling the observer. This method should |
| 472 // be the last call in any other method. | 454 // be the last call in any other method. |
| 473 FOR_EACH_OBSERVER(Observer, observer_list_, | 455 FOR_EACH_OBSERVER(Observer, observer_list_, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 break; | 687 break; |
| 706 case GaiaCookieRequestType::LIST_ACCOUNTS: | 688 case GaiaCookieRequestType::LIST_ACCOUNTS: |
| 707 uber_token_fetcher_.reset(); | 689 uber_token_fetcher_.reset(); |
| 708 signin_client_->DelayNetworkCall( | 690 signin_client_->DelayNetworkCall( |
| 709 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, | 691 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, |
| 710 base::Unretained(this))); | 692 base::Unretained(this))); |
| 711 break; | 693 break; |
| 712 }; | 694 }; |
| 713 } | 695 } |
| 714 } | 696 } |
| OLD | NEW |