| OLD | NEW |
| 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/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA }, | 303 { "fullEncryptionOption", IDS_SYNC_FULL_ENCRYPTION_DATA }, |
| 304 }; | 304 }; |
| 305 | 305 |
| 306 RegisterStrings(localized_strings, resources, arraysize(resources)); | 306 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 307 RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE); | 307 RegisterTitle(localized_strings, "syncSetupOverlay", IDS_SYNC_SETUP_TITLE); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void SyncSetupHandler::DisplayConfigureSync(bool show_advanced, | 310 void SyncSetupHandler::DisplayConfigureSync(bool show_advanced, |
| 311 bool passphrase_failed) { | 311 bool passphrase_failed) { |
| 312 // Should never call this when we are not signed in. | 312 // Should never call this when we are not signed in. |
| 313 DCHECK(!SigninManagerFactory::GetForProfile( | 313 DCHECK(SigninManagerFactory::GetForProfile( |
| 314 GetProfile())->GetAuthenticatedUsername().empty()); | 314 GetProfile())->IsAuthenticated()); |
| 315 ProfileSyncService* service = GetSyncService(); | 315 ProfileSyncService* service = GetSyncService(); |
| 316 DCHECK(service); | 316 DCHECK(service); |
| 317 if (!service->sync_initialized()) { | 317 if (!service->sync_initialized()) { |
| 318 service->UnsuppressAndStart(); | 318 service->UnsuppressAndStart(); |
| 319 | 319 |
| 320 // See if it's even possible to bring up the sync backend - if not | 320 // See if it's even possible to bring up the sync backend - if not |
| 321 // (unrecoverable error?), don't bother displaying a spinner that will be | 321 // (unrecoverable error?), don't bother displaying a spinner that will be |
| 322 // immediately closed because this leads to some ugly infinite UI loop (see | 322 // immediately closed because this leads to some ugly infinite UI loop (see |
| 323 // http://crbug.com/244769). | 323 // http://crbug.com/244769). |
| 324 if (SyncStartupTracker::GetSyncServiceState(GetProfile()) != | 324 if (SyncStartupTracker::GetSyncServiceState(GetProfile()) != |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 if (!browser) { | 513 if (!browser) { |
| 514 // Settings is not displayed in a browser window. Open a new window. | 514 // Settings is not displayed in a browser window. Open a new window. |
| 515 browser = new Browser(Browser::CreateParams( | 515 browser = new Browser(Browser::CreateParams( |
| 516 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); | 516 Browser::TYPE_TABBED, GetProfile(), chrome::GetActiveDesktop())); |
| 517 } | 517 } |
| 518 | 518 |
| 519 // If the signin manager already has an authenticated username, this is a | 519 // If the signin manager already has an authenticated username, this is a |
| 520 // re-auth scenario, and we need to ensure that the user signs in with the | 520 // re-auth scenario, and we need to ensure that the user signs in with the |
| 521 // same email address. | 521 // same email address. |
| 522 GURL url; | 522 GURL url; |
| 523 std::string email = SigninManagerFactory::GetForProfile( | 523 if (SigninManagerFactory::GetForProfile( |
| 524 browser->profile())->GetAuthenticatedUsername(); | 524 browser->profile())->IsAuthenticated()) { |
| 525 if (!email.empty()) { | |
| 526 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", | 525 UMA_HISTOGRAM_ENUMERATION("Signin.Reauth", |
| 527 signin::HISTOGRAM_SHOWN, | 526 signin::HISTOGRAM_SHOWN, |
| 528 signin::HISTOGRAM_MAX); | 527 signin::HISTOGRAM_MAX); |
| 529 | 528 |
| 530 SigninErrorController* error_controller = | 529 SigninErrorController* error_controller = |
| 531 ProfileOAuth2TokenServiceFactory::GetForProfile(browser->profile())-> | 530 ProfileOAuth2TokenServiceFactory::GetForProfile(browser->profile())-> |
| 532 signin_error_controller(); | 531 signin_error_controller(); |
| 533 DCHECK(error_controller->HasError()); | 532 DCHECK(error_controller->HasError()); |
| 534 if (switches::IsNewAvatarMenu()) { | 533 if (switches::IsNewAvatarMenu()) { |
| 535 browser->window()->ShowAvatarBubbleFromAvatarButton( | 534 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 | 760 |
| 762 void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) { | 761 void SyncSetupHandler::HandleShowSetupUI(const base::ListValue* args) { |
| 763 if (!GetSyncService()) { | 762 if (!GetSyncService()) { |
| 764 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 763 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 765 CloseUI(); | 764 CloseUI(); |
| 766 return; | 765 return; |
| 767 } | 766 } |
| 768 | 767 |
| 769 SigninManagerBase* signin = | 768 SigninManagerBase* signin = |
| 770 SigninManagerFactory::GetForProfile(GetProfile()); | 769 SigninManagerFactory::GetForProfile(GetProfile()); |
| 771 if (signin->GetAuthenticatedUsername().empty()) { | 770 if (!signin->IsAuthenticated()) { |
| 772 // For web-based signin, the signin page is not displayed in an overlay | 771 // For web-based signin, the signin page is not displayed in an overlay |
| 773 // on the settings page. So if we get here, it must be due to the user | 772 // on the settings page. So if we get here, it must be due to the user |
| 774 // cancelling signin (by reloading the sync settings page during initial | 773 // cancelling signin (by reloading the sync settings page during initial |
| 775 // signin) or by directly navigating to settings/syncSetup | 774 // signin) or by directly navigating to settings/syncSetup |
| 776 // (http://crbug.com/229836). So just exit and go back to the settings page. | 775 // (http://crbug.com/229836). So just exit and go back to the settings page. |
| 777 DLOG(WARNING) << "Cannot display sync setup UI when not signed in"; | 776 DLOG(WARNING) << "Cannot display sync setup UI when not signed in"; |
| 778 CloseUI(); | 777 CloseUI(); |
| 779 return; | 778 return; |
| 780 } | 779 } |
| 781 | 780 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 799 // the user goes through the real signin flow to generate a new auth token. | 798 // the user goes through the real signin flow to generate a new auth token. |
| 800 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { | 799 void SyncSetupHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { |
| 801 DVLOG(1) << "Signing out the user to fix a sync error."; | 800 DVLOG(1) << "Signing out the user to fix a sync error."; |
| 802 chrome::AttemptUserExit(); | 801 chrome::AttemptUserExit(); |
| 803 } | 802 } |
| 804 #endif | 803 #endif |
| 805 | 804 |
| 806 #if !defined(OS_CHROMEOS) | 805 #if !defined(OS_CHROMEOS) |
| 807 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) { | 806 void SyncSetupHandler::HandleStartSignin(const base::ListValue* args) { |
| 808 // Should only be called if the user is not already signed in. | 807 // Should only be called if the user is not already signed in. |
| 809 DCHECK(SigninManagerFactory::GetForProfile(GetProfile())-> | 808 DCHECK(!SigninManagerFactory::GetForProfile(GetProfile())-> |
| 810 GetAuthenticatedUsername().empty()); | 809 IsAuthenticated()); |
| 811 OpenSyncSetup(); | 810 OpenSyncSetup(); |
| 812 } | 811 } |
| 813 | 812 |
| 814 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) { | 813 void SyncSetupHandler::HandleStopSyncing(const base::ListValue* args) { |
| 815 if (GetSyncService()) | 814 if (GetSyncService()) |
| 816 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 815 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 817 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( | 816 SigninManagerFactory::GetForProfile(GetProfile())->SignOut( |
| 818 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); | 817 signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); |
| 819 | 818 |
| 820 bool delete_profile = false; | 819 bool delete_profile = false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 | 878 |
| 880 configuring_sync_ = false; | 879 configuring_sync_ = false; |
| 881 } | 880 } |
| 882 | 881 |
| 883 void SyncSetupHandler::OpenSyncSetup() { | 882 void SyncSetupHandler::OpenSyncSetup() { |
| 884 if (!PrepareSyncSetup()) | 883 if (!PrepareSyncSetup()) |
| 885 return; | 884 return; |
| 886 | 885 |
| 887 // There are several different UI flows that can bring the user here: | 886 // There are several different UI flows that can bring the user here: |
| 888 // 1) Signin promo. | 887 // 1) Signin promo. |
| 889 // 2) Normal signin through settings page (GetAuthenticatedUsername() is | 888 // 2) Normal signin through settings page (IsAuthenticated() is false). |
| 890 // empty). | |
| 891 // 3) Previously working credentials have expired. | 889 // 3) Previously working credentials have expired. |
| 892 // 4) User is signed in, but has stopped sync via the google dashboard, and | 890 // 4) User is signed in, but has stopped sync via the google dashboard, and |
| 893 // signout is prohibited by policy so we need to force a re-auth. | 891 // signout is prohibited by policy so we need to force a re-auth. |
| 894 // 5) User clicks [Advanced Settings] button on options page while already | 892 // 5) User clicks [Advanced Settings] button on options page while already |
| 895 // logged in. | 893 // logged in. |
| 896 // 6) One-click signin (credentials are already available, so should display | 894 // 6) One-click signin (credentials are already available, so should display |
| 897 // sync configure UI, not login UI). | 895 // sync configure UI, not login UI). |
| 898 // 7) User re-enables sync after disabling it via advanced settings. | 896 // 7) User re-enables sync after disabling it via advanced settings. |
| 899 #if !defined(OS_CHROMEOS) | 897 #if !defined(OS_CHROMEOS) |
| 900 SigninManagerBase* signin = | 898 SigninManagerBase* signin = |
| 901 SigninManagerFactory::GetForProfile(GetProfile()); | 899 SigninManagerFactory::GetForProfile(GetProfile()); |
| 902 | 900 |
| 903 if (signin->GetAuthenticatedUsername().empty() || | 901 if (!signin->IsAuthenticated() || |
| 904 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile())-> | 902 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile())-> |
| 905 signin_error_controller()->HasError()) { | 903 signin_error_controller()->HasError()) { |
| 906 // User is not logged in (cases 1-2), or login has been specially requested | 904 // User is not logged in (cases 1-2), or login has been specially requested |
| 907 // because previously working credentials have expired (case 3). Close sync | 905 // because previously working credentials have expired (case 3). Close sync |
| 908 // setup including any visible overlays, and display the gaia auth page. | 906 // setup including any visible overlays, and display the gaia auth page. |
| 909 // Control will be returned to the sync settings page once auth is complete. | 907 // Control will be returned to the sync settings page once auth is complete. |
| 910 CloseUI(); | 908 CloseUI(); |
| 911 DisplayGaiaLogin(); | 909 DisplayGaiaLogin(); |
| 912 return; | 910 return; |
| 913 } | 911 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 | 955 |
| 958 LoginUIService* service = GetLoginUIService(); | 956 LoginUIService* service = GetLoginUIService(); |
| 959 DCHECK(service); | 957 DCHECK(service); |
| 960 service->current_login_ui()->FocusUI(); | 958 service->current_login_ui()->FocusUI(); |
| 961 return true; | 959 return true; |
| 962 } | 960 } |
| 963 | 961 |
| 964 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 962 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
| 965 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 963 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
| 966 } | 964 } |
| OLD | NEW |