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

Side by Side Diff: chrome/browser/ui/webui/options/sync_setup_handler.cc

Issue 1473543002: Implement newly designed sign-in related histograms for desktop platorms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 5 years 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/webui/options/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/options/sync_setup_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", 328 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing",
329 base::Bind(&SyncSetupHandler::HandleStopSyncing, 329 base::Bind(&SyncSetupHandler::HandleStopSyncing,
330 base::Unretained(this))); 330 base::Unretained(this)));
331 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn", 331 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn",
332 base::Bind(&SyncSetupHandler::HandleStartSignin, 332 base::Bind(&SyncSetupHandler::HandleStartSignin,
333 base::Unretained(this))); 333 base::Unretained(this)));
334 #endif 334 #endif
335 } 335 }
336 336
337 #if !defined(OS_CHROMEOS) 337 #if !defined(OS_CHROMEOS)
338 void SyncSetupHandler::DisplayGaiaLogin() { 338 void SyncSetupHandler::DisplayGaiaLogin(
339 signin_metrics::AccessPoint access_point) {
339 DCHECK(!sync_startup_tracker_); 340 DCHECK(!sync_startup_tracker_);
340 // Advanced options are no longer being configured if the login screen is 341 // Advanced options are no longer being configured if the login screen is
341 // visible. If the user exits the signin wizard after this without 342 // visible. If the user exits the signin wizard after this without
342 // configuring sync, CloseSyncSetup() will ensure they are logged out. 343 // configuring sync, CloseSyncSetup() will ensure they are logged out.
343 configuring_sync_ = false; 344 configuring_sync_ = false;
344 DisplayGaiaLoginInNewTabOrWindow(); 345 DisplayGaiaLoginInNewTabOrWindow(access_point);
345 } 346 }
346 347
347 void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow() { 348 void SyncSetupHandler::DisplayGaiaLoginInNewTabOrWindow(
349 signin_metrics::AccessPoint access_point) {
348 Browser* browser = chrome::FindBrowserWithWebContents( 350 Browser* browser = chrome::FindBrowserWithWebContents(
349 web_ui()->GetWebContents()); 351 web_ui()->GetWebContents());
350 bool force_new_tab = false; 352 bool force_new_tab = false;
351 if (!browser) { 353 if (!browser) {
352 // Settings is not displayed in a browser window. Open a new window. 354 // Settings is not displayed in a browser window. Open a new window.
353 browser = new Browser(Browser::CreateParams( 355 browser = new Browser(Browser::CreateParams(
354 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); 356 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop()));
355 force_new_tab = true; 357 force_new_tab = true;
356 } 358 }
357 359
358 // If the signin manager already has an authenticated username, this is a 360 // If the signin manager already has an authenticated username, this is a
359 // re-auth scenario, and we need to ensure that the user signs in with the 361 // re-auth scenario, and we need to ensure that the user signs in with the
360 // same email address. 362 // same email address.
361 GURL url; 363 GURL url;
362 if (SigninManagerFactory::GetForProfile( 364 if (SigninManagerFactory::GetForProfile(
363 browser->profile())->IsAuthenticated()) { 365 browser->profile())->IsAuthenticated()) {
364 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", 366 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth",
365 signin_metrics::HISTOGRAM_REAUTH_SHOWN, 367 signin_metrics::HISTOGRAM_REAUTH_SHOWN,
366 signin_metrics::HISTOGRAM_REAUTH_MAX); 368 signin_metrics::HISTOGRAM_REAUTH_MAX);
367 369
368 SigninErrorController* error_controller = 370 SigninErrorController* error_controller =
369 SigninErrorControllerFactory::GetForProfile(browser->profile()); 371 SigninErrorControllerFactory::GetForProfile(browser->profile());
370 DCHECK(error_controller->HasError()); 372 DCHECK(error_controller->HasError());
371 if (!force_new_tab) { 373 if (!force_new_tab) {
372 browser->window()->ShowAvatarBubbleFromAvatarButton( 374 browser->window()->ShowAvatarBubbleFromAvatarButton(
373 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH, 375 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH,
374 signin::ManageAccountsParams()); 376 signin::ManageAccountsParams(), access_point);
375 } else { 377 } else {
376 url = signin::GetReauthURL(browser->profile(), 378 url = signin::GetReauthURL(
377 error_controller->error_account_id()); 379 access_point, signin_metrics::Reason::REASON_REAUTHENTICATION,
380 browser->profile(), error_controller->error_account_id());
378 } 381 }
379 } else { 382 } else {
380 signin_metrics::LogSigninSource(signin_metrics::SOURCE_SETTINGS);
381 if (!force_new_tab) { 383 if (!force_new_tab) {
382 browser->window()->ShowAvatarBubbleFromAvatarButton( 384 browser->window()->ShowAvatarBubbleFromAvatarButton(
383 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, 385 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN,
384 signin::ManageAccountsParams()); 386 signin::ManageAccountsParams(), access_point);
385 } else { 387 } else {
386 url = signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true); 388 url = signin::GetPromoURL(
389 access_point, signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT,
390 true);
387 } 391 }
388 } 392 }
389 393
390 if (url.is_valid()) 394 if (url.is_valid())
391 chrome::ShowSingletonTab(browser, url); 395 chrome::ShowSingletonTab(browser, url);
392 } 396 }
393 #endif 397 #endif
394 398
395 bool SyncSetupHandler::PrepareSyncSetup() { 399 bool SyncSetupHandler::PrepareSyncSetup() {
396 // If the wizard is already visible, just focus that one. 400 // If the wizard is already visible, just focus that one.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // blank setup overlay on this page by showing the "done" page. This can 625 // blank setup overlay on this page by showing the "done" page. This can
622 // happen if the user navigates to chrome://settings/syncSetup in more than 626 // happen if the user navigates to chrome://settings/syncSetup in more than
623 // one tab. See crbug.com/261566. 627 // one tab. See crbug.com/261566.
624 // Note: The following block will transfer focus to the existing wizard. 628 // Note: The following block will transfer focus to the existing wizard.
625 if (IsExistingWizardPresent() && !IsActiveLogin()) 629 if (IsExistingWizardPresent() && !IsActiveLogin())
626 CloseUI(); 630 CloseUI();
627 631
628 // If a setup wizard is present on this page or another, bring it to focus. 632 // If a setup wizard is present on this page or another, bring it to focus.
629 // Otherwise, display a new one on this page. 633 // Otherwise, display a new one on this page.
630 if (!FocusExistingWizardIfPresent()) 634 if (!FocusExistingWizardIfPresent())
631 OpenSyncSetup(); 635 OpenSyncSetup(args);
632 } 636 }
633 637
634 #if defined(OS_CHROMEOS) 638 #if defined(OS_CHROMEOS)
635 // On ChromeOS, we need to sign out the user session to fix an auth error, so 639 // On ChromeOS, we need to sign out the user session to fix an auth error, so
636 // the user goes through the real signin flow to generate a new auth token. 640 // the user goes through the real signin flow to generate a new auth token.
637 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { 641 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) {
638 DVLOG(1) << "Signing out the user to fix a sync error."; 642 DVLOG(1) << "Signing out the user to fix a sync error.";
639 chrome::AttemptUserExit(); 643 chrome::AttemptUserExit();
640 } 644 }
641 #endif 645 #endif
642 646
643 #if !defined(OS_CHROMEOS) 647 #if !defined(OS_CHROMEOS)
644 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) { 648 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) {
645 // Should only be called if the user is not already signed in. 649 // Should only be called if the user is not already signed in.
646 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())-> 650 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())->
647 IsAuthenticated()); 651 IsAuthenticated());
648 OpenSyncSetup(); 652 OpenSyncSetup(args);
649 } 653 }
650 654
651 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) { 655 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) {
652 if (GetSyncService()) 656 if (GetSyncService())
653 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 657 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
654 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( 658 SigninManagerFactory::GetForProfile(GetProfile())->SignOut(
655 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); 659 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS);
656 660
657 bool delete_profile = false; 661 bool delete_profile = false;
658 if (args->GetBoolean(0, &delete_profile) && delete_profile) { 662 if (args->GetBoolean(0, &delete_profile) && delete_profile) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 714
711 // Alert the sync service anytime the sync setup dialog is closed. This can 715 // Alert the sync service anytime the sync setup dialog is closed. This can
712 // happen due to the user clicking the OK or Cancel button, or due to the 716 // happen due to the user clicking the OK or Cancel button, or due to the
713 // dialog being closed by virtue of sync being disabled in the background. 717 // dialog being closed by virtue of sync being disabled in the background.
714 if (sync_service) 718 if (sync_service)
715 sync_service->SetSetupInProgress(false); 719 sync_service->SetSetupInProgress(false);
716 720
717 configuring_sync_ = false; 721 configuring_sync_ = false;
718 } 722 }
719 723
720 void SyncSetupHandler::OpenSyncSetup() { 724 void SyncSetupHandler::OpenSyncSetup(const base::ListValue* args) {
721 if (!PrepareSyncSetup()) 725 if (!PrepareSyncSetup())
722 return; 726 return;
723 727
724 // There are several different UI flows that can bring the user here: 728 // There are several different UI flows that can bring the user here:
725 // 1) Signin promo. 729 // 1) Signin promo.
726 // 2) Normal signin through settings page (IsAuthenticated() is false). 730 // 2) Normal signin through settings page (IsAuthenticated() is false).
727 // 3) Previously working credentials have expired. 731 // 3) Previously working credentials have expired.
728 // 4) User is signed in, but has stopped sync via the google dashboard, and 732 // 4) User is signed in, but has stopped sync via the google dashboard, and
729 // signout is prohibited by policy so we need to force a re-auth. 733 // signout is prohibited by policy so we need to force a re-auth.
730 // 5) User clicks [Advanced Settings] button on options page while already 734 // 5) User clicks [Advanced Settings] button on options page while already
731 // logged in. 735 // logged in.
732 // 6) One-click signin (credentials are already available, so should display 736 // 6) One-click signin (credentials are already available, so should display
733 // sync configure UI, not login UI). 737 // sync configure UI, not login UI).
734 // 7) User re-enables sync after disabling it via advanced settings. 738 // 7) User re-enables sync after disabling it via advanced settings.
735 #if !defined(OS_CHROMEOS) 739 #if !defined(OS_CHROMEOS)
736 SigninManagerBase* signin = 740 SigninManagerBase* signin =
737 SigninManagerFactory::GetForProfile(GetProfile()); 741 SigninManagerFactory::GetForProfile(GetProfile());
738 742
739 if (!signin->IsAuthenticated() || 743 if (!signin->IsAuthenticated() ||
740 SigninErrorControllerFactory::GetForProfile(GetProfile())->HasError()) { 744 SigninErrorControllerFactory::GetForProfile(GetProfile())->HasError()) {
741 // User is not logged in (cases 1-2), or login has been specially requested 745 // User is not logged in (cases 1-2), or login has been specially requested
742 // because previously working credentials have expired (case 3). Close sync 746 // because previously working credentials have expired (case 3). Close sync
743 // setup including any visible overlays, and display the gaia auth page. 747 // setup including any visible overlays, and display the gaia auth page.
744 // Control will be returned to the sync settings page once auth is complete. 748 // Control will be returned to the sync settings page once auth is complete.
745 CloseUI(); 749 CloseUI();
746 DisplayGaiaLogin(); 750 if (args) {
751 std::string access_point = base::UTF16ToUTF8(ExtractStringValue(args));
752 if (access_point == "access-point-supervised-user") {
753 DisplayGaiaLogin(
754 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER);
755 return;
756 }
757 }
758 DisplayGaiaLogin(signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS);
747 return; 759 return;
748 } 760 }
749 #endif 761 #endif
750 if (!GetSyncService()) { 762 if (!GetSyncService()) {
751 // This can happen if the user directly navigates to /settings/syncSetup. 763 // This can happen if the user directly navigates to /settings/syncSetup.
752 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; 764 DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
753 CloseUI(); 765 CloseUI();
754 return; 766 return;
755 } 767 }
756 768
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 "SyncSetupOverlay.showSyncSetupPage", page, args); 931 "SyncSetupOverlay.showSyncSetupPage", page, args);
920 932
921 // Make sure the tab used for the Gaia sign in does not cover the settings 933 // Make sure the tab used for the Gaia sign in does not cover the settings
922 // tab. 934 // tab.
923 FocusUI(); 935 FocusUI();
924 } 936 }
925 937
926 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 938 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
927 return LoginUIServiceFactory::GetForProfile(GetProfile()); 939 return LoginUIServiceFactory::GetForProfile(GetProfile());
928 } 940 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/sync_setup_handler.h ('k') | chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698