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

Side by Side Diff: chrome/browser/ui/webui/settings/sync_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: 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings/sync_handler.h" 5 #include "chrome/browser/ui/webui/settings/sync_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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", 231 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing",
232 base::Bind(&SyncHandler::HandleStopSyncing, 232 base::Bind(&SyncHandler::HandleStopSyncing,
233 base::Unretained(this))); 233 base::Unretained(this)));
234 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn", 234 web_ui()->RegisterMessageCallback("SyncSetupStartSignIn",
235 base::Bind(&SyncHandler::HandleStartSignin, 235 base::Bind(&SyncHandler::HandleStartSignin,
236 base::Unretained(this))); 236 base::Unretained(this)));
237 #endif 237 #endif
238 } 238 }
239 239
240 #if !defined(OS_CHROMEOS) 240 #if !defined(OS_CHROMEOS)
241 void SyncHandler::DisplayGaiaLogin() { 241 void SyncHandler::DisplayGaiaLogin(signin_metrics::AccessPoint access_point) {
242 DCHECK(!sync_startup_tracker_); 242 DCHECK(!sync_startup_tracker_);
243 // Advanced options are no longer being configured if the login screen is 243 // Advanced options are no longer being configured if the login screen is
244 // visible. If the user exits the signin wizard after this without 244 // visible. If the user exits the signin wizard after this without
245 // configuring sync, CloseSyncSetup() will ensure they are logged out. 245 // configuring sync, CloseSyncSetup() will ensure they are logged out.
246 configuring_sync_ = false; 246 configuring_sync_ = false;
247 DisplayGaiaLoginInNewTabOrWindow(); 247 DisplayGaiaLoginInNewTabOrWindow(access_point);
248 } 248 }
249 249
250 void SyncHandler::DisplayGaiaLoginInNewTabOrWindow() { 250 void SyncHandler::DisplayGaiaLoginInNewTabOrWindow(
251 signin_metrics::AccessPoint access_point) {
251 Browser* browser = chrome::FindBrowserWithWebContents( 252 Browser* browser = chrome::FindBrowserWithWebContents(
252 web_ui()->GetWebContents()); 253 web_ui()->GetWebContents());
253 bool force_new_tab = false; 254 bool force_new_tab = false;
254 if (!browser) { 255 if (!browser) {
255 // Settings is not displayed in a browser window. Open a new window. 256 // Settings is not displayed in a browser window. Open a new window.
256 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile_, 257 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile_,
257 chrome::GetActiveDesktop())); 258 chrome::GetActiveDesktop()));
258 force_new_tab = true; 259 force_new_tab = true;
259 } 260 }
260 261
261 // If the signin manager already has an authenticated username, this is a 262 // If the signin manager already has an authenticated username, this is a
262 // re-auth scenario, and we need to ensure that the user signs in with the 263 // re-auth scenario, and we need to ensure that the user signs in with the
263 // same email address. 264 // same email address.
264 GURL url; 265 GURL url;
265 if (SigninManagerFactory::GetForProfile( 266 if (SigninManagerFactory::GetForProfile(
266 browser->profile())->IsAuthenticated()) { 267 browser->profile())->IsAuthenticated()) {
267 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", 268 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth",
268 signin_metrics::HISTOGRAM_REAUTH_SHOWN, 269 signin_metrics::HISTOGRAM_REAUTH_SHOWN,
269 signin_metrics::HISTOGRAM_REAUTH_MAX); 270 signin_metrics::HISTOGRAM_REAUTH_MAX);
270 271
271 SigninErrorController* error_controller = 272 SigninErrorController* error_controller =
272 SigninErrorControllerFactory::GetForProfile(browser->profile()); 273 SigninErrorControllerFactory::GetForProfile(browser->profile());
273 DCHECK(error_controller->HasError()); 274 DCHECK(error_controller->HasError());
274 if (!force_new_tab) { 275 if (!force_new_tab) {
275 browser->window()->ShowAvatarBubbleFromAvatarButton( 276 browser->window()->ShowAvatarBubbleFromAvatarButton(
276 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH, 277 BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH,
277 signin::ManageAccountsParams()); 278 signin::ManageAccountsParams(), access_point);
278 } else { 279 } else {
279 url = signin::GetReauthURL(browser->profile(), 280 url = signin::GetReauthURL(
280 error_controller->error_account_id()); 281 access_point, signin_metrics::REASON_REAUTHENTICATION,
282 browser->profile(), error_controller->error_account_id());
281 } 283 }
282 } else { 284 } else {
283 signin_metrics::LogSigninSource(signin_metrics::SOURCE_SETTINGS);
284 if (!force_new_tab) { 285 if (!force_new_tab) {
285 browser->window()->ShowAvatarBubbleFromAvatarButton( 286 browser->window()->ShowAvatarBubbleFromAvatarButton(
286 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN, 287 BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN,
287 signin::ManageAccountsParams()); 288 signin::ManageAccountsParams(), access_point);
288 } else { 289 } else {
289 url = signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true); 290 url = signin::GetPromoURL(
291 access_point, signin_metrics::REASON_SIGNIN_PRIMARY_ACCOUNT, true);
290 } 292 }
291 } 293 }
292 294
293 if (url.is_valid()) 295 if (url.is_valid())
294 chrome::ShowSingletonTab(browser, url); 296 chrome::ShowSingletonTab(browser, url);
295 } 297 }
296 #endif 298 #endif
297 299
298 bool SyncHandler::PrepareSyncSetup() { 300 bool SyncHandler::PrepareSyncSetup() {
299 // If the wizard is already visible, just focus that one. 301 // If the wizard is already visible, just focus that one.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // blank setup overlay on this page by showing the "done" page. This can 520 // blank setup overlay on this page by showing the "done" page. This can
519 // happen if the user navigates to chrome://settings/syncSetup in more than 521 // happen if the user navigates to chrome://settings/syncSetup in more than
520 // one tab. See crbug.com/261566. 522 // one tab. See crbug.com/261566.
521 // Note: The following block will transfer focus to the existing wizard. 523 // Note: The following block will transfer focus to the existing wizard.
522 if (IsExistingWizardPresent() && !IsActiveLogin()) 524 if (IsExistingWizardPresent() && !IsActiveLogin())
523 CloseUI(); 525 CloseUI();
524 526
525 // If a setup wizard is present on this page or another, bring it to focus. 527 // If a setup wizard is present on this page or another, bring it to focus.
526 // Otherwise, display a new one on this page. 528 // Otherwise, display a new one on this page.
527 if (!FocusExistingWizardIfPresent()) 529 if (!FocusExistingWizardIfPresent())
528 OpenSyncSetup(); 530 OpenSyncSetup(args);
529 } 531 }
530 532
531 #if defined(OS_CHROMEOS) 533 #if defined(OS_CHROMEOS)
532 // On ChromeOS, we need to sign out the user session to fix an auth error, so 534 // On ChromeOS, we need to sign out the user session to fix an auth error, so
533 // the user goes through the real signin flow to generate a new auth token. 535 // the user goes through the real signin flow to generate a new auth token.
534 void SyncHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { 536 void SyncHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) {
535 DVLOG(1) << "Signing out the user to fix a sync error."; 537 DVLOG(1) << "Signing out the user to fix a sync error.";
536 chrome::AttemptUserExit(); 538 chrome::AttemptUserExit();
537 } 539 }
538 #endif 540 #endif
539 541
540 #if !defined(OS_CHROMEOS) 542 #if !defined(OS_CHROMEOS)
541 void SyncHandler::HandleStartSignin(const base::ListValue* args) { 543 void SyncHandler::HandleStartSignin(const base::ListValue* args) {
542 // Should only be called if the user is not already signed in. 544 // Should only be called if the user is not already signed in.
543 DCHECK(!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); 545 DCHECK(!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated());
544 OpenSyncSetup(); 546 OpenSyncSetup(args);
545 } 547 }
546 548
547 void SyncHandler::HandleStopSyncing(const base::ListValue* args) { 549 void SyncHandler::HandleStopSyncing(const base::ListValue* args) {
548 if (GetSyncService()) 550 if (GetSyncService())
549 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 551 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
550 SigninManagerFactory::GetForProfile(profile_) 552 SigninManagerFactory::GetForProfile(profile_)
551 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); 553 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS);
552 554
553 bool delete_profile = false; 555 bool delete_profile = false;
554 if (args->GetBoolean(0, &delete_profile) && delete_profile) { 556 if (args->GetBoolean(0, &delete_profile) && delete_profile) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 612
611 // Alert the sync service anytime the sync setup dialog is closed. This can 613 // Alert the sync service anytime the sync setup dialog is closed. This can
612 // happen due to the user clicking the OK or Cancel button, or due to the 614 // happen due to the user clicking the OK or Cancel button, or due to the
613 // dialog being closed by virtue of sync being disabled in the background. 615 // dialog being closed by virtue of sync being disabled in the background.
614 if (sync_service) 616 if (sync_service)
615 sync_service->SetSetupInProgress(false); 617 sync_service->SetSetupInProgress(false);
616 618
617 configuring_sync_ = false; 619 configuring_sync_ = false;
618 } 620 }
619 621
620 void SyncHandler::OpenSyncSetup() { 622 void SyncHandler::OpenSyncSetup(const base::ListValue* args) {
621 if (!PrepareSyncSetup()) 623 if (!PrepareSyncSetup())
622 return; 624 return;
623 625
624 // There are several different UI flows that can bring the user here: 626 // There are several different UI flows that can bring the user here:
625 // 1) Signin promo. 627 // 1) Signin promo.
626 // 2) Normal signin through settings page (IsAuthenticated() is false). 628 // 2) Normal signin through settings page (IsAuthenticated() is false).
627 // 3) Previously working credentials have expired. 629 // 3) Previously working credentials have expired.
628 // 4) User is signed in, but has stopped sync via the google dashboard, and 630 // 4) User is signed in, but has stopped sync via the google dashboard, and
629 // signout is prohibited by policy so we need to force a re-auth. 631 // signout is prohibited by policy so we need to force a re-auth.
630 // 5) User clicks [Advanced Settings] button on options page while already 632 // 5) User clicks [Advanced Settings] button on options page while already
631 // logged in. 633 // logged in.
632 // 6) One-click signin (credentials are already available, so should display 634 // 6) One-click signin (credentials are already available, so should display
633 // sync configure UI, not login UI). 635 // sync configure UI, not login UI).
634 // 7) User re-enables sync after disabling it via advanced settings. 636 // 7) User re-enables sync after disabling it via advanced settings.
635 #if !defined(OS_CHROMEOS) 637 #if !defined(OS_CHROMEOS)
636 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); 638 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
637 639
638 if (!signin->IsAuthenticated() || 640 if (!signin->IsAuthenticated() ||
639 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { 641 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) {
640 // User is not logged in (cases 1-2), or login has been specially requested 642 // User is not logged in (cases 1-2), or login has been specially requested
641 // because previously working credentials have expired (case 3). Close sync 643 // because previously working credentials have expired (case 3). Close sync
642 // setup including any visible overlays, and display the gaia auth page. 644 // setup including any visible overlays, and display the gaia auth page.
643 // Control will be returned to the sync settings page once auth is complete. 645 // Control will be returned to the sync settings page once auth is complete.
644 CloseUI(); 646 CloseUI();
645 DisplayGaiaLogin(); 647 if (args != NULL) {
648 std::string access_point = base::UTF16ToUTF8(ExtractStringValue(args));
649 if (access_point == "access-point-supervised-user") {
650 DisplayGaiaLogin(signin_metrics::ACCESS_POINT_SUPERVISED_USER);
651 return;
652 }
653 }
654 DisplayGaiaLogin(signin_metrics::ACCESS_POINT_SETTINGS);
646 return; 655 return;
647 } 656 }
648 #endif 657 #endif
649 if (!GetSyncService()) { 658 if (!GetSyncService()) {
650 // This can happen if the user directly navigates to /settings/syncSetup. 659 // This can happen if the user directly navigates to /settings/syncSetup.
651 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; 660 DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
652 CloseUI(); 661 CloseUI();
653 return; 662 return;
654 } 663 }
655 664
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 void SyncHandler::UpdateSyncState() { 904 void SyncHandler::UpdateSyncState() {
896 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", 905 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus",
897 *GetSyncStateDictionary()); 906 *GetSyncStateDictionary());
898 } 907 }
899 908
900 void SyncHandler::OnSigninAllowedPrefChange() { 909 void SyncHandler::OnSigninAllowedPrefChange() {
901 UpdateSyncState(); 910 UpdateSyncState();
902 } 911 }
903 912
904 } // namespace settings 913 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698