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

Unified Diff: chrome/browser/ui/webui/settings/people_handler.cc

Issue 1960063003: Settings People Revamp: Update PeopleHandler to use JS lifecycle calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add AllowJavascript to unit test to allow it to pass Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/people_handler.cc
diff --git a/chrome/browser/ui/webui/settings/people_handler.cc b/chrome/browser/ui/webui/settings/people_handler.cc
index 6ad898f8719f055496a5bf57555290fe28a99641..1d00d3fbc399d297710d18575a8b6c8ae0ce2a8b 100644
--- a/chrome/browser/ui/webui/settings/people_handler.cc
+++ b/chrome/browser/ui/webui/settings/people_handler.cc
@@ -173,19 +173,7 @@ const char PeopleHandler::kPassphraseFailedPageStatus[] = "passphraseFailed";
PeopleHandler::PeopleHandler(Profile* profile)
: profile_(profile),
configuring_sync_(false),
- sync_service_observer_(this) {
- PrefService* prefs = profile_->GetPrefs();
- profile_pref_registrar_.Init(prefs);
- profile_pref_registrar_.Add(
- prefs::kSigninAllowed,
- base::Bind(&PeopleHandler::OnSigninAllowedPrefChange,
- base::Unretained(this)));
-
- ProfileSyncService* sync_service(
- ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
- if (sync_service)
- sync_service_observer_.Add(sync_service);
-}
+ sync_service_observer_(this) {}
PeopleHandler::~PeopleHandler() {
// Early exit if running unit tests (no actual WebUI is attached).
@@ -241,6 +229,25 @@ void PeopleHandler::RegisterMessages() {
#endif
}
+void PeopleHandler::OnJavascriptAllowed() {
+ PrefService* prefs = profile_->GetPrefs();
+ profile_pref_registrar_.Init(prefs);
+ profile_pref_registrar_.Add(
+ prefs::kSigninAllowed,
+ base::Bind(&PeopleHandler::OnSigninAllowedPrefChange,
+ base::Unretained(this)));
+
+ ProfileSyncService* sync_service(
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
+ if (sync_service)
+ sync_service_observer_.Add(sync_service);
+}
+
+void PeopleHandler::OnJavascriptDisallowed() {
+ profile_pref_registrar_.RemoveAll();
+ sync_service_observer_.RemoveAll();
+}
+
#if !defined(OS_CHROMEOS)
void PeopleHandler::DisplayGaiaLogin(signin_metrics::AccessPoint access_point) {
DCHECK(!sync_startup_tracker_);
@@ -330,9 +337,9 @@ void PeopleHandler::DisplaySpinner() {
base::TimeDelta::FromSeconds(kTimeoutSec), this,
&PeopleHandler::DisplayTimeout);
- web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
- base::StringValue("page-status-changed"),
- base::StringValue(kSpinnerPageStatus));
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("page-status-changed"),
+ base::StringValue(kSpinnerPageStatus));
}
// TODO(kochi): Handle error conditions other than timeout.
@@ -344,9 +351,9 @@ void PeopleHandler::DisplayTimeout() {
// Do not listen to sync startup events.
sync_startup_tracker_.reset();
- web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
- base::StringValue("page-status-changed"),
- base::StringValue(kTimeoutPageStatus));
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("page-status-changed"),
+ base::StringValue(kTimeoutPageStatus));
}
void PeopleHandler::OnDidClosePage(const base::ListValue* args) {
@@ -509,6 +516,8 @@ void PeopleHandler::HandleSetEncryption(const base::ListValue* args) {
}
void PeopleHandler::HandleShowSetupUI(const base::ListValue* args) {
+ AllowJavascript();
+
if (!GetSyncService()) {
CloseUI();
return;
@@ -707,9 +716,9 @@ void PeopleHandler::FocusUI() {
void PeopleHandler::CloseUI() {
CloseSyncSetup();
- web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
- base::StringValue("page-status-changed"),
- base::StringValue(kDonePageStatus));
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("page-status-changed"),
+ base::StringValue(kDonePageStatus));
}
void PeopleHandler::GoogleSigninSucceeded(const std::string& /* account_id */,
@@ -908,9 +917,8 @@ void PeopleHandler::PushSyncPrefs() {
GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA));
}
- web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
- base::StringValue("sync-prefs-changed"),
- args);
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("sync-prefs-changed"), args);
// Make sure the tab used for the Gaia sign in does not cover the settings
// tab.
@@ -922,9 +930,9 @@ LoginUIService* PeopleHandler::GetLoginUIService() const {
}
void PeopleHandler::UpdateSyncStatus() {
- web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
- base::StringValue("sync-status-changed"),
- *GetSyncStatusDictionary());
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("sync-status-changed"),
+ *GetSyncStatusDictionary());
}
void PeopleHandler::OnSigninAllowedPrefChange() {
« no previous file with comments | « chrome/browser/ui/webui/settings/people_handler.h ('k') | chrome/browser/ui/webui/settings/people_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698