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

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

Issue 1900913002: Settings People Revamp: Split Profile Info out into its own handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/lifetime/application_lifetime.h" 19 #include "chrome/browser/lifetime/application_lifetime.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_attributes_entry.h"
23 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
24 #include "chrome/browser/profiles/profile_metrics.h" 21 #include "chrome/browser/profiles/profile_metrics.h"
25 #include "chrome/browser/profiles/profile_window.h" 22 #include "chrome/browser/profiles/profile_window.h"
26 #include "chrome/browser/signin/chrome_signin_helper.h" 23 #include "chrome/browser/signin/chrome_signin_helper.h"
27 #include "chrome/browser/signin/signin_error_controller_factory.h" 24 #include "chrome/browser/signin/signin_error_controller_factory.h"
28 #include "chrome/browser/signin/signin_manager_factory.h" 25 #include "chrome/browser/signin/signin_manager_factory.h"
29 #include "chrome/browser/signin/signin_promo.h" 26 #include "chrome/browser/signin/signin_promo.h"
30 #include "chrome/browser/sync/profile_sync_service_factory.h" 27 #include "chrome/browser/sync/profile_sync_service_factory.h"
31 #include "chrome/browser/sync/sync_ui_util.h" 28 #include "chrome/browser/sync/sync_ui_util.h"
32 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
(...skipping 12 matching lines...) Expand all
46 #include "components/signin/core/common/profile_management_switches.h" 43 #include "components/signin/core/common/profile_management_switches.h"
47 #include "components/signin/core/common/signin_pref_names.h" 44 #include "components/signin/core/common/signin_pref_names.h"
48 #include "components/sync_driver/sync_prefs.h" 45 #include "components/sync_driver/sync_prefs.h"
49 #include "content/public/browser/render_view_host.h" 46 #include "content/public/browser/render_view_host.h"
50 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
51 #include "content/public/browser/web_contents_delegate.h" 48 #include "content/public/browser/web_contents_delegate.h"
52 #include "google_apis/gaia/gaia_auth_util.h" 49 #include "google_apis/gaia/gaia_auth_util.h"
53 #include "google_apis/gaia/gaia_constants.h" 50 #include "google_apis/gaia/gaia_constants.h"
54 #include "grit/components_strings.h" 51 #include "grit/components_strings.h"
55 #include "net/base/url_util.h" 52 #include "net/base/url_util.h"
56 #include "third_party/skia/include/core/SkBitmap.h"
57 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
58 #include "ui/base/webui/web_ui_util.h" 54 #include "ui/base/webui/web_ui_util.h"
59 55
60 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
61 #include "chrome/browser/chrome_notification_types.h"
62 #include "chrome/browser/chromeos/profiles/profile_helper.h"
63 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
64 #include "components/signin/core/account_id/account_id.h"
65 #include "components/signin/core/browser/signin_manager_base.h" 57 #include "components/signin/core/browser/signin_manager_base.h"
66 #include "components/user_manager/user_manager.h"
67 #include "content/public/browser/notification_service.h"
68 #else 58 #else
69 #include "components/signin/core/browser/signin_manager.h" 59 #include "components/signin/core/browser/signin_manager.h"
70 #endif 60 #endif
71 61
72 using content::WebContents; 62 using content::WebContents;
73 using l10n_util::GetStringFUTF16; 63 using l10n_util::GetStringFUTF16;
74 using l10n_util::GetStringUTF16; 64 using l10n_util::GetStringUTF16;
75 65
76 namespace { 66 namespace {
77 67
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return false; 141 return false;
152 } 142 }
153 if (!result->GetString("passphrase", &config->passphrase)) { 143 if (!result->GetString("passphrase", &config->passphrase)) {
154 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value"; 144 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value";
155 return false; 145 return false;
156 } 146 }
157 } 147 }
158 return true; 148 return true;
159 } 149 }
160 150
161 void GetAccountNameAndIcon(const Profile& profile,
162 std::string* name,
163 std::string* icon_url) {
164 DCHECK(name);
165 DCHECK(icon_url);
166
167 #if defined(OS_CHROMEOS)
168 *name = profile.GetProfileUserName();
169 if (name->empty()) {
170 const user_manager::User* user =
171 chromeos::ProfileHelper::Get()->GetUserByProfile(&profile);
172 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST))
173 *name = user->email();
174 }
175 if (!name->empty())
176 *name = gaia::SanitizeEmail(gaia::CanonicalizeEmail(*name));
177
178 // Get image as data URL instead of using chrome://userimage source to avoid
179 // issues with caching.
180 const AccountId account_id(AccountId::FromUserEmail(*name));
181 scoped_refptr<base::RefCountedMemory> image =
182 chromeos::options::UserImageSource::GetUserImage(account_id);
183 *icon_url = webui::GetPngDataUrl(image->front(), image->size());
184 #else // !defined(OS_CHROMEOS)
185 ProfileAttributesEntry* entry;
186 if (g_browser_process->profile_manager()->GetProfileAttributesStorage().
187 GetProfileAttributesWithPath(profile.GetPath(), &entry)) {
188 *name = base::UTF16ToUTF8(entry->GetName());
189
190 if (entry->IsUsingGAIAPicture() && entry->GetGAIAPicture()) {
191 gfx::Image icon =
192 profiles::GetAvatarIconForWebUI(entry->GetAvatarIcon(), true);
193 *icon_url = webui::GetBitmapDataUrl(icon.AsBitmap());
194 } else {
195 *icon_url =
196 profiles::GetDefaultAvatarIconUrl(entry->GetAvatarIconIndex());
197 }
198 }
199 #endif // defined(OS_CHROMEOS)
200 }
201
202 } // namespace 151 } // namespace
203 152
204 namespace settings { 153 namespace settings {
205 154
206 PeopleHandler::PeopleHandler(Profile* profile) 155 PeopleHandler::PeopleHandler(Profile* profile)
207 : profile_(profile), 156 : profile_(profile),
208 configuring_sync_(false), 157 configuring_sync_(false),
209 sync_service_observer_(this) { 158 sync_service_observer_(this) {
210 PrefService* prefs = profile_->GetPrefs(); 159 PrefService* prefs = profile_->GetPrefs();
211 profile_pref_registrar_.Init(prefs); 160 profile_pref_registrar_.Init(prefs);
212 profile_pref_registrar_.Add( 161 profile_pref_registrar_.Add(
213 prefs::kSigninAllowed, 162 prefs::kSigninAllowed,
214 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange, 163 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange,
215 base::Unretained(this))); 164 base::Unretained(this)));
216 165
217 ProfileSyncService* sync_service( 166 ProfileSyncService* sync_service(
218 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); 167 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
219 if (sync_service) 168 if (sync_service)
220 sync_service_observer_.Add(sync_service); 169 sync_service_observer_.Add(sync_service);
221
222 g_browser_process->profile_manager()->
223 GetProfileAttributesStorage().AddObserver(this);
224
225 #if defined(OS_CHROMEOS)
226 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
227 content::NotificationService::AllSources());
228 #endif
229 } 170 }
230 171
231 PeopleHandler::~PeopleHandler() { 172 PeopleHandler::~PeopleHandler() {
232 g_browser_process->profile_manager()->
233 GetProfileAttributesStorage().RemoveObserver(this);
234
235 // Early exit if running unit tests (no actual WebUI is attached). 173 // Early exit if running unit tests (no actual WebUI is attached).
236 if (!web_ui()) 174 if (!web_ui())
237 return; 175 return;
238 176
239 // This case is hit when the user performs a back navigation. 177 // This case is hit when the user performs a back navigation.
240 CloseSyncSetup(); 178 CloseSyncSetup();
241 } 179 }
242 180
243 void PeopleHandler::ConfigureSyncDone() { 181 void PeopleHandler::ConfigureSyncDone() {
244 base::StringValue page("done"); 182 base::StringValue page("done");
(...skipping 20 matching lines...) Expand all
265 203
266 bool PeopleHandler::IsActiveLogin() const { 204 bool PeopleHandler::IsActiveLogin() const {
267 // LoginUIService can be nullptr if page is brought up in incognito mode 205 // LoginUIService can be nullptr if page is brought up in incognito mode
268 // (i.e. if the user is running in guest mode in cros and brings up settings). 206 // (i.e. if the user is running in guest mode in cros and brings up settings).
269 LoginUIService* service = GetLoginUIService(); 207 LoginUIService* service = GetLoginUIService();
270 return service && (service->current_login_ui() == this); 208 return service && (service->current_login_ui() == this);
271 } 209 }
272 210
273 void PeopleHandler::RegisterMessages() { 211 void PeopleHandler::RegisterMessages() {
274 web_ui()->RegisterMessageCallback( 212 web_ui()->RegisterMessageCallback(
275 "getProfileInfo",
276 base::Bind(&PeopleHandler::HandleGetProfileInfo, base::Unretained(this)));
277 web_ui()->RegisterMessageCallback(
278 "SyncSetupDidClosePage", 213 "SyncSetupDidClosePage",
279 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); 214 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this)));
280 web_ui()->RegisterMessageCallback( 215 web_ui()->RegisterMessageCallback(
281 "SyncSetupConfigure", 216 "SyncSetupConfigure",
282 base::Bind(&PeopleHandler::HandleConfigure, base::Unretained(this))); 217 base::Bind(&PeopleHandler::HandleConfigure, base::Unretained(this)));
283 web_ui()->RegisterMessageCallback( 218 web_ui()->RegisterMessageCallback(
284 "SyncSetupShowSetupUI", 219 "SyncSetupShowSetupUI",
285 base::Bind(&PeopleHandler::HandleShowSetupUI, base::Unretained(this))); 220 base::Bind(&PeopleHandler::HandleShowSetupUI, base::Unretained(this)));
286 web_ui()->RegisterMessageCallback( 221 web_ui()->RegisterMessageCallback(
287 "SyncSetupCloseTimeout", 222 "SyncSetupCloseTimeout",
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 375
441 DisplayConfigureSync(false); 376 DisplayConfigureSync(false);
442 } 377 }
443 378
444 ProfileSyncService* PeopleHandler::GetSyncService() const { 379 ProfileSyncService* PeopleHandler::GetSyncService() const {
445 return profile_->IsSyncAllowed() 380 return profile_->IsSyncAllowed()
446 ? ProfileSyncServiceFactory::GetForProfile(profile_) 381 ? ProfileSyncServiceFactory::GetForProfile(profile_)
447 : nullptr; 382 : nullptr;
448 } 383 }
449 384
450 void PeopleHandler::HandleGetProfileInfo(const base::ListValue* args) {
451 std::string name;
452 std::string icon_url;
453 GetAccountNameAndIcon(*profile_, &name, &icon_url);
454
455 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.receiveProfileInfo",
456 base::StringValue(name),
457 base::StringValue(icon_url));
458 }
459
460 void PeopleHandler::HandleConfigure(const base::ListValue* args) { 385 void PeopleHandler::HandleConfigure(const base::ListValue* args) {
461 DCHECK(!sync_startup_tracker_); 386 DCHECK(!sync_startup_tracker_);
462 std::string json; 387 std::string json;
463 if (!args->GetString(0, &json)) { 388 if (!args->GetString(0, &json)) {
464 NOTREACHED() << "Could not read JSON argument"; 389 NOTREACHED() << "Could not read JSON argument";
465 return; 390 return;
466 } 391 }
467 if (json.empty()) { 392 if (json.empty()) {
468 NOTREACHED(); 393 NOTREACHED();
469 return; 394 return;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 713
789 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */, 714 void PeopleHandler::GoogleSignedOut(const std::string& /* account_id */,
790 const std::string& /* username */) { 715 const std::string& /* username */) {
791 UpdateSyncState(); 716 UpdateSyncState();
792 } 717 }
793 718
794 void PeopleHandler::OnStateChanged() { 719 void PeopleHandler::OnStateChanged() {
795 UpdateSyncState(); 720 UpdateSyncState();
796 } 721 }
797 722
798 #if defined(OS_CHROMEOS)
799 void PeopleHandler::Observe(int type,
800 const content::NotificationSource& source,
801 const content::NotificationDetails& details) {
802 switch (type) {
803 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED:
804 HandleGetProfileInfo(nullptr);
805 break;
806 default:
807 NOTREACHED();
808 }
809 }
810 #endif
811
812 void PeopleHandler::OnProfileNameChanged(
813 const base::FilePath& /* profile_path */,
814 const base::string16& /* old_profile_name */) {
815 HandleGetProfileInfo(nullptr);
816 }
817
818 void PeopleHandler::OnProfileAvatarChanged(
819 const base::FilePath& /* profile_path */) {
820 HandleGetProfileInfo(nullptr);
821 }
822
823 std::unique_ptr<base::DictionaryValue> PeopleHandler::GetSyncStateDictionary() { 723 std::unique_ptr<base::DictionaryValue> PeopleHandler::GetSyncStateDictionary() {
824 // The items which are to be written into |sync_status| are also described in 724 // The items which are to be written into |sync_status| are also described in
825 // chrome/browser/resources/options/browser_options.js in @typedef 725 // chrome/browser/resources/options/browser_options.js in @typedef
826 // for SyncStatus. Please update it whenever you add or remove any keys here. 726 // for SyncStatus. Please update it whenever you add or remove any keys here.
827 std::unique_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue); 727 std::unique_ptr<base::DictionaryValue> sync_status(new base::DictionaryValue);
828 if (profile_->IsGuestSession()) { 728 if (profile_->IsGuestSession()) {
829 // Cannot display signin status when running in guest mode on chromeos 729 // Cannot display signin status when running in guest mode on chromeos
830 // because there is no SigninManager. 730 // because there is no SigninManager.
831 sync_status->SetBoolean("signinAllowed", false); 731 sync_status->SetBoolean("signinAllowed", false);
832 return sync_status; 732 return sync_status;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 void PeopleHandler::UpdateSyncState() { 917 void PeopleHandler::UpdateSyncState() {
1018 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", 918 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus",
1019 *GetSyncStateDictionary()); 919 *GetSyncStateDictionary());
1020 } 920 }
1021 921
1022 void PeopleHandler::OnSigninAllowedPrefChange() { 922 void PeopleHandler::OnSigninAllowedPrefChange() {
1023 UpdateSyncState(); 923 UpdateSyncState();
1024 } 924 }
1025 925
1026 } // namespace settings 926 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/people_handler.h ('k') | chrome/browser/ui/webui/settings/profile_info_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698