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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 10539128: Set timeout in sync setup (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed commented points Created 8 years, 6 months 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 (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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 localized_strings->SetString("createAccountLinkHTML", 277 localized_strings->SetString("createAccountLinkHTML",
278 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); 278 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account));
279 279
280 string16 sync_benefits_url( 280 string16 sync_benefits_url(
281 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( 281 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam(
282 chrome::kSyncLearnMoreURL))); 282 chrome::kSyncLearnMoreURL)));
283 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); 283 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url);
284 284
285 static OptionsStringResource resources[] = { 285 static OptionsStringResource resources[] = {
286 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, 286 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE },
287 { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE },
288 { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT },
287 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, 289 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK },
288 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, 290 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE },
289 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, 291 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE },
290 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, 292 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS },
291 { "signin", IDS_SYNC_SIGNIN }, 293 { "signin", IDS_SYNC_SIGNIN },
292 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, 294 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT },
293 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, 295 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR },
294 { "errorLearnMore", IDS_LEARN_MORE }, 296 { "errorLearnMore", IDS_LEARN_MORE },
295 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, 297 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL },
296 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, 298 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT },
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 StringValue page("login"); 531 StringValue page("login");
530 web_ui()->CallJavascriptFunction( 532 web_ui()->CallJavascriptFunction(
531 "SyncSetupOverlay.showSyncSetupPage", page, args); 533 "SyncSetupOverlay.showSyncSetupPage", page, args);
532 } 534 }
533 535
534 // TODO(kochi): Handle error conditions (timeout, other failures). 536 // TODO(kochi): Handle error conditions (timeout, other failures).
535 void SyncSetupHandler::DisplaySpinner() { 537 void SyncSetupHandler::DisplaySpinner() {
536 configuring_sync_ = true; 538 configuring_sync_ = true;
537 StringValue page("spinner"); 539 StringValue page("spinner");
538 DictionaryValue args; 540 DictionaryValue args;
541
542 const int kTimeoutSec = 30;
543 backend_start_timer_.reset(new base::OneShotTimer<SyncSetupHandler>());
544 backend_start_timer_->Start(FROM_HERE,
545 base::TimeDelta::FromSeconds(kTimeoutSec),
546 this, &SyncSetupHandler::DisplayTimeout);
539 web_ui()->CallJavascriptFunction( 547 web_ui()->CallJavascriptFunction(
540 "SyncSetupOverlay.showSyncSetupPage", page, args); 548 "SyncSetupOverlay.showSyncSetupPage", page, args);
541 } 549 }
550
551 // TODO(kochi): Handle error conditions other than timeout.
552 // http://crbug.com/128692
553 void SyncSetupHandler::DisplayTimeout() {
554 configuring_sync_ = false;
555 StringValue page("timeout");
556 DictionaryValue args;
557
Andrew T Wilson (Slow) 2012/06/15 23:29:40 This doesn't seem to cancel sync initialization. W
peria 2012/06/18 05:15:48 No, it does not cancel initialization. In such cas
558 web_ui()->CallJavascriptFunction(
559 "SyncSetupOverlay.showSyncSetupPage", page, args);
560 }
542 561
543 void SyncSetupHandler::RecordSignin() { 562 void SyncSetupHandler::RecordSignin() {
544 // By default, do nothing - subclasses can override. 563 // By default, do nothing - subclasses can override.
545 } 564 }
546 565
547 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { 566 void SyncSetupHandler::DisplayGaiaSuccessAndClose() {
548 RecordSignin(); 567 RecordSignin();
549 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); 568 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose");
550 } 569 }
551 570
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 674 }
656 675
657 void SyncSetupHandler::GaiaCredentialsValid() { 676 void SyncSetupHandler::GaiaCredentialsValid() {
658 DCHECK(IsActiveLogin()); 677 DCHECK(IsActiveLogin());
659 678
660 // Gaia credentials are valid - update the UI. 679 // Gaia credentials are valid - update the UI.
661 DisplayGaiaSuccessAndSettingUp(); 680 DisplayGaiaSuccessAndSettingUp();
662 } 681 }
663 682
664 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { 683 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) {
684 // Stop a timer to handle timeout in waiting for checking network connection.
685 if (backend_start_timer_.get())
686 backend_start_timer_.reset();
687
665 last_signin_error_ = error; 688 last_signin_error_ = error;
666 // Got a failed signin - this is either just a typical auth error, or a 689 // Got a failed signin - this is either just a typical auth error, or a
667 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). 690 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors).
668 // On ChromeOS, this condition should trigger the orange badge on wrench menu 691 // On ChromeOS, this condition should trigger the orange badge on wrench menu
669 // and prompt to sign out. 692 // and prompt to sign out.
670 #if !defined(OS_CHROMEOS) 693 #if !defined(OS_CHROMEOS)
671 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); 694 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected());
672 #else 695 #else
673 CloseOverlay(); 696 CloseOverlay();
674 #endif 697 #endif
675 } 698 }
676 699
677 Profile* SyncSetupHandler::GetProfile() const { 700 Profile* SyncSetupHandler::GetProfile() const {
678 return Profile::FromWebUI(web_ui()); 701 return Profile::FromWebUI(web_ui());
679 } 702 }
680 703
681 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 704 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
682 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); 705 return ProfileSyncServiceFactory::GetForProfile(GetProfile());
683 } 706 }
684 707
685 void SyncSetupHandler::SigninSuccess() { 708 void SyncSetupHandler::SigninSuccess() {
686 DCHECK(GetSyncService()->sync_initialized()); 709 DCHECK(GetSyncService()->sync_initialized());
710 // Stop a timer to handle timeout in waiting for checking network connection.
711 if (backend_start_timer_.get())
712 backend_start_timer_.reset();
713
687 // If we have signed in while sync is already setup, it must be due to some 714 // If we have signed in while sync is already setup, it must be due to some
688 // kind of re-authentication flow. In that case, just close the signin dialog 715 // kind of re-authentication flow. In that case, just close the signin dialog
689 // rather than forcing the user to go through sync configuration. 716 // rather than forcing the user to go through sync configuration.
690 if (GetSyncService()->HasSyncSetupCompleted()) 717 if (GetSyncService()->HasSyncSetupCompleted())
691 DisplayGaiaSuccessAndClose(); 718 DisplayGaiaSuccessAndClose();
692 else 719 else
693 DisplayConfigureSync(false, false); 720 DisplayConfigureSync(false, false);
694 } 721 }
695 722
696 void SyncSetupHandler::HandleConfigure(const ListValue* args) { 723 void SyncSetupHandler::HandleConfigure(const ListValue* args) {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 if (i != current_profile_index && AreUserNamesEqual( 1048 if (i != current_profile_index && AreUserNamesEqual(
1022 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1049 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1023 *error_message = l10n_util::GetStringUTF16( 1050 *error_message = l10n_util::GetStringUTF16(
1024 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1051 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1025 return false; 1052 return false;
1026 } 1053 }
1027 } 1054 }
1028 1055
1029 return true; 1056 return true;
1030 } 1057 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698