| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::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::REASON_SIGNIN_PRIMARY_ACCOUNT, |
| 292 true); |
| 290 } | 293 } |
| 291 } | 294 } |
| 292 | 295 |
| 293 if (url.is_valid()) | 296 if (url.is_valid()) |
| 294 chrome::ShowSingletonTab(browser, url); | 297 chrome::ShowSingletonTab(browser, url); |
| 295 } | 298 } |
| 296 #endif | 299 #endif |
| 297 | 300 |
| 298 bool SyncHandler::PrepareSyncSetup() { | 301 bool SyncHandler::PrepareSyncSetup() { |
| 299 // If the wizard is already visible, just focus that one. | 302 // If the wizard is already visible, just focus that one. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 // blank setup overlay on this page by showing the "done" page. This can | 521 // 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 | 522 // happen if the user navigates to chrome://settings/syncSetup in more than |
| 520 // one tab. See crbug.com/261566. | 523 // one tab. See crbug.com/261566. |
| 521 // Note: The following block will transfer focus to the existing wizard. | 524 // Note: The following block will transfer focus to the existing wizard. |
| 522 if (IsExistingWizardPresent() && !IsActiveLogin()) | 525 if (IsExistingWizardPresent() && !IsActiveLogin()) |
| 523 CloseUI(); | 526 CloseUI(); |
| 524 | 527 |
| 525 // If a setup wizard is present on this page or another, bring it to focus. | 528 // If a setup wizard is present on this page or another, bring it to focus. |
| 526 // Otherwise, display a new one on this page. | 529 // Otherwise, display a new one on this page. |
| 527 if (!FocusExistingWizardIfPresent()) | 530 if (!FocusExistingWizardIfPresent()) |
| 528 OpenSyncSetup(); | 531 OpenSyncSetup(args); |
| 529 } | 532 } |
| 530 | 533 |
| 531 #if defined(OS_CHROMEOS) | 534 #if defined(OS_CHROMEOS) |
| 532 // On ChromeOS, we need to sign out the user session to fix an auth error, so | 535 // 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. | 536 // the user goes through the real signin flow to generate a new auth token. |
| 534 void SyncHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { | 537 void SyncHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { |
| 535 DVLOG(1) << "Signing out the user to fix a sync error."; | 538 DVLOG(1) << "Signing out the user to fix a sync error."; |
| 536 chrome::AttemptUserExit(); | 539 chrome::AttemptUserExit(); |
| 537 } | 540 } |
| 538 #endif | 541 #endif |
| 539 | 542 |
| 540 #if !defined(OS_CHROMEOS) | 543 #if !defined(OS_CHROMEOS) |
| 541 void SyncHandler::HandleStartSignin(const base::ListValue* args) { | 544 void SyncHandler::HandleStartSignin(const base::ListValue* args) { |
| 542 // Should only be called if the user is not already signed in. | 545 // Should only be called if the user is not already signed in. |
| 543 DCHECK(!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); | 546 DCHECK(!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); |
| 544 OpenSyncSetup(); | 547 OpenSyncSetup(args); |
| 545 } | 548 } |
| 546 | 549 |
| 547 void SyncHandler::HandleStopSyncing(const base::ListValue* args) { | 550 void SyncHandler::HandleStopSyncing(const base::ListValue* args) { |
| 548 if (GetSyncService()) | 551 if (GetSyncService()) |
| 549 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 552 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 550 SigninManagerFactory::GetForProfile(profile_) | 553 SigninManagerFactory::GetForProfile(profile_) |
| 551 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); | 554 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); |
| 552 | 555 |
| 553 bool delete_profile = false; | 556 bool delete_profile = false; |
| 554 if (args->GetBoolean(0, &delete_profile) && delete_profile) { | 557 if (args->GetBoolean(0, &delete_profile) && delete_profile) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 613 |
| 611 // Alert the sync service anytime the sync setup dialog is closed. This can | 614 // 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 | 615 // 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. | 616 // dialog being closed by virtue of sync being disabled in the background. |
| 614 if (sync_service) | 617 if (sync_service) |
| 615 sync_service->SetSetupInProgress(false); | 618 sync_service->SetSetupInProgress(false); |
| 616 | 619 |
| 617 configuring_sync_ = false; | 620 configuring_sync_ = false; |
| 618 } | 621 } |
| 619 | 622 |
| 620 void SyncHandler::OpenSyncSetup() { | 623 void SyncHandler::OpenSyncSetup(const base::ListValue* args) { |
| 621 if (!PrepareSyncSetup()) | 624 if (!PrepareSyncSetup()) |
| 622 return; | 625 return; |
| 623 | 626 |
| 624 // There are several different UI flows that can bring the user here: | 627 // There are several different UI flows that can bring the user here: |
| 625 // 1) Signin promo. | 628 // 1) Signin promo. |
| 626 // 2) Normal signin through settings page (IsAuthenticated() is false). | 629 // 2) Normal signin through settings page (IsAuthenticated() is false). |
| 627 // 3) Previously working credentials have expired. | 630 // 3) Previously working credentials have expired. |
| 628 // 4) User is signed in, but has stopped sync via the google dashboard, and | 631 // 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. | 632 // 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 | 633 // 5) User clicks [Advanced Settings] button on options page while already |
| 631 // logged in. | 634 // logged in. |
| 632 // 6) One-click signin (credentials are already available, so should display | 635 // 6) One-click signin (credentials are already available, so should display |
| 633 // sync configure UI, not login UI). | 636 // sync configure UI, not login UI). |
| 634 // 7) User re-enables sync after disabling it via advanced settings. | 637 // 7) User re-enables sync after disabling it via advanced settings. |
| 635 #if !defined(OS_CHROMEOS) | 638 #if !defined(OS_CHROMEOS) |
| 636 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); | 639 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); |
| 637 | 640 |
| 638 if (!signin->IsAuthenticated() || | 641 if (!signin->IsAuthenticated() || |
| 639 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | 642 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
| 640 // User is not logged in (cases 1-2), or login has been specially requested | 643 // 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 | 644 // because previously working credentials have expired (case 3). Close sync |
| 642 // setup including any visible overlays, and display the gaia auth page. | 645 // 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. | 646 // Control will be returned to the sync settings page once auth is complete. |
| 644 CloseUI(); | 647 CloseUI(); |
| 645 DisplayGaiaLogin(); | 648 if (args) { |
| 649 std::string access_point = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 650 if (access_point == "access-point-supervised-user") { |
| 651 DisplayGaiaLogin( |
| 652 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER); |
| 653 return; |
| 654 } |
| 655 } |
| 656 DisplayGaiaLogin(signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); |
| 646 return; | 657 return; |
| 647 } | 658 } |
| 648 #endif | 659 #endif |
| 649 if (!GetSyncService()) { | 660 if (!GetSyncService()) { |
| 650 // This can happen if the user directly navigates to /settings/syncSetup. | 661 // This can happen if the user directly navigates to /settings/syncSetup. |
| 651 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 662 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 652 CloseUI(); | 663 CloseUI(); |
| 653 return; | 664 return; |
| 654 } | 665 } |
| 655 | 666 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 void SyncHandler::UpdateSyncState() { | 906 void SyncHandler::UpdateSyncState() { |
| 896 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", | 907 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", |
| 897 *GetSyncStateDictionary()); | 908 *GetSyncStateDictionary()); |
| 898 } | 909 } |
| 899 | 910 |
| 900 void SyncHandler::OnSigninAllowedPrefChange() { | 911 void SyncHandler::OnSigninAllowedPrefChange() { |
| 901 UpdateSyncState(); | 912 UpdateSyncState(); |
| 902 } | 913 } |
| 903 | 914 |
| 904 } // namespace settings | 915 } // namespace settings |
| OLD | NEW |