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

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

Issue 8539043: Refactor ProfileInfoCache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/options/manage_profile_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/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"
11 #include "base/value_conversions.h" 11 #include "base/value_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile_info_util.h"
14 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/profiles/profile_metrics.h" 17 #include "chrome/browser/profiles/profile_metrics.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 22
22 ManageProfileHandler::ManageProfileHandler() { 23 ManageProfileHandler::ManageProfileHandler() {
23 } 24 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const content::NotificationSource& source, 70 const content::NotificationSource& source,
70 const content::NotificationDetails& details) { 71 const content::NotificationDetails& details) {
71 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) 72 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED)
72 SendProfileNames(); 73 SendProfileNames();
73 else 74 else
74 OptionsPageUIHandler::Observe(type, source, details); 75 OptionsPageUIHandler::Observe(type, source, details);
75 } 76 }
76 77
77 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) { 78 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) {
78 ListValue image_url_list; 79 ListValue image_url_list;
79 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) { 80 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) {
80 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); 81 std::string url = profiles::GetDefaultAvatarIconUrl(i);
81 image_url_list.Append(Value::CreateStringValue(url)); 82 image_url_list.Append(Value::CreateStringValue(url));
82 } 83 }
83 84
84 web_ui_->CallJavascriptFunction( 85 web_ui_->CallJavascriptFunction(
85 "ManageProfileOverlay.receiveDefaultProfileIcons", 86 "ManageProfileOverlay.receiveDefaultProfileIcons",
86 image_url_list); 87 image_url_list);
87 } 88 }
88 89
89 void ManageProfileHandler::SendProfileNames() { 90 void ManageProfileHandler::SendProfileNames() {
91 DictionaryValue profile_name_dict;
92
90 ProfileInfoCache& cache = 93 ProfileInfoCache& cache =
91 g_browser_process->profile_manager()->GetProfileInfoCache(); 94 g_browser_process->profile_manager()->GetProfileInfoCache();
92 DictionaryValue profile_name_dict; 95 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName());
93 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) 96 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin();
94 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), 97 it != entries.end(); ++it) {
95 true); 98 profile_name_dict.SetBoolean(UTF16ToUTF8(it->name()), true);
99 }
96 100
97 web_ui_->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames", 101 web_ui_->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames",
98 profile_name_dict); 102 profile_name_dict);
99 } 103 }
100 104
101 void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) { 105 void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) {
102 DCHECK(args); 106 DCHECK(args);
103 107
104 Value* file_path_value; 108 Value* file_path_value;
105 FilePath profile_file_path; 109 FilePath profile_file_path;
106 if (!args->Get(0, &file_path_value) || 110 if (!args->Get(0, &file_path_value) ||
107 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) 111 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
108 return; 112 return;
109 113
110 ProfileInfoCache& cache = 114 ProfileInfoCache& cache =
111 g_browser_process->profile_manager()->GetProfileInfoCache(); 115 g_browser_process->profile_manager()->GetProfileInfoCache();
112 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 116 ProfileInfoEntry entry;
113 if (profile_index == std::string::npos) 117 if (!cache.GetInfoForProfile(profile_file_path, &entry))
114 return; 118 return;
115 119
116 string16 new_profile_name; 120 string16 new_profile_name;
117 if (!args->GetString(1, &new_profile_name)) 121 if (!args->GetString(1, &new_profile_name))
118 return; 122 return;
119 123
120 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name);
121 // The index in the cache may have changed if a new name triggered an
122 // alphabetical resort.
123 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
124 if (profile_index == std::string::npos)
125 return;
126
127 string16 icon_url; 124 string16 icon_url;
128 size_t new_icon_index; 125 size_t new_icon_index;
129 if (!args->GetString(2, &icon_url) || 126 if (!args->GetString(2, &icon_url) ||
130 !cache.IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index)) 127 !profiles::IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index))
131 return; 128 return;
132 129
130 entry.set_name(new_profile_name);
131 entry.set_icon_index(new_icon_index);
132 cache.SetInfoForProfile(entry);
133
133 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); 134 ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
134 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
135
136 ProfileMetrics::LogProfileUpdate(profile_file_path); 135 ProfileMetrics::LogProfileUpdate(profile_file_path);
137 } 136 }
138 137
139 void ManageProfileHandler::DeleteProfile(const ListValue* args) { 138 void ManageProfileHandler::DeleteProfile(const ListValue* args) {
140 DCHECK(args); 139 DCHECK(args);
141 140
142 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::PROFILE_DELETED); 141 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::PROFILE_DELETED);
143 142
144 Value* file_path_value; 143 Value* file_path_value;
145 FilePath profile_file_path; 144 FilePath profile_file_path;
(...skipping 22 matching lines...) Expand all
168 int profile_count = cache.GetNumberOfProfiles(); 167 int profile_count = cache.GetNumberOfProfiles();
169 if (index < 0 && index >= profile_count) 168 if (index < 0 && index >= profile_count)
170 return; 169 return;
171 170
172 FilePath current_profile_path = 171 FilePath current_profile_path =
173 web_ui_->tab_contents()->browser_context()->GetPath(); 172 web_ui_->tab_contents()->browser_context()->GetPath();
174 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index); 173 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
175 FilePath profile_path = cache.GetPathOfProfileAtIndex(index); 174 FilePath profile_path = cache.GetPathOfProfileAtIndex(index);
176 profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index)); 175 profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index));
177 profile_value.SetString("iconURL", 176 profile_value.SetString("iconURL",
178 cache.GetDefaultAvatarIconUrl(icon_index)); 177 profiles::GetDefaultAvatarIconUrl(icon_index));
179 profile_value.Set("filePath", base::CreateFilePathValue(profile_path)); 178 profile_value.Set("filePath", base::CreateFilePathValue(profile_path));
180 profile_value.SetBoolean("isCurrentProfile", 179 profile_value.SetBoolean("isCurrentProfile",
181 profile_path == current_profile_path); 180 profile_path == current_profile_path);
182 181
183 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo", 182 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo",
184 profile_value); 183 profile_value);
185 } 184 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.mm ('k') | chrome/browser/ui/webui/options/personal_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698