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

Side by Side Diff: chrome/browser/ui/webui/options2/manage_profile_handler2.cc

Issue 10689084: Merge 143541 - Fix edit profile link in NTP (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1180/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options2/manage_profile_handler2.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options2/manage_profile_handler2.h" 5 #include "chrome/browser/ui/webui/options2/manage_profile_handler2.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/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 void ManageProfileHandler::RegisterMessages() { 64 void ManageProfileHandler::RegisterMessages() {
65 web_ui()->RegisterMessageCallback("setProfileNameAndIcon", 65 web_ui()->RegisterMessageCallback("setProfileNameAndIcon",
66 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon, 66 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon,
67 base::Unretained(this))); 67 base::Unretained(this)));
68 web_ui()->RegisterMessageCallback("deleteProfile", 68 web_ui()->RegisterMessageCallback("deleteProfile",
69 base::Bind(&ManageProfileHandler::DeleteProfile, 69 base::Bind(&ManageProfileHandler::DeleteProfile,
70 base::Unretained(this))); 70 base::Unretained(this)));
71 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", 71 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons",
72 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, 72 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons,
73 base::Unretained(this))); 73 base::Unretained(this)));
74 web_ui()->RegisterMessageCallback("requestProfileInfo",
75 base::Bind(&ManageProfileHandler::RequestProfileInfo,
76 base::Unretained(this)));
77 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", 74 web_ui()->RegisterMessageCallback("profileIconSelectionChanged",
78 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, 75 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged,
79 base::Unretained(this))); 76 base::Unretained(this)));
80 } 77 }
81 78
82 void ManageProfileHandler::Observe( 79 void ManageProfileHandler::Observe(
83 int type, 80 int type,
84 const content::NotificationSource& source, 81 const content::NotificationSource& source,
85 const content::NotificationDetails& details) { 82 const content::NotificationDetails& details) {
86 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { 83 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 Value* file_path_value; 226 Value* file_path_value;
230 FilePath profile_file_path; 227 FilePath profile_file_path;
231 if (!args->Get(0, &file_path_value) || 228 if (!args->Get(0, &file_path_value) ||
232 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) 229 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
233 return; 230 return;
234 231
235 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 232 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
236 profile_file_path); 233 profile_file_path);
237 } 234 }
238 235
239 void ManageProfileHandler::RequestProfileInfo(const ListValue* args) {
240 DCHECK(args);
241
242 Value* index_value;
243 double index_double;
244 if (!args->Get(0, &index_value) || !index_value->GetAsDouble(&index_double))
245 return;
246
247 int index = static_cast<int>(index_double);
248 ProfileInfoCache& cache =
249 g_browser_process->profile_manager()->GetProfileInfoCache();
250 int profile_count = cache.GetNumberOfProfiles();
251 if (index < 0 && index >= profile_count)
252 return;
253
254 FilePath profile_path = cache.GetPathOfProfileAtIndex(index);
255 FilePath current_profile_path = Profile::FromWebUI(web_ui())->GetPath();
256 bool is_current_profile =
257 profile_path == Profile::FromWebUI(web_ui())->GetPath();
258
259 DictionaryValue profile_value;
260 profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index));
261 profile_value.Set("filePath", base::CreateFilePathValue(profile_path));
262 profile_value.SetBoolean("isCurrentProfile", is_current_profile);
263
264 bool is_gaia_picture =
265 cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
266 cache.GetGAIAPictureOfProfileAtIndex(index);
267 if (is_gaia_picture) {
268 gfx::Image icon = profiles::GetAvatarIconForWebUI(
269 cache.GetAvatarIconOfProfileAtIndex(index), true);
270 profile_value.SetString("iconURL",
271 web_ui_util::GetImageDataUrl(*icon.ToImageSkia()));
272 } else {
273 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
274 profile_value.SetString("iconURL",
275 cache.GetDefaultAvatarIconUrl(icon_index));
276 }
277
278 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo",
279 profile_value);
280
281 // Ensure that we have the most up to date GAIA picture.
282 if (is_current_profile) {
283 GAIAInfoUpdateService* service =
284 Profile::FromWebUI(web_ui())->GetGAIAInfoUpdateService();
285 if (service)
286 service->Update();
287 }
288 }
289
290 void ManageProfileHandler::ProfileIconSelectionChanged( 236 void ManageProfileHandler::ProfileIconSelectionChanged(
291 const base::ListValue* args) { 237 const base::ListValue* args) {
292 DCHECK(args); 238 DCHECK(args);
293 239
294 Value* file_path_value; 240 Value* file_path_value;
295 FilePath file_path; 241 FilePath file_path;
296 if (!args->Get(0, &file_path_value) || 242 if (!args->Get(0, &file_path_value) ||
297 !base::GetValueAsFilePath(*file_path_value, &file_path)) { 243 !base::GetValueAsFilePath(*file_path_value, &file_path)) {
298 return; 244 return;
299 } 245 }
(...skipping 19 matching lines...) Expand all
319 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); 265 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i);
320 if (gaia_name.empty()) 266 if (gaia_name.empty())
321 return; 267 return;
322 268
323 StringValue gaia_name_value(gaia_name); 269 StringValue gaia_name_value(gaia_name);
324 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", 270 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName",
325 gaia_name_value); 271 gaia_name_value);
326 } 272 }
327 273
328 } // namespace options2 274 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/manage_profile_handler2.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698