Chromium Code Reviews| 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 GURL("http://.google.com"), | |
|
Roger Tawa OOO till Jul 10th
2015/04/15 18:51:06
A constant very similar to this is also used on ch
Mike Lerman
2015/04/16 13:13:46
Done. Also, it's supposed to be http not https - t
| |
| 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->assign(listed_accounts_.begin(), listed_accounts_.end()); |
|
Roger Tawa OOO till Jul 10th
2015/04/15 18:51:06
Should do this only if the return value is true. S
Mike Lerman
2015/04/16 13:13:46
Done.
| |
| 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(); |
| 328 | 340 return false; |
| 329 VLOG(1) << "GaiaCookieManagerService::ListAccounts"; | 341 } |
| 330 gaia_auth_fetcher_.reset( | 342 return true; |
| 331 new GaiaAuthFetcher(this, source_, | |
| 332 signin_client_->GetURLRequestContext())); | |
| 333 gaia_auth_fetcher_->StartListAccounts(); | |
| 334 } | 343 } |
| 335 | 344 |
| 336 void GaiaCookieManagerService::LogOutAllAccounts() { | 345 void GaiaCookieManagerService::LogOutAllAccounts() { |
| 337 VLOG(1) << "GaiaCookieManagerService::LogOutAllAccounts"; | 346 VLOG(1) << "GaiaCookieManagerService::LogOutAllAccounts"; |
| 338 | 347 |
| 339 bool log_out_queued = false; | 348 bool log_out_queued = false; |
| 340 if (!requests_.empty()) { | 349 if (!requests_.empty()) { |
| 341 // Track requests to keep; all other unstarted requests will be removed. | 350 // Track requests to keep; all other unstarted requests will be removed. |
| 342 std::vector<GaiaCookieRequest> requests_to_keep; | 351 std::vector<GaiaCookieRequest> requests_to_keep; |
| 343 | 352 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 } | 396 } |
| 388 | 397 |
| 389 void GaiaCookieManagerService::CancelAll() { | 398 void GaiaCookieManagerService::CancelAll() { |
| 390 VLOG(1) << "GaiaCookieManagerService::CancelAll"; | 399 VLOG(1) << "GaiaCookieManagerService::CancelAll"; |
| 391 gaia_auth_fetcher_.reset(); | 400 gaia_auth_fetcher_.reset(); |
| 392 uber_token_fetcher_.reset(); | 401 uber_token_fetcher_.reset(); |
| 393 requests_.clear(); | 402 requests_.clear(); |
| 394 gaia_auth_fetcher_timer_.Stop(); | 403 gaia_auth_fetcher_timer_.Stop(); |
| 395 } | 404 } |
| 396 | 405 |
| 406 // It is unknown if the cookie was changed because of processing initiated by | |
| 407 // this class or other (such as the user clearing all cookies or a cookie being | |
| 408 // evicted). | |
| 409 void GaiaCookieManagerService::OnCookieChanged( | |
| 410 const net::CanonicalCookie& cookie, | |
| 411 bool removed) { | |
| 412 DCHECK_EQ("APISID", cookie.Name()); | |
| 413 DCHECK(GaiaUrls::GetInstance()->gaia_url().host().find(cookie.Domain()) != | |
| 414 std::string::npos); | |
|
Roger Tawa OOO till Jul 10th
2015/04/15 18:51:06
nit: use DCHECK_NE ?
Mike Lerman
2015/04/16 13:13:46
Now that I have a GaiaURL for google.com, this is
| |
| 415 gaia_auth_fetcher_retries_ = 0; | |
| 416 if (requests_.empty()) { | |
| 417 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); | |
| 418 StartFetchingListAccounts(); | |
| 419 } else { | |
| 420 // Remove all pending ListAccount calls; for efficiency, only call | |
| 421 // after all pending requests are processed. | |
| 422 // Track requests to keep; all other unstarted requests will be removed. | |
| 423 std::vector<GaiaCookieRequest> requests_to_keep; | |
| 424 | |
| 425 // Check all pending, non-executing requests. | |
| 426 for (auto it = requests_.begin() + 1; it != requests_.end(); ++it) { | |
| 427 // Keep all requests except for LIST_ACCOUNTS. | |
| 428 if (it->request_type() != GaiaCookieRequestType::LIST_ACCOUNTS) | |
| 429 requests_to_keep.push_back(*it); | |
| 430 } | |
| 431 | |
| 432 // Remove all but the executing request. Re-add all requests being kept. | |
| 433 if (requests_.size() > 1) { | |
| 434 requests_.erase(requests_.begin() + 1, requests_.end()); | |
| 435 requests_.insert( | |
| 436 requests_.end(), requests_to_keep.begin(), requests_to_keep.end()); | |
| 437 } | |
| 438 requests_.push_back(GaiaCookieRequest::CreateListAccountsRequest()); | |
| 439 } | |
| 440 } | |
| 441 | |
| 397 void GaiaCookieManagerService::SignalComplete( | 442 void GaiaCookieManagerService::SignalComplete( |
| 398 const std::string& account_id, | 443 const std::string& account_id, |
| 399 const GoogleServiceAuthError& error) { | 444 const GoogleServiceAuthError& error) { |
| 400 // Its possible for the observer to delete |this| object. Don't access | 445 // Its possible for the observer to delete |this| object. Don't access |
| 401 // access any members after this calling the observer. This method should | 446 // access any members after this calling the observer. This method should |
| 402 // be the last call in any other method. | 447 // be the last call in any other method. |
| 403 FOR_EACH_OBSERVER(Observer, observer_list_, | 448 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 404 OnAddAccountToCookieCompleted(account_id, error)); | 449 OnAddAccountToCookieCompleted(account_id, error)); |
| 405 } | 450 } |
| 406 | 451 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 << " account=" << requests_.front().account_id() | 484 << " account=" << requests_.front().account_id() |
| 440 << " error=" << error.ToString(); | 485 << " error=" << error.ToString(); |
| 441 const std::string account_id = requests_.front().account_id(); | 486 const std::string account_id = requests_.front().account_id(); |
| 442 HandleNextRequest(); | 487 HandleNextRequest(); |
| 443 SignalComplete(account_id, error); | 488 SignalComplete(account_id, error); |
| 444 } | 489 } |
| 445 | 490 |
| 446 void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { | 491 void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { |
| 447 VLOG(1) << "MergeSession successful account=" | 492 VLOG(1) << "MergeSession successful account=" |
| 448 << requests_.front().account_id(); | 493 << requests_.front().account_id(); |
| 494 DCHECK(requests_.front().request_type() == | |
| 495 GaiaCookieRequestType::ADD_ACCOUNT); | |
| 449 const std::string account_id = requests_.front().account_id(); | 496 const std::string account_id = requests_.front().account_id(); |
| 450 HandleNextRequest(); | 497 HandleNextRequest(); |
| 451 SignalComplete(account_id, GoogleServiceAuthError::AuthErrorNone()); | 498 SignalComplete(account_id, GoogleServiceAuthError::AuthErrorNone()); |
| 452 | 499 |
| 453 gaia_auth_fetcher_backoff_.InformOfRequest(true); | 500 gaia_auth_fetcher_backoff_.InformOfRequest(true); |
| 454 uber_token_ = std::string(); | 501 uber_token_ = std::string(); |
| 455 } | 502 } |
| 456 | 503 |
| 457 void GaiaCookieManagerService::OnMergeSessionFailure( | 504 void GaiaCookieManagerService::OnMergeSessionFailure( |
| 458 const GoogleServiceAuthError& error) { | 505 const GoogleServiceAuthError& error) { |
| 506 DCHECK(requests_.front().request_type() == | |
| 507 GaiaCookieRequestType::ADD_ACCOUNT); | |
| 459 VLOG(1) << "Failed MergeSession" | 508 VLOG(1) << "Failed MergeSession" |
| 460 << " account=" << requests_.front().account_id() | 509 << " account=" << requests_.front().account_id() |
| 461 << " error=" << error.ToString(); | 510 << " error=" << error.ToString(); |
| 462 | |
| 463 if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && | 511 if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && |
| 464 IsTransientError(error)) { | 512 IsTransientError(error)) { |
| 465 gaia_auth_fetcher_backoff_.InformOfRequest(false); | 513 gaia_auth_fetcher_backoff_.InformOfRequest(false); |
| 466 gaia_auth_fetcher_timer_.Start( | 514 gaia_auth_fetcher_timer_.Start( |
| 467 FROM_HERE, gaia_auth_fetcher_backoff_.GetTimeUntilRelease(), this, | 515 FROM_HERE, gaia_auth_fetcher_backoff_.GetTimeUntilRelease(), this, |
| 468 &GaiaCookieManagerService::StartFetchingMergeSession); | 516 &GaiaCookieManagerService::StartFetchingMergeSession); |
| 469 return; | 517 return; |
| 470 } | 518 } |
| 471 | 519 |
| 472 uber_token_ = std::string(); | 520 uber_token_ = std::string(); |
| 473 const std::string account_id = requests_.front().account_id(); | 521 const std::string account_id = requests_.front().account_id(); |
| 474 HandleNextRequest(); | 522 HandleNextRequest(); |
| 475 SignalComplete(account_id, error); | 523 SignalComplete(account_id, error); |
| 476 } | 524 } |
| 477 | 525 |
| 526 void GaiaCookieManagerService::OnListAccountsSuccess(const std::string& data) { | |
| 527 VLOG(1) << "ListAccounts successful"; | |
| 528 DCHECK(requests_.front().request_type() == | |
| 529 GaiaCookieRequestType::LIST_ACCOUNTS); | |
|
Roger Tawa OOO till Jul 10th
2015/04/15 18:51:06
If |requests_.size() > 1| then maybe we should jus
Mike Lerman
2015/04/16 13:13:46
I'm hesitant if that's the best thing to do. We've
| |
| 530 gaia_auth_fetcher_backoff_.InformOfRequest(true); | |
| 531 | |
| 532 if (!gaia::ParseListAccountsData(data, &listed_accounts_)) { | |
| 533 listed_accounts_.clear(); | |
| 534 OnListAccountsFailure(GoogleServiceAuthError( | |
| 535 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); | |
| 536 return; | |
| 537 } | |
| 538 | |
| 539 list_accounts_fetched_once_ = true; | |
| 540 FOR_EACH_OBSERVER(Observer, observer_list_, | |
| 541 OnGaiaAccountsInCookieUpdated( | |
| 542 listed_accounts_, | |
| 543 GoogleServiceAuthError(GoogleServiceAuthError::NONE))); | |
| 544 HandleNextRequest(); | |
| 545 } | |
| 546 | |
| 547 void GaiaCookieManagerService::OnListAccountsFailure( | |
| 548 const GoogleServiceAuthError& error) { | |
| 549 VLOG(1) << "ListAccounts failed"; | |
| 550 DCHECK(requests_.front().request_type() == | |
| 551 GaiaCookieRequestType::LIST_ACCOUNTS); | |
| 552 if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && | |
| 553 IsTransientError(error)) { | |
| 554 gaia_auth_fetcher_backoff_.InformOfRequest(false); | |
| 555 gaia_auth_fetcher_timer_.Start( | |
| 556 FROM_HERE, gaia_auth_fetcher_backoff_.GetTimeUntilRelease(), this, | |
| 557 &GaiaCookieManagerService::StartFetchingListAccounts); | |
| 558 return; | |
| 559 } | |
| 560 | |
| 561 HandleNextRequest(); | |
| 562 } | |
| 563 | |
| 478 void GaiaCookieManagerService::StartFetchingUbertoken() { | 564 void GaiaCookieManagerService::StartFetchingUbertoken() { |
| 479 VLOG(1) << "GaiaCookieManagerService::StartFetching account_id=" | 565 VLOG(1) << "GaiaCookieManagerService::StartFetching account_id=" |
| 480 << requests_.front().account_id(); | 566 << requests_.front().account_id(); |
| 481 uber_token_fetcher_.reset( | 567 uber_token_fetcher_.reset( |
| 482 new UbertokenFetcher(token_service_, this, source_, | 568 new UbertokenFetcher(token_service_, this, source_, |
| 483 signin_client_->GetURLRequestContext())); | 569 signin_client_->GetURLRequestContext())); |
| 484 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); | 570 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); |
| 485 } | 571 } |
| 486 | 572 |
| 487 void GaiaCookieManagerService::StartFetchingMergeSession() { | 573 void GaiaCookieManagerService::StartFetchingMergeSession() { |
| 488 DCHECK(!uber_token_.empty()); | 574 DCHECK(!uber_token_.empty()); |
| 489 gaia_auth_fetcher_.reset( | 575 gaia_auth_fetcher_.reset( |
| 490 new GaiaAuthFetcher(this, source_, | 576 new GaiaAuthFetcher(this, source_, |
| 491 signin_client_->GetURLRequestContext())); | 577 signin_client_->GetURLRequestContext())); |
| 492 | 578 |
| 493 gaia_auth_fetcher_->StartMergeSession(uber_token_, | 579 gaia_auth_fetcher_->StartMergeSession(uber_token_, |
| 494 external_cc_result_fetcher_.GetExternalCcResult()); | 580 external_cc_result_fetcher_.GetExternalCcResult()); |
| 495 } | 581 } |
| 496 | 582 |
| 583 void GaiaCookieManagerService::StartFetchingListAccounts() { | |
| 584 VLOG(1) << "GaiaCookieManagerService::ListAccounts"; | |
| 585 gaia_auth_fetcher_.reset( | |
| 586 new GaiaAuthFetcher(this, source_, | |
| 587 signin_client_->GetURLRequestContext())); | |
| 588 gaia_auth_fetcher_->StartListAccounts(); | |
| 589 } | |
| 590 | |
| 497 void GaiaCookieManagerService::OnURLFetchComplete( | 591 void GaiaCookieManagerService::OnURLFetchComplete( |
| 498 const net::URLFetcher* source) { | 592 const net::URLFetcher* source) { |
| 499 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); | 593 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); |
| 500 VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete"; | 594 VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete"; |
| 501 HandleNextRequest(); | 595 HandleNextRequest(); |
| 502 } | 596 } |
| 503 | 597 |
| 504 void GaiaCookieManagerService::HandleNextRequest() { | 598 void GaiaCookieManagerService::HandleNextRequest() { |
| 505 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest"; | 599 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest"; |
| 506 requests_.pop_front(); | 600 if (requests_.front().request_type() == |
| 601 GaiaCookieRequestType::LIST_ACCOUNTS) { | |
| 602 // This and any directly subsequent list accounts would return the same. | |
| 603 while (!requests_.empty() && requests_.front().request_type() == | |
| 604 GaiaCookieRequestType::LIST_ACCOUNTS) { | |
| 605 requests_.pop_front(); | |
| 606 } | |
| 607 } else { | |
| 608 // Pop the completed request. | |
| 609 requests_.pop_front(); | |
| 610 } | |
| 611 | |
| 507 gaia_auth_fetcher_.reset(); | 612 gaia_auth_fetcher_.reset(); |
| 613 gaia_auth_fetcher_retries_ = 0; | |
| 508 if (requests_.empty()) { | 614 if (requests_.empty()) { |
| 509 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more"; | 615 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more"; |
| 510 uber_token_fetcher_.reset(); | 616 uber_token_fetcher_.reset(); |
| 511 } else { | 617 } else { |
| 512 switch (requests_.front().request_type()) { | 618 switch (requests_.front().request_type()) { |
| 513 case GaiaCookieRequestType::ADD_ACCOUNT: | 619 case GaiaCookieRequestType::ADD_ACCOUNT: |
| 514 StartFetchingUbertoken(); | 620 StartFetchingUbertoken(); |
| 515 break; | 621 break; |
| 516 case GaiaCookieRequestType::LOG_OUT: | 622 case GaiaCookieRequestType::LOG_OUT: |
| 517 StartLogOutUrlFetch(); | 623 StartLogOutUrlFetch(); |
| 518 break; | 624 break; |
| 519 case GaiaCookieRequestType::LIST_ACCOUNTS: | 625 case GaiaCookieRequestType::LIST_ACCOUNTS: |
| 626 uber_token_fetcher_.reset(); | |
| 627 StartFetchingListAccounts(); | |
| 520 break; | 628 break; |
| 521 }; | 629 }; |
| 522 } | 630 } |
| 523 } | 631 } |
| OLD | NEW |