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

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

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