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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/profiles_manage_handler.cc
diff --git a/chrome/browser/ui/webui/options/profiles_manage_handler.cc b/chrome/browser/ui/webui/options/profiles_manage_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e82ecb35954cb7144f70290cac230d20862d20c9
--- /dev/null
+++ b/chrome/browser/ui/webui/options/profiles_manage_handler.cc
@@ -0,0 +1,117 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/options/profiles_manage_handler.h"
+
+#include "base/string_number_conversions.h"
+#include "base/utf_string_conversions.h"
+#include "base/value_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/common/notification_service.h"
+#include "grit/generated_resources.h"
+
+ProfilesManageHandler::ProfilesManageHandler() {
+}
+
+ProfilesManageHandler::~ProfilesManageHandler() {
+}
+
+void ProfilesManageHandler::GetLocalizedValues(
+ DictionaryValue* localized_strings) {
+ DCHECK(localized_strings);
+
+ static OptionsStringResource resources[] = {
+ { "profilesManageTitle", IDS_PROFILES_MANAGE_TITLE },
+ { "profilesManageNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL },
+ { "profilesManageDuplicateNameError",
+ IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR },
+ { "profilesManageIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL },
+ { "profilesManageOK", IDS_OK },
+ { "profilesManageCancel", IDS_CANCEL },
+ };
+
+ RegisterStrings(localized_strings, resources, arraysize(resources));
+}
+
+void ProfilesManageHandler::Initialize() {
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
+ NotificationService::AllSources());
+ SendProfileIcons();
+ SendProfileNames();
+}
+
+void ProfilesManageHandler::RegisterMessages() {
+ web_ui_->RegisterMessageCallback("setProfileNameAndIcon",
+ NewCallback(this, &ProfilesManageHandler::SetProfileNameAndIcon));
+}
+
+void ProfilesManageHandler::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
+ SendProfileNames();
+ } else {
+ OptionsPageUIHandler::Observe(type, source, details);
+ }
+}
+
+void ProfilesManageHandler::SendProfileIcons() {
Miranda Callahan 2011/07/19 20:40:55 I feel like this should be changed to "InitializeD
+ ListValue image_url_list;
+ for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
+ std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
+ image_url_list.Append(Value::CreateStringValue(url));
+ }
+ web_ui_->CallJavascriptFunction("ProfilesManageOverlay.receiveProfileIcons",
+ image_url_list);
+}
+
+void ProfilesManageHandler::SendProfileNames() {
+ 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);
+ }
+
+ web_ui_->CallJavascriptFunction("ProfilesManageOverlay.receiveProfileNames",
+ profile_name_dict);
+}
+
+void ProfilesManageHandler::SetProfileNameAndIcon(const ListValue* args) {
+ Value* file_path_value;
+ FilePath profile_file_path;
+ if (!args->Get(0, &file_path_value) ||
+ !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) {
+ return;
+ }
+
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
+ if (profile_index == std::string::npos) {
sail 2011/07/19 19:39:50 no need for braces for single line statements, mor
+ return;
+ }
+
+ string16 new_profile_name;
+ if (!args->GetString(1, &new_profile_name)) {
+ return;
+ }
+
+ cache.SetNameOfProfileAtIndex(profile_index, new_profile_name);
+
+ string16 icon_url;
+ size_t new_icon_index;
+ if (!args->GetString(2, &icon_url) ||
+ !cache.IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index)) {
+ return;
+ }
+
+ cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
+}
+

Powered by Google App Engine
This is Rietveld 408576698