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

Side by Side Diff: chrome/browser/ui/webui/settings/people_handler.cc

Issue 1536593004: Settings People Revamp: Implement Chrome Profile name/icon selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn build Created 5 years 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 "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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 profile_pref_registrar_.Init(prefs); 208 profile_pref_registrar_.Init(prefs);
209 profile_pref_registrar_.Add( 209 profile_pref_registrar_.Add(
210 prefs::kSigninAllowed, 210 prefs::kSigninAllowed,
211 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange, 211 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange,
212 base::Unretained(this))); 212 base::Unretained(this)));
213 213
214 ProfileSyncService* sync_service( 214 ProfileSyncService* sync_service(
215 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); 215 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
216 if (sync_service) 216 if (sync_service)
217 sync_service_observer_.Add(sync_service); 217 sync_service_observer_.Add(sync_service);
218
219 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
218 } 220 }
219 221
220 PeopleHandler::~PeopleHandler() { 222 PeopleHandler::~PeopleHandler() {
221 // Just exit if running unit tests (no actual WebUI is attached). 223 // Just exit if running unit tests (no actual WebUI is attached).
222 if (!web_ui()) 224 if (!web_ui())
223 return; 225 return;
224 226
225 // This case is hit when the user performs a back navigation. 227 // This case is hit when the user performs a back navigation.
226 CloseSyncSetup(); 228 CloseSyncSetup();
229
230 g_browser_process->profile_manager()->
231 GetProfileInfoCache().RemoveObserver(this);
227 } 232 }
228 233
229 void PeopleHandler::ConfigureSyncDone() { 234 void PeopleHandler::ConfigureSyncDone() {
230 base::StringValue page("done"); 235 base::StringValue page("done");
231 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.showSyncSetupPage", 236 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.showSyncSetupPage",
232 page); 237 page);
233 238
234 // Suppress the sign in promo once the user starts sync. This way the user 239 // Suppress the sign in promo once the user starts sync. This way the user
235 // doesn't see the sign in promo even if they sign out later on. 240 // doesn't see the sign in promo even if they sign out later on.
236 signin::SetUserSkippedPromo(profile_); 241 signin::SetUserSkippedPromo(profile_);
(...skipping 14 matching lines...) Expand all
251 256
252 bool PeopleHandler::IsActiveLogin() const { 257 bool PeopleHandler::IsActiveLogin() const {
253 // LoginUIService can be nullptr if page is brought up in incognito mode 258 // LoginUIService can be nullptr if page is brought up in incognito mode
254 // (i.e. if the user is running in guest mode in cros and brings up settings). 259 // (i.e. if the user is running in guest mode in cros and brings up settings).
255 LoginUIService* service = GetLoginUIService(); 260 LoginUIService* service = GetLoginUIService();
256 return service && (service->current_login_ui() == this); 261 return service && (service->current_login_ui() == this);
257 } 262 }
258 263
259 void PeopleHandler::RegisterMessages() { 264 void PeopleHandler::RegisterMessages() {
260 web_ui()->RegisterMessageCallback( 265 web_ui()->RegisterMessageCallback(
266 "GetProfileInfo",
267 base::Bind(&PeopleHandler::HandleGetProfileInfo, base::Unretained(this)));
268 web_ui()->RegisterMessageCallback(
261 "SyncSetupDidClosePage", 269 "SyncSetupDidClosePage",
262 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); 270 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this)));
263 web_ui()->RegisterMessageCallback( 271 web_ui()->RegisterMessageCallback(
264 "SyncSetupConfigure", 272 "SyncSetupConfigure",
265 base::Bind(&PeopleHandler::HandleConfigure, base::Unretained(this))); 273 base::Bind(&PeopleHandler::HandleConfigure, base::Unretained(this)));
266 web_ui()->RegisterMessageCallback( 274 web_ui()->RegisterMessageCallback(
267 "SyncSetupShowSetupUI", 275 "SyncSetupShowSetupUI",
268 base::Bind(&PeopleHandler::HandleShowSetupUI, base::Unretained(this))); 276 base::Bind(&PeopleHandler::HandleShowSetupUI, base::Unretained(this)));
269 web_ui()->RegisterMessageCallback( 277 web_ui()->RegisterMessageCallback(
270 "SyncSetupCloseTimeout", 278 "SyncSetupCloseTimeout",
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 431
424 DisplayConfigureSync(false); 432 DisplayConfigureSync(false);
425 } 433 }
426 434
427 ProfileSyncService* PeopleHandler::GetSyncService() const { 435 ProfileSyncService* PeopleHandler::GetSyncService() const {
428 return profile_->IsSyncAllowed() 436 return profile_->IsSyncAllowed()
429 ? ProfileSyncServiceFactory::GetForProfile(profile_) 437 ? ProfileSyncServiceFactory::GetForProfile(profile_)
430 : nullptr; 438 : nullptr;
431 } 439 }
432 440
441 void PeopleHandler::HandleGetProfileInfo(const base::ListValue* args) {
442 std::string name;
443 std::string icon_url;
444 GetAccountNameAndIcon(*profile_, &name, &icon_url);
445
446 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.receiveProfileInfo",
447 base::StringValue(name),
448 base::StringValue(icon_url));
449 }
450
433 void PeopleHandler::HandleConfigure(const base::ListValue* args) { 451 void PeopleHandler::HandleConfigure(const base::ListValue* args) {
434 DCHECK(!sync_startup_tracker_); 452 DCHECK(!sync_startup_tracker_);
435 std::string json; 453 std::string json;
436 if (!args->GetString(0, &json)) { 454 if (!args->GetString(0, &json)) {
437 NOTREACHED() << "Could not read JSON argument"; 455 NOTREACHED() << "Could not read JSON argument";
438 return; 456 return;
439 } 457 }
440 if (json.empty()) { 458 if (json.empty()) {
441 NOTREACHED(); 459 NOTREACHED();
442 return; 460 return;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 776
759 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */, 777 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */,
760 const std::string& /* username */) { 778 const std::string& /* username */) {
761 UpdateSyncState(); 779 UpdateSyncState();
762 } 780 }
763 781
764 void PeopleHandler::OnStateChanged() { 782 void PeopleHandler::OnStateChanged() {
765 UpdateSyncState(); 783 UpdateSyncState();
766 } 784 }
767 785
786 void PeopleHandler::OnProfileNameChanged(
787 const base::FilePath& profile_path,
788 const base::string16& old_profile_name) {
dschuyler 2015/12/22 18:47:48 comment out unused params
tommycli 2015/12/22 21:58:33 Done.
789 HandleGetProfileInfo(nullptr);
790 }
791
792 void PeopleHandler::OnProfileAvatarChanged(
793 const base::FilePath& profile_path) {
dschuyler 2015/12/22 18:47:48 comment out unused param name.
tommycli 2015/12/22 21:58:33 Done.
794 HandleGetProfileInfo(nullptr);
795 }
796
768 scoped_ptr<base::DictionaryValue> PeopleHandler::GetSyncStateDictionary() { 797 scoped_ptr<base::DictionaryValue> PeopleHandler::GetSyncStateDictionary() {
769 // The items which are to be written into |sync_status| are also described in 798 // The items which are to be written into |sync_status| are also described in
770 // chrome/browser/resources/options/browser_options.js in @typedef 799 // chrome/browser/resources/options/browser_options.js in @typedef
771 // for SyncStatus. Please update it whenever you add or remove any keys here. 800 // for SyncStatus. Please update it whenever you add or remove any keys here.
772 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue); 801 scoped_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
773 if (profile_->IsGuestSession()) { 802 if (profile_->IsGuestSession()) {
774 // Cannot display signin status when running in guest mode on chromeos 803 // Cannot display signin status when running in guest mode on chromeos
775 // because there is no SigninManager. 804 // because there is no SigninManager.
776 sync_status->SetBoolean("signinAllowed", false); 805 sync_status->SetBoolean("signinAllowed", false);
777 return sync_status.Pass(); 806 return sync_status.Pass();
(...skipping 30 matching lines...) Expand all
808 &link_label) == sync_ui_util::SYNC_ERROR; 837 &link_label) == sync_ui_util::SYNC_ERROR;
809 sync_status->SetString("statusText", status_label); 838 sync_status->SetString("statusText", status_label);
810 sync_status->SetString("actionLinkText", link_label); 839 sync_status->SetString("actionLinkText", link_label);
811 sync_status->SetBoolean("hasError", status_has_error); 840 sync_status->SetBoolean("hasError", status_has_error);
812 841
813 sync_status->SetBoolean("managed", service && service->IsManaged()); 842 sync_status->SetBoolean("managed", service && service->IsManaged());
814 sync_status->SetBoolean("signedIn", signin->IsAuthenticated()); 843 sync_status->SetBoolean("signedIn", signin->IsAuthenticated());
815 sync_status->SetBoolean("hasUnrecoverableError", 844 sync_status->SetBoolean("hasUnrecoverableError",
816 service && service->HasUnrecoverableError()); 845 service && service->HasUnrecoverableError());
817 846
818 std::string name;
819 std::string icon_url;
820 GetAccountNameAndIcon(*profile_, &name, &icon_url);
821 sync_status->SetString("name", name);
822 sync_status->SetString("iconURL", icon_url);
823
824 return sync_status.Pass(); 847 return sync_status.Pass();
825 } 848 }
826 849
827 bool PeopleHandler::IsExistingWizardPresent() { 850 bool PeopleHandler::IsExistingWizardPresent() {
828 LoginUIService* service = GetLoginUIService(); 851 LoginUIService* service = GetLoginUIService();
829 DCHECK(service); 852 DCHECK(service);
830 return service->current_login_ui() != nullptr; 853 return service->current_login_ui() != nullptr;
831 } 854 }
832 855
833 bool PeopleHandler::FocusExistingWizardIfPresent() { 856 bool PeopleHandler::FocusExistingWizardIfPresent() {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 void PeopleHandler::UpdateSyncState() { 991 void PeopleHandler::UpdateSyncState() {
969 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", 992 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus",
970 *GetSyncStateDictionary()); 993 *GetSyncStateDictionary());
971 } 994 }
972 995
973 void PeopleHandler::OnSigninAllowedPrefChange() { 996 void PeopleHandler::OnSigninAllowedPrefChange() {
974 UpdateSyncState(); 997 UpdateSyncState();
975 } 998 }
976 999
977 } // namespace settings 1000 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698