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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper.cc

Issue 362613002: Implementation of SigninClient::GetSigninScopedDeviceId (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/sync/one_click_signin_helper.h" 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 GaiaUrls::GetInstance()->service_login_url().ReplaceComponents( 407 GaiaUrls::GetInstance()->service_login_url().ReplaceComponents(
408 replacements); 408 replacements);
409 409
410 return (url.ReplaceComponents(replacements) == clean_login_url && 410 return (url.ReplaceComponents(replacements) == clean_login_url &&
411 source != signin::SOURCE_UNKNOWN) || 411 source != signin::SOURCE_UNKNOWN) ||
412 (IsValidGaiaSigninRedirectOrResponseURL(url) && 412 (IsValidGaiaSigninRedirectOrResponseURL(url) &&
413 url.spec().find("ChromeLoginPrompt") != std::string::npos && 413 url.spec().find("ChromeLoginPrompt") != std::string::npos &&
414 !email.empty()); 414 !email.empty());
415 } 415 }
416 416
417 // Gets signin scoped device id from signin client if profile is valid. 417 // If profile is valid then generates new signin scoped device id from signin
418 // Otherwise returns empty string. 418 // client. Otherwise returns empty string.
419 std::string GetSigninScopedDeviceId(Profile* profile) { 419 std::string GenerateNewSigninScopedDeviceId(Profile* profile) {
420 std::string signin_scoped_device_id; 420 std::string signin_scoped_device_id;
421 SigninClient* signin_client = 421 SigninClient* signin_client =
422 profile ? ChromeSigninClientFactory::GetForProfile(profile) : NULL; 422 profile ? ChromeSigninClientFactory::GetForProfile(profile) : NULL;
423 if (signin_client) { 423 if (signin_client) {
424 signin_client->ClearSigninScopedDeviceId();
424 signin_scoped_device_id = signin_client->GetSigninScopedDeviceId(); 425 signin_scoped_device_id = signin_client->GetSigninScopedDeviceId();
425 } 426 }
426 return signin_scoped_device_id; 427 return signin_scoped_device_id;
427 } 428 }
428 429
429 // CurrentHistoryCleaner ------------------------------------------------------ 430 // CurrentHistoryCleaner ------------------------------------------------------
430 431
431 // Watch a webcontents and remove URL from the history once loading is complete. 432 // Watch a webcontents and remove URL from the history once loading is complete.
432 // We have to delay the cleaning until the new URL has finished loading because 433 // We have to delay the cleaning until the new URL has finished loading because
433 // we're not allowed to remove the last-loaded URL from the history. Objects 434 // we're not allowed to remove the last-loaded URL from the history. Objects
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 source(signin::SOURCE_UNKNOWN) {} 510 source(signin::SOURCE_UNKNOWN) {}
510 511
511 OneClickSigninHelper::StartSyncArgs::StartSyncArgs( 512 OneClickSigninHelper::StartSyncArgs::StartSyncArgs(
512 Profile* profile, 513 Profile* profile,
513 Browser* browser, 514 Browser* browser,
514 OneClickSigninHelper::AutoAccept auto_accept, 515 OneClickSigninHelper::AutoAccept auto_accept,
515 const std::string& session_index, 516 const std::string& session_index,
516 const std::string& email, 517 const std::string& email,
517 const std::string& password, 518 const std::string& password,
518 const std::string& refresh_token, 519 const std::string& refresh_token,
519 const std::string& signin_scoped_device_id,
520 content::WebContents* web_contents, 520 content::WebContents* web_contents,
521 bool untrusted_confirmation_required, 521 bool untrusted_confirmation_required,
522 signin::Source source, 522 signin::Source source,
523 OneClickSigninSyncStarter::Callback callback) 523 OneClickSigninSyncStarter::Callback callback)
524 : profile(profile), 524 : profile(profile),
525 browser(browser), 525 browser(browser),
526 auto_accept(auto_accept), 526 auto_accept(auto_accept),
527 session_index(session_index), 527 session_index(session_index),
528 email(email), 528 email(email),
529 password(password), 529 password(password),
530 refresh_token(refresh_token), 530 refresh_token(refresh_token),
531 signin_scoped_device_id(signin_scoped_device_id),
532 web_contents(web_contents), 531 web_contents(web_contents),
533 source(source), 532 source(source),
534 callback(callback) { 533 callback(callback) {
535 DCHECK(session_index.empty() != refresh_token.empty()); 534 DCHECK(session_index.empty() != refresh_token.empty());
536 if (untrusted_confirmation_required) { 535 if (untrusted_confirmation_required) {
537 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; 536 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN;
538 } else if (source == signin::SOURCE_SETTINGS || 537 } else if (source == signin::SOURCE_SETTINGS ||
539 source == signin::SOURCE_WEBSTORE_INSTALL) { 538 source == signin::SOURCE_WEBSTORE_INSTALL) {
540 // Do not display a status confirmation for webstore installs or re-auth. 539 // Do not display a status confirmation for webstore installs or re-auth.
541 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; 540 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 args_.browser, args_.profile, desktop_type_); 653 args_.browser, args_.profile, desktop_type_);
655 args_.browser->window()->ShowOneClickSigninBubble( 654 args_.browser->window()->ShowOneClickSigninBubble(
656 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, 655 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
657 base::string16(), // No email required - this is not a SAML confirmation. 656 base::string16(), // No email required - this is not a SAML confirmation.
658 base::UTF8ToUTF16(error_message), 657 base::UTF8ToUTF16(error_message),
659 // Callback is ignored. 658 // Callback is ignored.
660 BrowserWindow::StartSyncCallback()); 659 BrowserWindow::StartSyncCallback());
661 } 660 }
662 661
663 void OneClickSigninHelper::SyncStarterWrapper::StartSigninOAuthHelper() { 662 void OneClickSigninHelper::SyncStarterWrapper::StartSigninOAuthHelper() {
663 std::string signin_scoped_device_id =
664 GenerateNewSigninScopedDeviceId(args_.profile);
pavely 2014/06/30 23:31:09 This is where new id generated before signing in.
Roger Tawa OOO till Jul 10th 2014/07/01 13:42:54 For mirror, sign in occurs in inline_login_handler
pavely 2014/07/01 21:41:47 Ok, it seems like there are multiple codepaths tha
Roger Tawa OOO till Jul 10th 2014/07/03 15:07:41 In mirror, start tracing from InlineLoginHandlerI
664 signin_oauth_helper_.reset( 665 signin_oauth_helper_.reset(
665 new SigninOAuthHelper(args_.profile->GetRequestContext(), 666 new SigninOAuthHelper(args_.profile->GetRequestContext(),
666 args_.session_index, 667 args_.session_index,
667 args_.signin_scoped_device_id, 668 signin_scoped_device_id,
668 this)); 669 this));
669 } 670 }
670 671
671 void 672 void
672 OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( 673 OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter(
673 const std::string& email, 674 const std::string& email,
674 const std::string& refresh_token) { 675 const std::string& refresh_token) {
675 // The starter deletes itself once it's done. 676 // The starter deletes itself once it's done.
676 new OneClickSigninSyncStarter(args_.profile, args_.browser, 677 new OneClickSigninSyncStarter(args_.profile, args_.browser,
677 email, args_.password, 678 email, args_.password,
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 const std::string& password, 1175 const std::string& password,
1175 const std::string& refresh_token, 1176 const std::string& refresh_token,
1176 OneClickSigninHelper::AutoAccept auto_accept, 1177 OneClickSigninHelper::AutoAccept auto_accept,
1177 signin::Source source, 1178 signin::Source source,
1178 OneClickSigninSyncStarter::StartSyncMode start_mode, 1179 OneClickSigninSyncStarter::StartSyncMode start_mode,
1179 OneClickSigninSyncStarter::Callback sync_callback) { 1180 OneClickSigninSyncStarter::Callback sync_callback) {
1180 Profile* profile = 1181 Profile* profile =
1181 Profile::FromBrowserContext(contents->GetBrowserContext()); 1182 Profile::FromBrowserContext(contents->GetBrowserContext());
1182 std::string last_email = 1183 std::string last_email =
1183 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); 1184 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername);
1184 std::string signin_scoped_device_id = GetSigninScopedDeviceId(profile);
1185 1185
1186 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) { 1186 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) {
1187 // If the new email address is different from the email address that 1187 // If the new email address is different from the email address that
1188 // just signed in, show a confirmation dialog. 1188 // just signed in, show a confirmation dialog.
1189 1189
1190 // No need to display a second confirmation so pass false below. 1190 // No need to display a second confirmation so pass false below.
1191 // TODO(atwilson): Move this into OneClickSigninSyncStarter. 1191 // TODO(atwilson): Move this into OneClickSigninSyncStarter.
1192 // The tab modal dialog always executes its callback before |contents| 1192 // The tab modal dialog always executes its callback before |contents|
1193 // is deleted. 1193 // is deleted.
1194 Browser* browser = chrome::FindBrowserWithWebContents(contents); 1194 Browser* browser = chrome::FindBrowserWithWebContents(contents);
1195 ConfirmEmailDialogDelegate::AskForConfirmation( 1195 ConfirmEmailDialogDelegate::AskForConfirmation(
1196 contents, 1196 contents,
1197 last_email, 1197 last_email,
1198 email, 1198 email,
1199 base::Bind( 1199 base::Bind(
1200 &StartExplicitSync, 1200 &StartExplicitSync,
1201 StartSyncArgs(profile, browser, auto_accept, 1201 StartSyncArgs(profile, browser, auto_accept,
1202 session_index, email, password, 1202 session_index, email, password,
1203 refresh_token, signin_scoped_device_id, 1203 refresh_token,
1204 contents, false /* confirmation_required */, source, 1204 contents, false /* confirmation_required */, source,
1205 sync_callback), 1205 sync_callback),
1206 contents, 1206 contents,
1207 start_mode)); 1207 start_mode));
1208 return true; 1208 return true;
1209 } 1209 }
1210 1210
1211 return false; 1211 return false;
1212 } 1212 }
1213 1213
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 switched_to_advanced_ = source == signin::SOURCE_SETTINGS; 1480 switched_to_advanced_ = source == signin::SOURCE_SETTINGS;
1481 } 1481 }
1482 } 1482 }
1483 1483
1484 Browser* browser = chrome::FindBrowserWithWebContents(contents); 1484 Browser* browser = chrome::FindBrowserWithWebContents(contents);
1485 1485
1486 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." 1486 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go."
1487 << " auto_accept=" << auto_accept_ 1487 << " auto_accept=" << auto_accept_
1488 << " source=" << source_; 1488 << " source=" << source_;
1489 1489
1490 std::string signin_scoped_device_id = GetSigninScopedDeviceId(profile);
1491 switch (auto_accept_) { 1490 switch (auto_accept_) {
1492 case AUTO_ACCEPT_NONE: 1491 case AUTO_ACCEPT_NONE:
1493 if (showing_signin_) 1492 if (showing_signin_)
1494 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); 1493 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED);
1495 break; 1494 break;
1496 case AUTO_ACCEPT_ACCEPTED: 1495 case AUTO_ACCEPT_ACCEPTED:
1497 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); 1496 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED);
1498 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); 1497 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS);
1499 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); 1498 SigninManager::DisableOneClickSignIn(profile->GetPrefs());
1500 // Start syncing with the default settings - prompt the user to sign in 1499 // Start syncing with the default settings - prompt the user to sign in
1501 // first. 1500 // first.
1502 if (!do_not_start_sync_for_testing_) { 1501 if (!do_not_start_sync_for_testing_) {
1503 StartSync( 1502 StartSync(
1504 StartSyncArgs(profile, browser, auto_accept_, 1503 StartSyncArgs(profile, browser, auto_accept_,
1505 session_index_, email_, password_, 1504 session_index_, email_, password_, "",
1506 "", signin_scoped_device_id,
1507 NULL /* don't force sync setup in same tab */, 1505 NULL /* don't force sync setup in same tab */,
1508 true /* confirmation_required */, source_, 1506 true /* confirmation_required */, source_,
1509 CreateSyncStarterCallback()), 1507 CreateSyncStarterCallback()),
1510 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); 1508 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS);
1511 } 1509 }
1512 break; 1510 break;
1513 case AUTO_ACCEPT_CONFIGURE: 1511 case AUTO_ACCEPT_CONFIGURE:
1514 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); 1512 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED);
1515 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); 1513 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED);
1516 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); 1514 SigninManager::DisableOneClickSignIn(profile->GetPrefs());
1517 // Display the extra confirmation (even in the SAML case) in case this 1515 // Display the extra confirmation (even in the SAML case) in case this
1518 // was an untrusted renderer. 1516 // was an untrusted renderer.
1519 if (!do_not_start_sync_for_testing_) { 1517 if (!do_not_start_sync_for_testing_) {
1520 StartSync( 1518 StartSync(
1521 StartSyncArgs(profile, browser, auto_accept_, 1519 StartSyncArgs(profile, browser, auto_accept_,
1522 session_index_, email_, password_, 1520 session_index_, email_, password_, "",
1523 "", signin_scoped_device_id,
1524 NULL /* don't force sync setup in same tab */, 1521 NULL /* don't force sync setup in same tab */,
1525 true /* confirmation_required */, source_, 1522 true /* confirmation_required */, source_,
1526 CreateSyncStarterCallback()), 1523 CreateSyncStarterCallback()),
1527 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); 1524 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST);
1528 } 1525 }
1529 break; 1526 break;
1530 case AUTO_ACCEPT_EXPLICIT: { 1527 case AUTO_ACCEPT_EXPLICIT: {
1531 signin::Source original_source = 1528 signin::Source original_source =
1532 signin::GetSourceForPromoURL(original_continue_url_); 1529 signin::GetSourceForPromoURL(original_continue_url_);
1533 if (switched_to_advanced_) { 1530 if (switched_to_advanced_) {
(...skipping 25 matching lines...) Expand all
1559 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : 1556 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE :
1560 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : 1557 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST :
1561 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; 1558 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS;
1562 1559
1563 if (!HandleCrossAccountError(contents, session_index_, email_, password_, 1560 if (!HandleCrossAccountError(contents, session_index_, email_, password_,
1564 "", auto_accept_, source_, start_mode, 1561 "", auto_accept_, source_, start_mode,
1565 CreateSyncStarterCallback())) { 1562 CreateSyncStarterCallback())) {
1566 if (!do_not_start_sync_for_testing_) { 1563 if (!do_not_start_sync_for_testing_) {
1567 StartSync( 1564 StartSync(
1568 StartSyncArgs(profile, browser, auto_accept_, 1565 StartSyncArgs(profile, browser, auto_accept_,
1569 session_index_, email_, password_, 1566 session_index_, email_, password_, "",
1570 "", signin_scoped_device_id,
1571 contents, 1567 contents,
1572 untrusted_confirmation_required_, source_, 1568 untrusted_confirmation_required_, source_,
1573 CreateSyncStarterCallback()), 1569 CreateSyncStarterCallback()),
1574 start_mode); 1570 start_mode);
1575 } 1571 }
1576 1572
1577 // If this explicit sign in is not from settings page/webstore, show 1573 // If this explicit sign in is not from settings page/webstore, show
1578 // the NTP/Apps page after sign in completes. In the case of the 1574 // the NTP/Apps page after sign in completes. In the case of the
1579 // settings page, it will get auto-closed after sync setup. In the case 1575 // settings page, it will get auto-closed after sync setup. In the case
1580 // of webstore, it will redirect back to webstore. 1576 // of webstore, it will redirect back to webstore.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 // If the web contents is showing a blank page and not about to be closed, 1619 // If the web contents is showing a blank page and not about to be closed,
1624 // redirect to the NTP or apps page. 1620 // redirect to the NTP or apps page.
1625 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && 1621 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) &&
1626 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { 1622 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) {
1627 RedirectToNtpOrAppsPage( 1623 RedirectToNtpOrAppsPage(
1628 web_contents(), 1624 web_contents(),
1629 signin::GetSourceForPromoURL(original_continue_url_)); 1625 signin::GetSourceForPromoURL(original_continue_url_));
1630 } 1626 }
1631 } 1627 }
1632 } 1628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698