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

Side by Side 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 unified diff | Download patch
OLDNEW
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/people_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // static 166 // static
167 const char PeopleHandler::kSpinnerPageStatus[] = "spinner"; 167 const char PeopleHandler::kSpinnerPageStatus[] = "spinner";
168 const char PeopleHandler::kConfigurePageStatus[] = "configure"; 168 const char PeopleHandler::kConfigurePageStatus[] = "configure";
169 const char PeopleHandler::kTimeoutPageStatus[] = "timeout"; 169 const char PeopleHandler::kTimeoutPageStatus[] = "timeout";
170 const char PeopleHandler::kDonePageStatus[] = "done"; 170 const char PeopleHandler::kDonePageStatus[] = "done";
171 const char PeopleHandler::kPassphraseFailedPageStatus[] = "passphraseFailed"; 171 const char PeopleHandler::kPassphraseFailedPageStatus[] = "passphraseFailed";
172 172
173 PeopleHandler::PeopleHandler(Profile* profile) 173 PeopleHandler::PeopleHandler(Profile* profile)
174 : profile_(profile), 174 : profile_(profile),
175 configuring_sync_(false), 175 configuring_sync_(false),
176 sync_service_observer_(this) { 176 sync_service_observer_(this) {}
177 PrefService* prefs = profile_->GetPrefs();
178 profile_pref_registrar_.Init(prefs);
179 profile_pref_registrar_.Add(
180 prefs::kSigninAllowed,
181 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange,
182 base::Unretained(this)));
183
184 ProfileSyncService* sync_service(
185 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
186 if (sync_service)
187 sync_service_observer_.Add(sync_service);
188 }
189 177
190 PeopleHandler::~PeopleHandler() { 178 PeopleHandler::~PeopleHandler() {
191 // Early exit if running unit tests (no actual WebUI is attached). 179 // Early exit if running unit tests (no actual WebUI is attached).
192 if (!web_ui()) 180 if (!web_ui())
193 return; 181 return;
194 182
195 // This case is hit when the user performs a back navigation. 183 // This case is hit when the user performs a back navigation.
196 CloseSyncSetup(); 184 CloseSyncSetup();
197 } 185 }
198 186
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 #else 222 #else
235 web_ui()->RegisterMessageCallback( 223 web_ui()->RegisterMessageCallback(
236 "SyncSetupStopSyncing", 224 "SyncSetupStopSyncing",
237 base::Bind(&PeopleHandler::HandleStopSyncing, base::Unretained(this))); 225 base::Bind(&PeopleHandler::HandleStopSyncing, base::Unretained(this)));
238 web_ui()->RegisterMessageCallback( 226 web_ui()->RegisterMessageCallback(
239 "SyncSetupStartSignIn", 227 "SyncSetupStartSignIn",
240 base::Bind(&PeopleHandler::HandleStartSignin, base::Unretained(this))); 228 base::Bind(&PeopleHandler::HandleStartSignin, base::Unretained(this)));
241 #endif 229 #endif
242 } 230 }
243 231
232 void PeopleHandler::OnJavascriptAllowed() {
233 PrefService* prefs = profile_->GetPrefs();
234 profile_pref_registrar_.Init(prefs);
235 profile_pref_registrar_.Add(
236 prefs::kSigninAllowed,
237 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange,
238 base::Unretained(this)));
239
240 ProfileSyncService* sync_service(
241 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
242 if (sync_service)
243 sync_service_observer_.Add(sync_service);
244 }
245
246 void PeopleHandler::OnJavascriptDisallowed() {
247 profile_pref_registrar_.RemoveAll();
248 sync_service_observer_.RemoveAll();
249 }
250
244 #if !defined(OS_CHROMEOS) 251 #if !defined(OS_CHROMEOS)
245 void PeopleHandler::DisplayGaiaLogin(signin_metrics::AccessPoint access_point) { 252 void PeopleHandler::DisplayGaiaLogin(signin_metrics::AccessPoint access_point) {
246 DCHECK(!sync_startup_tracker_); 253 DCHECK(!sync_startup_tracker_);
247 // Advanced options are no longer being configured if the login screen is 254 // Advanced options are no longer being configured if the login screen is
248 // visible. If the user exits the signin wizard after this without 255 // visible. If the user exits the signin wizard after this without
249 // configuring sync, CloseSyncSetup() will ensure they are logged out. 256 // configuring sync, CloseSyncSetup() will ensure they are logged out.
250 configuring_sync_ = false; 257 configuring_sync_ = false;
251 DisplayGaiaLoginInNewTabOrWindow(access_point); 258 DisplayGaiaLoginInNewTabOrWindow(access_point);
252 } 259 }
253 260
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 void PeopleHandler::DisplaySpinner() { 330 void PeopleHandler::DisplaySpinner() {
324 configuring_sync_ = true; 331 configuring_sync_ = true;
325 332
326 const int kTimeoutSec = 30; 333 const int kTimeoutSec = 30;
327 DCHECK(!backend_start_timer_); 334 DCHECK(!backend_start_timer_);
328 backend_start_timer_.reset(new base::OneShotTimer()); 335 backend_start_timer_.reset(new base::OneShotTimer());
329 backend_start_timer_->Start(FROM_HERE, 336 backend_start_timer_->Start(FROM_HERE,
330 base::TimeDelta::FromSeconds(kTimeoutSec), this, 337 base::TimeDelta::FromSeconds(kTimeoutSec), this,
331 &PeopleHandler::DisplayTimeout); 338 &PeopleHandler::DisplayTimeout);
332 339
333 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 340 CallJavascriptFunction("cr.webUIListenerCallback",
334 base::StringValue("page-status-changed"), 341 base::StringValue("page-status-changed"),
335 base::StringValue(kSpinnerPageStatus)); 342 base::StringValue(kSpinnerPageStatus));
336 } 343 }
337 344
338 // TODO(kochi): Handle error conditions other than timeout. 345 // TODO(kochi): Handle error conditions other than timeout.
339 // http://crbug.com/128692 346 // http://crbug.com/128692
340 void PeopleHandler::DisplayTimeout() { 347 void PeopleHandler::DisplayTimeout() {
341 // Stop a timer to handle timeout in waiting for checking network connection. 348 // Stop a timer to handle timeout in waiting for checking network connection.
342 backend_start_timer_.reset(); 349 backend_start_timer_.reset();
343 350
344 // Do not listen to sync startup events. 351 // Do not listen to sync startup events.
345 sync_startup_tracker_.reset(); 352 sync_startup_tracker_.reset();
346 353
347 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 354 CallJavascriptFunction("cr.webUIListenerCallback",
348 base::StringValue("page-status-changed"), 355 base::StringValue("page-status-changed"),
349 base::StringValue(kTimeoutPageStatus)); 356 base::StringValue(kTimeoutPageStatus));
350 } 357 }
351 358
352 void PeopleHandler::OnDidClosePage(const base::ListValue* args) { 359 void PeopleHandler::OnDidClosePage(const base::ListValue* args) {
353 CloseSyncSetup(); 360 CloseSyncSetup();
354 } 361 }
355 362
356 void PeopleHandler::SyncStartupFailed() { 363 void PeopleHandler::SyncStartupFailed() {
357 // Stop a timer to handle timeout in waiting for checking network connection. 364 // Stop a timer to handle timeout in waiting for checking network connection.
358 backend_start_timer_.reset(); 365 backend_start_timer_.reset();
359 366
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 base::StringValue(kConfigurePageStatus)); 509 base::StringValue(kConfigurePageStatus));
503 } 510 }
504 511
505 if (configuration.encrypt_all) 512 if (configuration.encrypt_all)
506 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); 513 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT);
507 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty()) 514 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty())
508 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); 515 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE);
509 } 516 }
510 517
511 void PeopleHandler::HandleShowSetupUI(const base::ListValue* args) { 518 void PeopleHandler::HandleShowSetupUI(const base::ListValue* args) {
519 AllowJavascript();
520
512 if (!GetSyncService()) { 521 if (!GetSyncService()) {
513 CloseUI(); 522 CloseUI();
514 return; 523 return;
515 } 524 }
516 525
517 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); 526 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
518 if (!signin->IsAuthenticated()) { 527 if (!signin->IsAuthenticated()) {
519 // For web-based signin, the signin page is not displayed in an overlay 528 // For web-based signin, the signin page is not displayed in an overlay
520 // on the settings page. So if we get here, it must be due to the user 529 // on the settings page. So if we get here, it must be due to the user
521 // cancelling signin (by reloading the sync settings page during initial 530 // cancelling signin (by reloading the sync settings page during initial
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 } 709 }
701 710
702 void PeopleHandler::FocusUI() { 711 void PeopleHandler::FocusUI() {
703 DCHECK(IsActiveLogin()); 712 DCHECK(IsActiveLogin());
704 WebContents* web_contents = web_ui()->GetWebContents(); 713 WebContents* web_contents = web_ui()->GetWebContents();
705 web_contents->GetDelegate()->ActivateContents(web_contents); 714 web_contents->GetDelegate()->ActivateContents(web_contents);
706 } 715 }
707 716
708 void PeopleHandler::CloseUI() { 717 void PeopleHandler::CloseUI() {
709 CloseSyncSetup(); 718 CloseSyncSetup();
710 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 719 CallJavascriptFunction("cr.webUIListenerCallback",
711 base::StringValue("page-status-changed"), 720 base::StringValue("page-status-changed"),
712 base::StringValue(kDonePageStatus)); 721 base::StringValue(kDonePageStatus));
713 } 722 }
714 723
715 void PeopleHandler::GoogleSigninSucceeded(const std::string& /* account_id */, 724 void PeopleHandler::GoogleSigninSucceeded(const std::string& /* account_id */,
716 const std::string& /* username */, 725 const std::string& /* username */,
717 const std::string& /* password */) { 726 const std::string& /* password */) {
718 UpdateSyncStatus(); 727 UpdateSyncStatus();
719 } 728 }
720 729
721 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */, 730 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */,
722 const std::string& /* username */) { 731 const std::string& /* username */) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 break; 910 break;
902 } 911 }
903 } else if (passphrase_type == syncer::CUSTOM_PASSPHRASE) { 912 } else if (passphrase_type == syncer::CUSTOM_PASSPHRASE) {
904 args.SetString("fullEncryptionBody", 913 args.SetString("fullEncryptionBody",
905 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_BODY_CUSTOM)); 914 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_BODY_CUSTOM));
906 } else { 915 } else {
907 args.SetString("fullEncryptionBody", 916 args.SetString("fullEncryptionBody",
908 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); 917 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA));
909 } 918 }
910 919
911 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 920 CallJavascriptFunction("cr.webUIListenerCallback",
912 base::StringValue("sync-prefs-changed"), 921 base::StringValue("sync-prefs-changed"), args);
913 args);
914 922
915 // Make sure the tab used for the Gaia sign in does not cover the settings 923 // Make sure the tab used for the Gaia sign in does not cover the settings
916 // tab. 924 // tab.
917 FocusUI(); 925 FocusUI();
918 } 926 }
919 927
920 LoginUIService* PeopleHandler::GetLoginUIService() const { 928 LoginUIService* PeopleHandler::GetLoginUIService() const {
921 return LoginUIServiceFactory::GetForProfile(profile_); 929 return LoginUIServiceFactory::GetForProfile(profile_);
922 } 930 }
923 931
924 void PeopleHandler::UpdateSyncStatus() { 932 void PeopleHandler::UpdateSyncStatus() {
925 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 933 CallJavascriptFunction("cr.webUIListenerCallback",
926 base::StringValue("sync-status-changed"), 934 base::StringValue("sync-status-changed"),
927 *GetSyncStatusDictionary()); 935 *GetSyncStatusDictionary());
928 } 936 }
929 937
930 void PeopleHandler::OnSigninAllowedPrefChange() { 938 void PeopleHandler::OnSigninAllowedPrefChange() {
931 UpdateSyncStatus(); 939 UpdateSyncStatus();
932 } 940 }
933 941
934 void PeopleHandler::MarkFirstSetupComplete() { 942 void PeopleHandler::MarkFirstSetupComplete() {
935 // Suppress the sign in promo once the user starts sync. This way the user 943 // Suppress the sign in promo once the user starts sync. This way the user
936 // doesn't see the sign in promo even if they sign out later on. 944 // doesn't see the sign in promo even if they sign out later on.
937 signin::SetUserSkippedPromo(profile_); 945 signin::SetUserSkippedPromo(profile_);
938 946
939 ProfileSyncService* service = GetSyncService(); 947 ProfileSyncService* service = GetSyncService();
940 DCHECK(service); 948 DCHECK(service);
941 if (service->IsFirstSetupComplete()) 949 if (service->IsFirstSetupComplete())
942 return; 950 return;
943 951
944 // This is the first time configuring sync, so log it. 952 // This is the first time configuring sync, so log it.
945 base::FilePath profile_file_path = profile_->GetPath(); 953 base::FilePath profile_file_path = profile_->GetPath();
946 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); 954 ProfileMetrics::LogProfileSyncSignIn(profile_file_path);
947 955
948 // We're done configuring, so notify ProfileSyncService that it is OK to 956 // We're done configuring, so notify ProfileSyncService that it is OK to
949 // start syncing. 957 // start syncing.
950 service->SetSetupInProgress(false); 958 service->SetSetupInProgress(false);
951 service->SetFirstSetupComplete(); 959 service->SetFirstSetupComplete();
952 } 960 }
953 961
954 } // namespace settings 962 } // namespace settings
OLDNEW
« 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