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

Side by Side Diff: chrome/browser/ui/webui/options/profiles_manage_handler.cc

Issue 7400032: Multi-profile WebUI settings (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Notify when deleting profile from cache Created 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options/profiles_manage_handler.h"
6
7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h"
9 #include "base/value_conversions.h"
10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/chrome_notification_types.h"
15 #include "content/common/notification_service.h"
16 #include "grit/generated_resources.h"
17
18 ProfilesManageHandler::ProfilesManageHandler() {
19 }
20
21 ProfilesManageHandler::~ProfilesManageHandler() {
22 }
23
24 void ProfilesManageHandler::GetLocalizedValues(
25 DictionaryValue* localized_strings) {
26 DCHECK(localized_strings);
27
28 static OptionsStringResource resources[] = {
29 { "profilesManageTitle", IDS_PROFILES_MANAGE_TITLE },
30 { "profilesManageNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL },
31 { "profilesManageDuplicateNameError",
32 IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR },
33 { "profilesManageIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL },
34 { "profilesManageOK", IDS_OK },
35 { "profilesManageCancel", IDS_CANCEL },
36 };
37
38 RegisterStrings(localized_strings, resources, arraysize(resources));
39 }
40
41 void ProfilesManageHandler::Initialize() {
42 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
43 NotificationService::AllSources());
44 SendProfileIcons();
45 SendProfileNames();
46 }
47
48 void ProfilesManageHandler::RegisterMessages() {
49 web_ui_->RegisterMessageCallback("setProfileNameAndIcon",
50 NewCallback(this, &ProfilesManageHandler::SetProfileNameAndIcon));
51 }
52
53 void ProfilesManageHandler::Observe(int type,
54 const NotificationSource& source,
55 const NotificationDetails& details) {
56 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
57 SendProfileNames();
58 } else {
59 OptionsPageUIHandler::Observe(type, source, details);
60 }
61 }
62
63 void ProfilesManageHandler::SendProfileIcons() {
Miranda Callahan 2011/07/19 20:40:55 I feel like this should be changed to "InitializeD
64 ListValue image_url_list;
65 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
66 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
67 image_url_list.Append(Value::CreateStringValue(url));
68 }
69 web_ui_->CallJavascriptFunction("ProfilesManageOverlay.receiveProfileIcons",
70 image_url_list);
71 }
72
73 void ProfilesManageHandler::SendProfileNames() {
74 ProfileInfoCache& cache =
75 g_browser_process->profile_manager()->GetProfileInfoCache();
76 DictionaryValue profile_name_dict;
77 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
78 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)),
79 true);
80 }
81
82 web_ui_->CallJavascriptFunction("ProfilesManageOverlay.receiveProfileNames",
83 profile_name_dict);
84 }
85
86 void ProfilesManageHandler::SetProfileNameAndIcon(const ListValue* args) {
87 Value* file_path_value;
88 FilePath profile_file_path;
89 if (!args->Get(0, &file_path_value) ||
90 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) {
91 return;
92 }
93
94 ProfileInfoCache& cache =
95 g_browser_process->profile_manager()->GetProfileInfoCache();
96 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
97 if (profile_index == std::string::npos) {
sail 2011/07/19 19:39:50 no need for braces for single line statements, mor
98 return;
99 }
100
101 string16 new_profile_name;
102 if (!args->GetString(1, &new_profile_name)) {
103 return;
104 }
105
106 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name);
107
108 string16 icon_url;
109 size_t new_icon_index;
110 if (!args->GetString(2, &icon_url) ||
111 !cache.IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index)) {
112 return;
113 }
114
115 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
116 }
117
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698