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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 localized_strings->SetString( | 222 localized_strings->SetString( |
223 "encryptionHelpURL", chrome::kSyncEncryptionHelpURL); | 223 "encryptionHelpURL", chrome::kSyncEncryptionHelpURL); |
224 localized_strings->SetString( | 224 localized_strings->SetString( |
225 "passphraseEncryptionMessage", | 225 "passphraseEncryptionMessage", |
226 GetStringFUTF16(IDS_SYNC_PASSPHRASE_ENCRYPTION_MESSAGE, product_name)); | 226 GetStringFUTF16(IDS_SYNC_PASSPHRASE_ENCRYPTION_MESSAGE, product_name)); |
227 localized_strings->SetString( | 227 localized_strings->SetString( |
228 "passphraseRecover", | 228 "passphraseRecover", |
229 GetStringFUTF16(IDS_SYNC_PASSPHRASE_RECOVER, | 229 GetStringFUTF16(IDS_SYNC_PASSPHRASE_RECOVER, |
230 ASCIIToUTF16(google_util::StringAppendGoogleLocaleParam( | 230 ASCIIToUTF16(google_util::StringAppendGoogleLocaleParam( |
231 chrome::kSyncGoogleDashboardURL)))); | 231 chrome::kSyncGoogleDashboardURL)))); |
| 232 localized_strings->SetString("stopSyncingExplanation", |
| 233 l10n_util::GetStringFUTF16( |
| 234 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, |
| 235 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| 236 ASCIIToUTF16(google_util::StringAppendGoogleLocaleParam( |
| 237 chrome::kSyncGoogleDashboardURL)))); |
| 238 localized_strings->SetString("stopSyncingTitle", |
| 239 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE)); |
| 240 localized_strings->SetString("stopSyncingConfirm", |
| 241 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)); |
| 242 |
232 bool is_start_page = false; | 243 bool is_start_page = false; |
233 if (web_ui) { | 244 if (web_ui) { |
234 SyncPromoUI::Source source = SyncPromoUI::GetSourceForSyncPromoURL( | 245 SyncPromoUI::Source source = SyncPromoUI::GetSourceForSyncPromoURL( |
235 web_ui->GetWebContents()->GetURL()); | 246 web_ui->GetWebContents()->GetURL()); |
236 is_start_page = source == SyncPromoUI::SOURCE_START_PAGE; | 247 is_start_page = source == SyncPromoUI::SOURCE_START_PAGE; |
237 } | 248 } |
238 int title_id = is_start_page ? IDS_SYNC_PROMO_TITLE_SHORT : | 249 int title_id = is_start_page ? IDS_SYNC_PROMO_TITLE_SHORT : |
239 IDS_SYNC_PROMO_TITLE_EXISTING_USER; | 250 IDS_SYNC_PROMO_TITLE_EXISTING_USER; |
240 string16 short_product_name(GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 251 string16 short_product_name(GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
241 localized_strings->SetString( | 252 localized_strings->SetString( |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 base::Bind(&SyncSetupHandler::HandleAttachHandler, | 442 base::Bind(&SyncSetupHandler::HandleAttachHandler, |
432 base::Unretained(this))); | 443 base::Unretained(this))); |
433 web_ui()->RegisterMessageCallback( | 444 web_ui()->RegisterMessageCallback( |
434 "SyncSetupShowErrorUI", | 445 "SyncSetupShowErrorUI", |
435 base::Bind(&SyncSetupHandler::HandleShowErrorUI, | 446 base::Bind(&SyncSetupHandler::HandleShowErrorUI, |
436 base::Unretained(this))); | 447 base::Unretained(this))); |
437 web_ui()->RegisterMessageCallback( | 448 web_ui()->RegisterMessageCallback( |
438 "SyncSetupShowSetupUI", | 449 "SyncSetupShowSetupUI", |
439 base::Bind(&SyncSetupHandler::HandleShowSetupUI, | 450 base::Bind(&SyncSetupHandler::HandleShowSetupUI, |
440 base::Unretained(this))); | 451 base::Unretained(this))); |
| 452 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", |
| 453 base::Bind(&SyncSetupHandler::HandleStopSyncing, |
| 454 base::Unretained(this))); |
441 } | 455 } |
442 | 456 |
443 SigninManager* SyncSetupHandler::GetSignin() const { | 457 SigninManager* SyncSetupHandler::GetSignin() const { |
444 return SigninManagerFactory::GetForProfile(GetProfile()); | 458 return SigninManagerFactory::GetForProfile(GetProfile()); |
445 } | 459 } |
446 | 460 |
447 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { | 461 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { |
448 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); | 462 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); |
449 } | 463 } |
450 | 464 |
451 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( | 465 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( |
452 const string16& error_message, bool fatal_error) { | 466 const string16& error_message, bool fatal_error) { |
453 // We are no longer configuring sync if the login screen is visible. | 467 // We are no longer configuring sync if the login screen is visible. |
454 // If the user exits the signin wizard after this without configuring sync, | 468 // If the user exits the signin wizard after this without configuring sync, |
455 // CloseSyncSetup() will ensure they are logged out. | 469 // CloseSyncSetup() will ensure they are logged out. |
456 configuring_sync_ = false; | 470 configuring_sync_ = false; |
457 | 471 |
458 // Setup args for the GAIA login screen: | 472 // Setup args for the GAIA login screen: |
459 // error_message: custom error message to display. | 473 // error_message: custom error message to display. |
460 // fatalError: fatal error message to display. | 474 // fatalError: fatal error message to display. |
461 // error: GoogleServiceAuthError from previous login attempt (0 if none). | 475 // error: GoogleServiceAuthError from previous login attempt (0 if none). |
462 // user: The email the user most recently entered. | 476 // user: The email the user most recently entered. |
463 // editable_user: Whether the username field should be editable. | 477 // editable_user: Whether the username field should be editable. |
464 // captchaUrl: The captcha image to display to the user (empty if none). | 478 // captchaUrl: The captcha image to display to the user (empty if none). |
465 // TODO(atwilson): Convert all to unix_hacker style (http://crbug.com/119646). | |
466 std::string user, captcha; | 479 std::string user, captcha; |
467 int error; | 480 int error; |
468 bool editable_user; | 481 bool editable_user; |
469 if (!last_attempted_user_email_.empty()) { | 482 if (!last_attempted_user_email_.empty()) { |
470 // This is a repeat of a login attempt. | 483 // This is a repeat of a login attempt. |
471 user = last_attempted_user_email_; | 484 user = last_attempted_user_email_; |
472 error = last_signin_error_.state(); | 485 error = last_signin_error_.state(); |
473 captcha = last_signin_error_.captcha().image_url.spec(); | 486 captcha = last_signin_error_.captcha().image_url.spec(); |
474 editable_user = true; | 487 editable_user = true; |
475 } else { | 488 } else { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 #endif | 757 #endif |
745 | 758 |
746 service->ShowErrorUI(); | 759 service->ShowErrorUI(); |
747 } | 760 } |
748 | 761 |
749 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { | 762 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { |
750 DCHECK(!configuring_sync_); | 763 DCHECK(!configuring_sync_); |
751 OpenSyncSetup(false); | 764 OpenSyncSetup(false); |
752 } | 765 } |
753 | 766 |
| 767 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { |
| 768 ProfileSyncService* service = GetSyncService(); |
| 769 DCHECK(service); |
| 770 |
| 771 if (ProfileSyncService::IsSyncEnabled()) { |
| 772 service->DisableForUser(); |
| 773 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 774 } |
| 775 } |
| 776 |
754 void SyncSetupHandler::CloseSyncSetup() { | 777 void SyncSetupHandler::CloseSyncSetup() { |
755 // TODO(atwilson): Move UMA tracking of signin events out of sync module. | 778 // TODO(atwilson): Move UMA tracking of signin events out of sync module. |
756 if (IsActiveLogin()) { | 779 if (IsActiveLogin()) { |
757 ProfileSyncService* sync_service = GetSyncService(); | 780 ProfileSyncService* sync_service = GetSyncService(); |
758 if (!sync_service->HasSyncSetupCompleted()) { | 781 if (!sync_service->HasSyncSetupCompleted()) { |
759 if (signin_tracker_.get()) { | 782 if (signin_tracker_.get()) { |
760 ProfileSyncService::SyncEvent( | 783 ProfileSyncService::SyncEvent( |
761 ProfileSyncService::CANCEL_DURING_SIGNON); | 784 ProfileSyncService::CANCEL_DURING_SIGNON); |
762 } else if (configuring_sync_) { | 785 } else if (configuring_sync_) { |
763 ProfileSyncService::SyncEvent( | 786 ProfileSyncService::SyncEvent( |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 if (i != current_profile_index && AreUserNamesEqual( | 925 if (i != current_profile_index && AreUserNamesEqual( |
903 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 926 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
904 *error_message = l10n_util::GetStringUTF16( | 927 *error_message = l10n_util::GetStringUTF16( |
905 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 928 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
906 return false; | 929 return false; |
907 } | 930 } |
908 } | 931 } |
909 | 932 |
910 return true; | 933 return true; |
911 } | 934 } |
OLD | NEW |