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

Side by Side Diff: chrome/browser/ui/webui/settings/settings_manage_profile_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: 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 (c) 2013 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/options/manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h"
6
7 #include <stddef.h>
8 6
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
11 #include "base/macros.h"
12 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
13 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
14 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
17 #include "base/value_conversions.h" 14 #include "base/value_conversions.h"
18 #include "base/values.h" 15 #include "base/values.h"
19 #include "build/build_config.h"
20 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/profiles/gaia_info_update_service.h" 18 #include "chrome/browser/profiles/gaia_info_update_service.h"
23 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
25 #include "chrome/browser/profiles/profile_info_cache.h" 21 #include "chrome/browser/profiles/profile_info_cache.h"
26 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/profiles/profile_metrics.h" 23 #include "chrome/browser/profiles/profile_metrics.h"
28 #include "chrome/browser/profiles/profile_shortcut_manager.h" 24 #include "chrome/browser/profiles/profile_shortcut_manager.h"
29 #include "chrome/browser/profiles/profile_window.h" 25 #include "chrome/browser/profiles/profile_window.h"
30 #include "chrome/browser/profiles/profiles_state.h" 26 #include "chrome/browser/profiles/profiles_state.h"
31 #include "chrome/browser/signin/signin_manager_factory.h" 27 #include "chrome/browser/signin/signin_manager_factory.h"
32 #include "chrome/browser/sync/profile_sync_service_factory.h"
33 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" 29 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
35 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
37 #include "chrome/grit/chromium_strings.h" 32 #include "chrome/grit/chromium_strings.h"
38 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
39 #include "components/browser_sync/browser/profile_sync_service.h"
40 #include "components/signin/core/browser/signin_manager.h" 34 #include "components/signin/core/browser/signin_manager.h"
41 #include "components/signin/core/common/profile_management_switches.h" 35 #include "components/signin/core/common/profile_management_switches.h"
42 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/web_ui.h" 38 #include "content/public/browser/web_ui.h"
45 #include "google_apis/gaia/gaia_auth_util.h" 39 #include "google_apis/gaia/gaia_auth_util.h"
46 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/base/webui/web_ui_util.h" 41 #include "ui/base/webui/web_ui_util.h"
48 42
49 #if defined(ENABLE_SETTINGS_APP) 43 namespace settings {
50 #include "chrome/browser/ui/app_list/app_list_service.h"
51 #include "content/public/browser/web_contents.h"
52 #endif
53 44
54 namespace options { 45 ManageProfileHandler::ManageProfileHandler(Profile* profile)
55 46 : profile_(profile), weak_factory_(this) {
56 namespace { 47 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
57
58 const char kCreateProfileIdentifier[] = "create";
59 const char kManageProfileIdentifier[] = "manage";
60
61 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path|
62 // and returns true on success.
63 bool GetProfilePathFromArgs(const base::ListValue* args,
64 base::FilePath* profile_file_path) {
65 const base::Value* file_path_value;
66 if (!args->Get(0, &file_path_value))
67 return false;
68 return base::GetValueAsFilePath(*file_path_value, profile_file_path);
69 }
70
71 void HandleLogDeleteUserDialogShown(const base::ListValue* args) {
72 ProfileMetrics::LogProfileDeleteUser(
73 ProfileMetrics::DELETE_PROFILE_SETTINGS_SHOW_WARNING);
74 }
75
76 } // namespace
77
78 ManageProfileHandler::ManageProfileHandler()
79 : weak_factory_(this) {
80 } 48 }
81 49
82 ManageProfileHandler::~ManageProfileHandler() { 50 ManageProfileHandler::~ManageProfileHandler() {
83 ProfileSyncService* service = 51 g_browser_process->profile_manager()->
84 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 52 GetProfileInfoCache().RemoveObserver(this);
85 // Sync may be disabled in tests.
86 if (service)
87 service->RemoveObserver(this);
88 }
89
90 void ManageProfileHandler::GetLocalizedValues(
91 base::DictionaryValue* localized_strings) {
92 DCHECK(localized_strings);
93
94 static OptionsStringResource resources[] = {
95 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL },
96 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL },
97 { "manageProfilesExistingSupervisedUser",
98 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_REMOTELY },
99 { "managedProfilesExistingLocalSupervisedUser",
100 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_LOCALLY },
101 { "manageProfilesSupervisedSignedInLabel",
102 IDS_PROFILES_CREATE_SUPERVISED_SIGNED_IN_LABEL },
103 { "manageProfilesSupervisedNotSignedIn",
104 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML },
105 { "manageProfilesSupervisedAccountDetailsOutOfDate",
106 IDS_PROFILES_CREATE_SUPERVISED_ACCOUNT_DETAILS_OUT_OF_DATE_LABEL },
107 { "manageProfilesSupervisedSignInAgainLink",
108 IDS_PROFILES_GAIA_REAUTH_TITLE },
109 { "manageProfilesConfirm", IDS_SAVE },
110 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE },
111 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL },
112 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE },
113 { "disconnectManagedProfileTitle",
114 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_TITLE },
115 { "disconnectManagedProfileOK",
116 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_OK_BUTTON_LABEL },
117 { "createProfileTitle", IDS_PROFILES_CREATE_TITLE },
118 { "createProfileInstructions", IDS_PROFILES_CREATE_INSTRUCTIONS },
119 { "createProfileConfirm", IDS_ADD },
120 { "createProfileShortcutCheckbox", IDS_PROFILES_CREATE_SHORTCUT_CHECKBOX },
121 { "createProfileShortcutButton", IDS_PROFILES_CREATE_SHORTCUT_BUTTON },
122 { "removeProfileShortcutButton", IDS_PROFILES_REMOVE_SHORTCUT_BUTTON },
123 { "importExistingSupervisedUserLink",
124 IDS_IMPORT_EXISTING_LEGACY_SUPERVISED_USER_TITLE },
125 };
126
127 RegisterStrings(localized_strings, resources, arraysize(resources));
128 RegisterTitle(localized_strings, "manageProfile", IDS_PROFILES_MANAGE_TITLE);
129 RegisterTitle(localized_strings, "createProfile", IDS_PROFILES_CREATE_TITLE);
130
131 base::string16 supervised_user_dashboard_url =
132 base::ASCIIToUTF16(chrome::kLegacySupervisedUserManagementURL);
133 base::string16 supervised_user_dashboard_display =
134 base::ASCIIToUTF16(chrome::kLegacySupervisedUserManagementDisplayURL);
135 localized_strings->SetString("deleteSupervisedProfileAddendum",
136 l10n_util::GetStringFUTF16(IDS_PROFILES_DELETE_LEGACY_SUPERVISED_ADDENDUM,
137 supervised_user_dashboard_url,
138 supervised_user_dashboard_display));
139
140 localized_strings->SetBoolean("profileShortcutsEnabled",
141 ProfileShortcutManager::IsFeatureEnabled());
142
143 GenerateSignedinUserSpecificStrings(localized_strings);
144 }
145
146 void ManageProfileHandler::InitializeHandler() {
147 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
148
149 Profile* profile = Profile::FromWebUI(web_ui());
150 pref_change_registrar_.Init(profile->GetPrefs());
151 pref_change_registrar_.Add(
152 prefs::kSupervisedUserCreationAllowed,
153 base::Bind(&ManageProfileHandler::OnCreateSupervisedUserPrefChange,
154 base::Unretained(this)));
155 ProfileSyncService* service =
156 ProfileSyncServiceFactory::GetForProfile(profile);
157 // Sync may be disabled for tests.
158 if (service)
159 service->AddObserver(this);
160 }
161
162 void ManageProfileHandler::InitializePage() {
163 SendExistingProfileNames();
164 OnCreateSupervisedUserPrefChange();
165 } 53 }
166 54
167 void ManageProfileHandler::RegisterMessages() { 55 void ManageProfileHandler::RegisterMessages() {
168 web_ui()->RegisterMessageCallback("setProfileIconAndName", 56 web_ui()->RegisterMessageCallback("setProfileIconAndName",
169 base::Bind(&ManageProfileHandler::SetProfileIconAndName, 57 base::Bind(&ManageProfileHandler::SetProfileIconAndName,
170 base::Unretained(this))); 58 base::Unretained(this)));
171 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", 59 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons",
172 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, 60 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons,
173 base::Unretained(this))); 61 base::Unretained(this)));
174 web_ui()->RegisterMessageCallback("requestNewProfileDefaults",
175 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults,
176 base::Unretained(this)));
177 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", 62 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts",
178 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, 63 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts,
179 base::Unretained(this))); 64 base::Unretained(this)));
180 web_ui()->RegisterMessageCallback("requestCreateProfileUpdate",
181 base::Bind(&ManageProfileHandler::RequestCreateProfileUpdate,
182 base::Unretained(this)));
183 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", 65 web_ui()->RegisterMessageCallback("profileIconSelectionChanged",
184 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, 66 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged,
185 base::Unretained(this))); 67 base::Unretained(this)));
186 #if defined(ENABLE_SETTINGS_APP)
187 web_ui()->RegisterMessageCallback("switchAppListProfile",
188 base::Bind(&ManageProfileHandler::SwitchAppListProfile,
189 base::Unretained(this)));
190 #endif
191 web_ui()->RegisterMessageCallback("addProfileShortcut", 68 web_ui()->RegisterMessageCallback("addProfileShortcut",
192 base::Bind(&ManageProfileHandler::AddProfileShortcut, 69 base::Bind(&ManageProfileHandler::AddProfileShortcut,
193 base::Unretained(this))); 70 base::Unretained(this)));
194 web_ui()->RegisterMessageCallback("removeProfileShortcut", 71 web_ui()->RegisterMessageCallback("removeProfileShortcut",
195 base::Bind(&ManageProfileHandler::RemoveProfileShortcut, 72 base::Bind(&ManageProfileHandler::RemoveProfileShortcut,
196 base::Unretained(this))); 73 base::Unretained(this)));
197 web_ui()->RegisterMessageCallback("refreshGaiaPicture", 74 web_ui()->RegisterMessageCallback("refreshGaiaPicture",
198 base::Bind(&ManageProfileHandler::RefreshGaiaPicture, 75 base::Bind(&ManageProfileHandler::RefreshGaiaPicture,
199 base::Unretained(this))); 76 base::Unretained(this)));
200 web_ui()->RegisterMessageCallback(
201 "showDisconnectManagedProfileDialog",
202 base::Bind(&ManageProfileHandler::ShowDisconnectManagedProfileDialog,
203 base::Unretained(this)));
204 web_ui()->RegisterMessageCallback("logDeleteUserDialogShown",
205 base::Bind(&HandleLogDeleteUserDialogShown));
206 }
207
208 void ManageProfileHandler::Uninitialize() {
209 g_browser_process->profile_manager()->
210 GetProfileInfoCache().RemoveObserver(this);
211 }
212
213 void ManageProfileHandler::OnProfileAdded(const base::FilePath& profile_path) {
214 SendExistingProfileNames();
215 }
216
217 void ManageProfileHandler::OnProfileWasRemoved(
218 const base::FilePath& profile_path,
219 const base::string16& profile_name) {
220 SendExistingProfileNames();
221 } 77 }
222 78
223 void ManageProfileHandler::OnProfileNameChanged( 79 void ManageProfileHandler::OnProfileNameChanged(
224 const base::FilePath& profile_path, 80 const base::FilePath& profile_path,
225 const base::string16& old_profile_name) { 81 const base::string16& old_profile_name) {
226 base::StringValue value(kManageProfileIdentifier); 82 SendAvailableIcons();
227 SendProfileIconsAndNames(value);
228 } 83 }
229 84
230 void ManageProfileHandler::OnProfileAvatarChanged( 85 void ManageProfileHandler::OnProfileAvatarChanged(
231 const base::FilePath& profile_path) { 86 const base::FilePath& profile_path) {
232 base::StringValue value(kManageProfileIdentifier); 87 SendAvailableIcons();
233 SendProfileIconsAndNames(value);
234 }
235
236 void ManageProfileHandler::OnStateChanged() {
237 RequestCreateProfileUpdate(NULL);
238 }
239
240 void ManageProfileHandler::GenerateSignedinUserSpecificStrings(
241 base::DictionaryValue* dictionary) {
242 std::string username;
243 std::string domain_name;
244
245 #if !defined(OS_CHROMEOS)
246 Profile* profile = Profile::FromWebUI(web_ui());
247 DCHECK(profile);
248 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile);
249 if (manager) {
250 username = manager->GetAuthenticatedAccountInfo().email;
251 // If there is no one logged in or if the profile name is empty then the
252 // domain name is empty. This happens in browser tests.
253 if (!username.empty()) {
254 domain_name = "<span id=disconnect-managed-profile-domain-name>" +
255 gaia::ExtractDomainName(username) + "</span>";
256 }
257 }
258 #endif
259
260 dictionary->SetString(
261 "disconnectManagedProfileDomainInformation",
262 l10n_util::GetStringFUTF16(
263 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_DOMAIN_INFORMATION,
264 base::ASCIIToUTF16(domain_name)));
265
266 dictionary->SetString(
267 "disconnectManagedProfileText",
268 l10n_util::GetStringFUTF16(
269 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_TEXT,
270 base::UTF8ToUTF16(username),
271 base::UTF8ToUTF16(chrome::kSyncGoogleDashboardURL)));
272 } 88 }
273 89
274 void ManageProfileHandler::RequestDefaultProfileIcons( 90 void ManageProfileHandler::RequestDefaultProfileIcons(
275 const base::ListValue* args) { 91 const base::ListValue* args) {
276 std::string mode; 92 SendAvailableIcons();
277 bool ok = args->GetString(0, &mode);
278 DCHECK(ok);
279 DCHECK(mode == kCreateProfileIdentifier || mode == kManageProfileIdentifier);
280 if (ok) {
281 base::StringValue value(mode);
282 SendProfileIconsAndNames(value);
283 }
284 } 93 }
285 94
286 void ManageProfileHandler::RequestNewProfileDefaults( 95 void ManageProfileHandler::SendAvailableIcons() {
287 const base::ListValue* args) {
288 const ProfileInfoCache& cache =
289 g_browser_process->profile_manager()->GetProfileInfoCache();
290 const size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile();
291
292 base::DictionaryValue profile_info;
293 profile_info.SetString("name", cache.ChooseNameForNewProfile(icon_index));
294 profile_info.SetString("iconURL",
295 profiles::GetDefaultAvatarIconUrl(icon_index));
296
297 web_ui()->CallJavascriptFunction(
298 "ManageProfileOverlay.receiveNewProfileDefaults", profile_info);
299 }
300
301 void ManageProfileHandler::SendProfileIconsAndNames(
302 const base::StringValue& mode) {
303 base::ListValue image_url_list; 96 base::ListValue image_url_list;
304 base::ListValue default_name_list;
305
306 const ProfileInfoCache& cache = 97 const ProfileInfoCache& cache =
307 g_browser_process->profile_manager()->GetProfileInfoCache(); 98 g_browser_process->profile_manager()->GetProfileInfoCache();
308 99
309 // In manage mode, first add the GAIA picture if it is available. No GAIA 100 // First add the GAIA picture if it is available.
310 // picture in create mode. 101 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
311 if (mode.GetString() == kManageProfileIdentifier) { 102 if (profile_index != std::string::npos) {
312 Profile* profile = Profile::FromWebUI(web_ui()); 103 const gfx::Image* icon =
313 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 104 cache.GetGAIAPictureOfProfileAtIndex(profile_index);
314 if (profile_index != std::string::npos) { 105 if (icon) {
315 const gfx::Image* icon = 106 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true);
316 cache.GetGAIAPictureOfProfileAtIndex(profile_index); 107 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap());
317 if (icon) { 108 image_url_list.AppendString(gaia_picture_url_);
318 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true);
319 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap());
320 image_url_list.AppendString(gaia_picture_url_);
321 default_name_list.AppendString(std::string());
322 }
323 } 109 }
324 } 110 }
325 111
326 // Next add the default avatar icons and names. 112 // Next add the default avatar icons and names.
327 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { 113 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) {
328 std::string url = profiles::GetDefaultAvatarIconUrl(i); 114 std::string url = profiles::GetDefaultAvatarIconUrl(i);
329 image_url_list.AppendString(url); 115 image_url_list.AppendString(url);
330 default_name_list.AppendString(cache.ChooseNameForNewProfile(i));
331 } 116 }
332 117
333 web_ui()->CallJavascriptFunction( 118 web_ui()->CallJavascriptFunction(
334 "ManageProfileOverlay.receiveDefaultProfileIconsAndNames", mode, 119 "settings.SyncPrivateApi.receiveAvailableIcons",
335 image_url_list, default_name_list); 120 image_url_list);
336 }
337
338 void ManageProfileHandler::SendExistingProfileNames() {
339 const ProfileInfoCache& cache =
340 g_browser_process->profile_manager()->GetProfileInfoCache();
341 base::DictionaryValue profile_name_dict;
342 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
343 profile_name_dict.SetBoolean(
344 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), true);
345 }
346
347 web_ui()->CallJavascriptFunction(
348 "ManageProfileOverlay.receiveExistingProfileNames", profile_name_dict);
349 }
350
351 void ManageProfileHandler::ShowDisconnectManagedProfileDialog(
352 const base::ListValue* args) {
353 base::DictionaryValue replacements;
354 GenerateSignedinUserSpecificStrings(&replacements);
355 web_ui()->CallJavascriptFunction(
356 "ManageProfileOverlay.showDisconnectManagedProfileDialog", replacements);
357 } 121 }
358 122
359 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) { 123 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) {
360 DCHECK(args); 124 DCHECK(args);
361 125
362 base::FilePath profile_file_path; 126 std::string icon_url;
363 if (!GetProfilePathFromArgs(args, &profile_file_path)) 127 if (!args->GetString(0, &icon_url))
364 return; 128 return;
365 129
366 Profile* profile = 130 PrefService* pref_service = profile_->GetPrefs();
367 g_browser_process->profile_manager()->GetProfile(profile_file_path);
368 if (!profile)
369 return;
370
371 std::string icon_url;
372 if (!args->GetString(1, &icon_url))
373 return;
374
375 PrefService* pref_service = profile->GetPrefs();
376 // Updating the profile preferences will cause the cache to be updated. 131 // Updating the profile preferences will cause the cache to be updated.
377 132
378 // Metrics logging variable. 133 // Metrics logging variable.
379 bool previously_using_gaia_icon = 134 bool previously_using_gaia_icon =
380 pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar); 135 pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar);
381 136
382 size_t new_icon_index; 137 size_t new_icon_index;
383 if (icon_url == gaia_picture_url_) { 138 if (icon_url == gaia_picture_url_) {
384 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); 139 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false);
385 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, true); 140 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, true);
386 if (!previously_using_gaia_icon) { 141 if (!previously_using_gaia_icon) {
387 // Only log if they changed to the GAIA photo. 142 // Only log if they changed to the GAIA photo.
388 // Selection of GAIA photo as avatar is logged as part of the function 143 // Selection of GAIA photo as avatar is logged as part of the function
389 // below. 144 // below.
390 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); 145 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN);
391 } 146 }
392 } else if (profiles::IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { 147 } else if (profiles::IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) {
393 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); 148 ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
394 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); 149 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index);
395 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); 150 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false);
396 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false); 151 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false);
397 } else { 152 } else {
398 // Only default avatars and Gaia account photos are supported. 153 // Only default avatars and Gaia account photos are supported.
399 CHECK(false); 154 CHECK(false);
400 } 155 }
401 ProfileMetrics::LogProfileUpdate(profile_file_path); 156 ProfileMetrics::LogProfileUpdate(profile_->GetPath());
402 157
403 if (profile->IsLegacySupervised()) 158 if (profile_->IsLegacySupervised())
404 return; 159 return;
405 160
406 base::string16 new_profile_name; 161 base::string16 new_profile_name;
407 if (!args->GetString(2, &new_profile_name)) 162 if (!args->GetString(1, &new_profile_name))
408 return; 163 return;
409 164
410 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); 165 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name);
411 CHECK(!new_profile_name.empty()); 166 CHECK(!new_profile_name.empty());
412 profiles::UpdateProfileName(profile, new_profile_name); 167 profiles::UpdateProfileName(profile_, new_profile_name);
413 } 168 }
414 169
415 #if defined(ENABLE_SETTINGS_APP)
416 void ManageProfileHandler::SwitchAppListProfile(const base::ListValue* args) {
417 DCHECK(args);
418 DCHECK(profiles::IsMultipleProfilesEnabled());
419
420 const base::Value* file_path_value;
421 base::FilePath profile_file_path;
422 if (!args->Get(0, &file_path_value) ||
423 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
424 return;
425
426 AppListService* app_list_service = AppListService::Get(
427 options::helper::GetDesktopType(web_ui()));
428 app_list_service->SetProfilePath(profile_file_path);
429 app_list_service->Show();
430
431 // Close the settings app, since it will now be for the wrong profile.
432 web_ui()->GetWebContents()->Close();
433 }
434 #endif // defined(ENABLE_SETTINGS_APP)
435
436 void ManageProfileHandler::ProfileIconSelectionChanged( 170 void ManageProfileHandler::ProfileIconSelectionChanged(
437 const base::ListValue* args) { 171 const base::ListValue* args) {
438 DCHECK(args); 172 DCHECK(args);
439 173
440 base::FilePath profile_file_path;
441 if (!GetProfilePathFromArgs(args, &profile_file_path))
442 return;
443
444 // Currently this only supports editing the current profile's info.
445 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath())
446 return;
447
448 std::string icon_url; 174 std::string icon_url;
449 if (!args->GetString(1, &icon_url)) 175 if (!args->GetString(0, &icon_url))
450 return; 176 return;
451 177
452 if (icon_url != gaia_picture_url_) 178 if (icon_url != gaia_picture_url_)
453 return; 179 return;
454 180
455 // If the selection is the GAIA picture then also show the profile name in the 181 // If the selection is the GAIA picture then also show the profile name in the
456 // text field. This will display either the GAIA given name, if available, 182 // text field. This will display either the GAIA given name, if available,
457 // or the first name. 183 // or the first name.
458 ProfileInfoCache& cache = 184 ProfileInfoCache& cache =
459 g_browser_process->profile_manager()->GetProfileInfoCache(); 185 g_browser_process->profile_manager()->GetProfileInfoCache();
460 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 186 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
461 if (profile_index == std::string::npos) 187 if (profile_index == std::string::npos)
462 return; 188 return;
463 base::string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index); 189 base::string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index);
464 if (gaia_name.empty()) 190 if (gaia_name.empty())
465 return; 191 return;
466 192
467 base::StringValue gaia_name_value(gaia_name); 193 base::StringValue gaia_name_value(gaia_name);
468 base::StringValue mode_value(kManageProfileIdentifier); 194 web_ui()->CallJavascriptFunction(
469 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", 195 "settings.SyncPrivateApi.setProfileName",
470 gaia_name_value, mode_value); 196 gaia_name_value);
471 } 197 }
472 198
473 void ManageProfileHandler::RequestHasProfileShortcuts( 199 void ManageProfileHandler::RequestHasProfileShortcuts(
474 const base::ListValue* args) { 200 const base::ListValue* args) {
475 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
476 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); 202 DCHECK(ProfileShortcutManager::IsFeatureEnabled());
477 203
478 base::FilePath profile_file_path;
479 if (!GetProfilePathFromArgs(args, &profile_file_path))
480 return;
481
482 const ProfileInfoCache& cache = 204 const ProfileInfoCache& cache =
483 g_browser_process->profile_manager()->GetProfileInfoCache(); 205 g_browser_process->profile_manager()->GetProfileInfoCache();
484 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 206 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
485 if (profile_index == std::string::npos) 207 if (profile_index == std::string::npos)
486 return; 208 return;
487 209
488 // Don't show the add/remove desktop shortcut button in the single user case. 210 // Don't show the add/remove desktop shortcut button in the single user case.
489 if (cache.GetNumberOfProfiles() <= 1) 211 if (cache.GetNumberOfProfiles() <= 1)
490 return; 212 return;
491 213
492 const base::FilePath profile_path = 214 const base::FilePath profile_path =
493 cache.GetPathOfProfileAtIndex(profile_index); 215 cache.GetPathOfProfileAtIndex(profile_index);
494 ProfileShortcutManager* shortcut_manager = 216 ProfileShortcutManager* shortcut_manager =
495 g_browser_process->profile_manager()->profile_shortcut_manager(); 217 g_browser_process->profile_manager()->profile_shortcut_manager();
496 shortcut_manager->HasProfileShortcuts( 218 shortcut_manager->HasProfileShortcuts(
497 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, 219 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts,
498 weak_factory_.GetWeakPtr())); 220 weak_factory_.GetWeakPtr()));
499 } 221 }
500 222
501 void ManageProfileHandler::RequestCreateProfileUpdate(
502 const base::ListValue* args) {
503 Profile* profile = Profile::FromWebUI(web_ui());
504 SigninManagerBase* manager =
505 SigninManagerFactory::GetForProfile(profile);
506 base::string16 username =
507 base::UTF8ToUTF16(manager->GetAuthenticatedAccountInfo().email);
508 ProfileSyncService* service =
509 ProfileSyncServiceFactory::GetForProfile(profile);
510 GoogleServiceAuthError::State state = GoogleServiceAuthError::NONE;
511
512 // |service| might be null if Sync is disabled from the command line.
513 if (service)
514 state = service->GetAuthError().state();
515
516 bool has_error = (!service ||
517 state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
518 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
519 state == GoogleServiceAuthError::ACCOUNT_DELETED ||
520 state == GoogleServiceAuthError::ACCOUNT_DISABLED);
521 web_ui()->CallJavascriptFunction("CreateProfileOverlay.updateSignedInStatus",
522 base::StringValue(username),
523 base::FundamentalValue(has_error));
524
525 OnCreateSupervisedUserPrefChange();
526 }
527
528 void ManageProfileHandler::OnCreateSupervisedUserPrefChange() {
529 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
530 base::FundamentalValue allowed(
531 prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed));
532 web_ui()->CallJavascriptFunction(
533 "CreateProfileOverlay.updateSupervisedUsersAllowed", allowed);
534 }
535
536 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { 223 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) {
537 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 224 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
538 225
539 const base::FundamentalValue has_shortcuts_value(has_shortcuts); 226 const base::FundamentalValue has_shortcuts_value(has_shortcuts);
540 web_ui()->CallJavascriptFunction( 227 web_ui()->CallJavascriptFunction(
541 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); 228 "settings.SyncPrivateApi.receiveHasProfileShortcuts",
229 has_shortcuts_value);
542 } 230 }
543 231
544 void ManageProfileHandler::AddProfileShortcut(const base::ListValue* args) { 232 void ManageProfileHandler::AddProfileShortcut(const base::ListValue* args) {
545 base::FilePath profile_file_path;
546 if (!GetProfilePathFromArgs(args, &profile_file_path))
547 return;
548
549 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); 233 DCHECK(ProfileShortcutManager::IsFeatureEnabled());
550 ProfileShortcutManager* shortcut_manager = 234 ProfileShortcutManager* shortcut_manager =
551 g_browser_process->profile_manager()->profile_shortcut_manager(); 235 g_browser_process->profile_manager()->profile_shortcut_manager();
552 DCHECK(shortcut_manager); 236 DCHECK(shortcut_manager);
553 237
554 shortcut_manager->CreateProfileShortcut(profile_file_path); 238 shortcut_manager->CreateProfileShortcut(profile_->GetPath());
555 239
556 // Update the UI buttons. 240 // Update the UI buttons.
557 OnHasProfileShortcuts(true); 241 OnHasProfileShortcuts(true);
558 } 242 }
559 243
560 void ManageProfileHandler::RemoveProfileShortcut(const base::ListValue* args) { 244 void ManageProfileHandler::RemoveProfileShortcut(const base::ListValue* args) {
561 base::FilePath profile_file_path;
562 if (!GetProfilePathFromArgs(args, &profile_file_path))
563 return;
564
565 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); 245 DCHECK(ProfileShortcutManager::IsFeatureEnabled());
566 ProfileShortcutManager* shortcut_manager = 246 ProfileShortcutManager* shortcut_manager =
567 g_browser_process->profile_manager()->profile_shortcut_manager(); 247 g_browser_process->profile_manager()->profile_shortcut_manager();
568 DCHECK(shortcut_manager); 248 DCHECK(shortcut_manager);
569 249
570 shortcut_manager->RemoveProfileShortcuts(profile_file_path); 250 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath());
571 251
572 // Update the UI buttons. 252 // Update the UI buttons.
573 OnHasProfileShortcuts(false); 253 OnHasProfileShortcuts(false);
574 } 254 }
575 255
576 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { 256 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) {
577 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); 257 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui()));
578 } 258 }
579 259
580 } // namespace options 260 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/settings_manage_profile_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698