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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/manage_profile_handler.cc
diff --git a/chrome/browser/ui/webui/options/manage_profile_handler.cc b/chrome/browser/ui/webui/options/manage_profile_handler.cc
index ec38b07f8b25e524aa3bb0172b0c79a11410c00d..5131aa5b58b85b54b58bcf7bbd3da4d255d25c81 100644
--- a/chrome/browser/ui/webui/options/manage_profile_handler.cc
+++ b/chrome/browser/ui/webui/options/manage_profile_handler.cc
@@ -11,6 +11,7 @@
#include "base/value_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile_info_util.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
@@ -76,8 +77,8 @@ void ManageProfileHandler::Observe(
void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) {
ListValue image_url_list;
- for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
- std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
+ for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) {
+ std::string url = profiles::GetDefaultAvatarIconUrl(i);
image_url_list.Append(Value::CreateStringValue(url));
}
@@ -87,12 +88,15 @@ void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) {
}
void ManageProfileHandler::SendProfileNames() {
+ DictionaryValue profile_name_dict;
+
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
- DictionaryValue profile_name_dict;
- for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i)
- profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)),
- true);
+ const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName());
+ for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin();
+ it != entries.end(); ++it) {
+ profile_name_dict.SetBoolean(UTF16ToUTF8(it->name()), true);
+ }
web_ui_->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames",
profile_name_dict);
@@ -109,30 +113,25 @@ void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) {
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
- size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
- if (profile_index == std::string::npos)
+ ProfileInfoEntry entry;
+ if (!cache.GetInfoForProfile(profile_file_path, &entry))
return;
string16 new_profile_name;
if (!args->GetString(1, &new_profile_name))
return;
- cache.SetNameOfProfileAtIndex(profile_index, new_profile_name);
- // The index in the cache may have changed if a new name triggered an
- // alphabetical resort.
- profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
- if (profile_index == std::string::npos)
- return;
-
string16 icon_url;
size_t new_icon_index;
if (!args->GetString(2, &icon_url) ||
- !cache.IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index))
+ !profiles::IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index))
return;
- ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
- cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
+ entry.set_name(new_profile_name);
+ entry.set_icon_index(new_icon_index);
+ cache.SetInfoForProfile(entry);
+ ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
ProfileMetrics::LogProfileUpdate(profile_file_path);
}
@@ -175,7 +174,7 @@ void ManageProfileHandler::RequestProfileInfo(const ListValue* args) {
FilePath profile_path = cache.GetPathOfProfileAtIndex(index);
profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index));
profile_value.SetString("iconURL",
- cache.GetDefaultAvatarIconUrl(icon_index));
+ profiles::GetDefaultAvatarIconUrl(icon_index));
profile_value.Set("filePath", base::CreateFilePathValue(profile_path));
profile_value.SetBoolean("isCurrentProfile",
profile_path == current_profile_path);
« 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