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