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

Side by Side Diff: components/signin/core/browser/gaia_cookie_manager_service.cc

Issue 1070563004: GCMS has automatic checks for CheckExternalConnections. It will be (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only fetch ExternalCCResult once per PKS lifetime. Also, unit tests are totally radical. Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 fetchers_[fetcher->GetOriginalURL()] = std::make_pair(token, fetcher); 187 fetchers_[fetcher->GetOriginalURL()] = std::make_pair(token, fetcher);
188 fetcher->Start(); 188 fetcher->Start();
189 } 189 }
190 } 190 }
191 } 191 }
192 } 192 }
193 193
194 void GaiaCookieManagerService::ExternalCcResultFetcher:: 194 void GaiaCookieManagerService::ExternalCcResultFetcher::
195 OnGetCheckConnectionInfoError(const GoogleServiceAuthError& error) { 195 OnGetCheckConnectionInfoError(const GoogleServiceAuthError& error) {
196 CleanupTransientState(); 196 CleanupTransientState();
197 FireGetCheckConnectionInfoCompleted(false); 197 FireGetCheckConnectionInfoCompleted(false);
Roger Tawa OOO till Jul 10th 2015/04/08 21:24:17 Since we are doing this only once now, should we a
Mike Lerman 2015/04/09 14:40:09 Ok and done. Will use the same gaia_auth_fetcher_
198 } 198 }
199 199
200 net::URLFetcher* 200 net::URLFetcher*
201 GaiaCookieManagerService::ExternalCcResultFetcher::CreateFetcher( 201 GaiaCookieManagerService::ExternalCcResultFetcher::CreateFetcher(
202 const GURL& url) { 202 const GURL& url) {
203 net::URLFetcher* fetcher = 203 net::URLFetcher* fetcher =
204 net::URLFetcher::Create(0, url, net::URLFetcher::GET, this); 204 net::URLFetcher::Create(0, url, net::URLFetcher::GET, this);
205 fetcher->SetRequestContext(helper_->request_context()); 205 fetcher->SetRequestContext(helper_->request_context());
206 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 206 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
207 net::LOAD_DO_NOT_SAVE_COOKIES); 207 net::LOAD_DO_NOT_SAVE_COOKIES);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 gaia_auth_fetcher_.reset(); 253 gaia_auth_fetcher_.reset();
254 254
255 for (URLToTokenAndFetcher::const_iterator it = fetchers_.begin(); 255 for (URLToTokenAndFetcher::const_iterator it = fetchers_.begin();
256 it != fetchers_.end(); ++it) { 256 it != fetchers_.end(); ++it) {
257 delete it->second.second; 257 delete it->second.second;
258 } 258 }
259 fetchers_.clear(); 259 fetchers_.clear();
260 } 260 }
261 261
262 void GaiaCookieManagerService::ExternalCcResultFetcher:: 262 void GaiaCookieManagerService::ExternalCcResultFetcher::
263 FireGetCheckConnectionInfoCompleted(bool succeeded) { 263 FireGetCheckConnectionInfoCompleted(bool succeeded) {
Roger Tawa OOO till Jul 10th 2015/04/08 21:24:17 Nit: is this function name still appropriate?
Mike Lerman 2015/04/09 14:40:09 Removed "Fire". It's cleaner.
264 base::TimeDelta time_to_check_connections = 264 base::TimeDelta time_to_check_connections =
265 base::Time::Now() - m_external_cc_result_start_time_; 265 base::Time::Now() - m_external_cc_result_start_time_;
266 signin_metrics::LogExternalCcResultFetches(succeeded, 266 signin_metrics::LogExternalCcResultFetches(succeeded,
267 time_to_check_connections); 267 time_to_check_connections);
268 FOR_EACH_OBSERVER(Observer, helper_->observer_list_, 268
269 GetCheckConnectionInfoCompleted(succeeded)); 269 helper_->external_cc_result_fetched_ = true;
270 // Since the ExternalCCResultFetcher is only Started in place of calling
271 // StartFetchingMergeSession, we can assume we need to call
272 // StartFetchingMergeSession. If this assumption becomes invalid, a Callback
273 // will need to be passed to Start() and Run() here.
274 helper_->StartFetchingMergeSession();
270 } 275 }
271 276
272 GaiaCookieManagerService::GaiaCookieManagerService( 277 GaiaCookieManagerService::GaiaCookieManagerService(
273 OAuth2TokenService* token_service, 278 OAuth2TokenService* token_service,
274 const std::string& source, 279 const std::string& source,
275 SigninClient* signin_client) 280 SigninClient* signin_client)
276 : token_service_(token_service), 281 : token_service_(token_service),
277 signin_client_(signin_client), 282 signin_client_(signin_client),
278 external_cc_result_fetcher_(this), 283 external_cc_result_fetcher_(this),
279 gaia_auth_fetcher_backoff_(&kBackoffPolicy), 284 gaia_auth_fetcher_backoff_(&kBackoffPolicy),
280 gaia_auth_fetcher_retries_(0), 285 gaia_auth_fetcher_retries_(0),
281 source_(source) { 286 source_(source),
287 external_cc_result_fetched_(false) {
282 } 288 }
283 289
284 GaiaCookieManagerService::~GaiaCookieManagerService() { 290 GaiaCookieManagerService::~GaiaCookieManagerService() {
285 CancelAll(); 291 CancelAll();
286 DCHECK(requests_.empty()); 292 DCHECK(requests_.empty());
287 } 293 }
288 294
289 void GaiaCookieManagerService::AddAccountToCookie( 295 void GaiaCookieManagerService::AddAccountToCookie(
290 const std::string& account_id) { 296 const std::string& account_id) {
291 DCHECK(!account_id.empty()); 297 DCHECK(!account_id.empty());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 void GaiaCookieManagerService::SignalComplete( 386 void GaiaCookieManagerService::SignalComplete(
381 const std::string& account_id, 387 const std::string& account_id,
382 const GoogleServiceAuthError& error) { 388 const GoogleServiceAuthError& error) {
383 // Its possible for the observer to delete |this| object. Don't access 389 // Its possible for the observer to delete |this| object. Don't access
384 // access any members after this calling the observer. This method should 390 // access any members after this calling the observer. This method should
385 // be the last call in any other method. 391 // be the last call in any other method.
386 FOR_EACH_OBSERVER(Observer, observer_list_, 392 FOR_EACH_OBSERVER(Observer, observer_list_,
387 OnAddAccountToCookieCompleted(account_id, error)); 393 OnAddAccountToCookieCompleted(account_id, error));
388 } 394 }
389 395
390 void GaiaCookieManagerService::StartFetchingExternalCcResult() {
391 if (!external_cc_result_fetcher_.IsRunning())
392 external_cc_result_fetcher_.Start();
393 }
394
395 void GaiaCookieManagerService::StartLogOutUrlFetch() { 396 void GaiaCookieManagerService::StartLogOutUrlFetch() {
396 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); 397 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT);
397 VLOG(1) << "GaiaCookieManagerService::StartLogOutUrlFetch"; 398 VLOG(1) << "GaiaCookieManagerService::StartLogOutUrlFetch";
398 GURL logout_url(GaiaUrls::GetInstance()->service_logout_url().Resolve( 399 GURL logout_url(GaiaUrls::GetInstance()->service_logout_url().Resolve(
399 base::StringPrintf("?source=%s", source_.c_str()))); 400 base::StringPrintf("?source=%s", source_.c_str())));
400 net::URLFetcher* fetcher = 401 net::URLFetcher* fetcher =
401 net::URLFetcher::Create(logout_url, net::URLFetcher::GET, this); 402 net::URLFetcher::Create(logout_url, net::URLFetcher::GET, this);
402 fetcher->SetRequestContext(signin_client_->GetURLRequestContext()); 403 fetcher->SetRequestContext(signin_client_->GetURLRequestContext());
403 fetcher->Start(); 404 fetcher->Start();
404 } 405 }
405 406
406 void GaiaCookieManagerService::OnUbertokenSuccess( 407 void GaiaCookieManagerService::OnUbertokenSuccess(
407 const std::string& uber_token) { 408 const std::string& uber_token) {
409 DCHECK(requests_.front().request_type() ==
410 GaiaCookieRequestType::ADD_ACCOUNT);
408 VLOG(1) << "GaiaCookieManagerService::OnUbertokenSuccess" 411 VLOG(1) << "GaiaCookieManagerService::OnUbertokenSuccess"
409 << " account=" << requests_.front().account_id(); 412 << " account=" << requests_.front().account_id();
410 gaia_auth_fetcher_retries_ = 0; 413 gaia_auth_fetcher_retries_ = 0;
411 uber_token_ = uber_token; 414 uber_token_ = uber_token;
415
416 if (!external_cc_result_fetched_ &&
417 !external_cc_result_fetcher_.IsRunning()) {
418 external_cc_result_fetcher_.Start();
419 return;
420 }
421
412 StartFetchingMergeSession(); 422 StartFetchingMergeSession();
413 } 423 }
414 424
415 void GaiaCookieManagerService::OnUbertokenFailure( 425 void GaiaCookieManagerService::OnUbertokenFailure(
416 const GoogleServiceAuthError& error) { 426 const GoogleServiceAuthError& error) {
417 VLOG(1) << "Failed to retrieve ubertoken" 427 VLOG(1) << "Failed to retrieve ubertoken"
418 << " account=" << requests_.front().account_id() 428 << " account=" << requests_.front().account_id()
419 << " error=" << error.ToString(); 429 << " error=" << error.ToString();
420 const std::string account_id = requests_.front().account_id(); 430 const std::string account_id = requests_.front().account_id();
421 HandleNextRequest(); 431 HandleNextRequest();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 signin_client_->GetURLRequestContext())); 472 signin_client_->GetURLRequestContext()));
463 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); 473 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id());
464 } 474 }
465 475
466 void GaiaCookieManagerService::StartFetchingMergeSession() { 476 void GaiaCookieManagerService::StartFetchingMergeSession() {
467 DCHECK(!uber_token_.empty()); 477 DCHECK(!uber_token_.empty());
468 gaia_auth_fetcher_.reset( 478 gaia_auth_fetcher_.reset(
469 new GaiaAuthFetcher(this, source_, 479 new GaiaAuthFetcher(this, source_,
470 signin_client_->GetURLRequestContext())); 480 signin_client_->GetURLRequestContext()));
471 481
472 // It's possible that not all external checks have completed.
473 // GetExternalCcResult() returns results for those that have.
474 gaia_auth_fetcher_->StartMergeSession(uber_token_, 482 gaia_auth_fetcher_->StartMergeSession(uber_token_,
475 external_cc_result_fetcher_.GetExternalCcResult()); 483 external_cc_result_fetcher_.GetExternalCcResult());
476 } 484 }
477 485
478 void GaiaCookieManagerService::OnURLFetchComplete( 486 void GaiaCookieManagerService::OnURLFetchComplete(
479 const net::URLFetcher* source) { 487 const net::URLFetcher* source) {
480 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); 488 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT);
481 VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete"; 489 VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete";
482 HandleNextRequest(); 490 HandleNextRequest();
483 } 491 }
(...skipping 11 matching lines...) Expand all
495 StartFetchingUbertoken(); 503 StartFetchingUbertoken();
496 break; 504 break;
497 case GaiaCookieRequestType::LOG_OUT: 505 case GaiaCookieRequestType::LOG_OUT:
498 StartLogOutUrlFetch(); 506 StartLogOutUrlFetch();
499 break; 507 break;
500 case GaiaCookieRequestType::LIST_ACCOUNTS: 508 case GaiaCookieRequestType::LIST_ACCOUNTS:
501 break; 509 break;
502 }; 510 };
503 } 511 }
504 } 512 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698