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

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

Issue 7400032: Multi-profile WebUI settings (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: profiles_icon_list.js -> profiles_icon_grid.js 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/manage_profile_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 ManageProfileHandler::ManageProfileHandler() {
19 }
20
21 ManageProfileHandler::~ManageProfileHandler() {
22 }
23
24 void ManageProfileHandler::GetLocalizedValues(
25 DictionaryValue* localized_strings) {
26 DCHECK(localized_strings);
27
28 static OptionsStringResource resources[] = {
29 { "manageProfilesTitle", IDS_PROFILES_MANAGE_TITLE },
30 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL },
31 { "manageProfilesDuplicateNameError",
32 IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR },
33 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL },
34 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE },
35 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL },
36 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE },
37 };
38
39 RegisterStrings(localized_strings, resources, arraysize(resources));
40 }
41
42 void ManageProfileHandler::Initialize() {
43 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
44 NotificationService::AllSources());
45 InitializeDefaultProfileIcons();
46 SendProfileNames();
47 }
48
49 void ManageProfileHandler::RegisterMessages() {
50 web_ui_->RegisterMessageCallback("setProfileNameAndIcon",
51 NewCallback(this, &ManageProfileHandler::SetProfileNameAndIcon));
52 web_ui_->RegisterMessageCallback("deleteProfile",
53 NewCallback(this, &ManageProfileHandler::DeleteProfile));
54 }
55
56 void ManageProfileHandler::Observe(int type,
57 const NotificationSource& source,
58 const NotificationDetails& details) {
59 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED)
60 SendProfileNames();
61 else
62 OptionsPageUIHandler::Observe(type, source, details);
63 }
64
65 void ManageProfileHandler::InitializeDefaultProfileIcons() {
66 ListValue image_url_list;
67 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
68 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
69 image_url_list.Append(Value::CreateStringValue(url));
70 }
71
72 web_ui_->CallJavascriptFunction(
73 "ManageProfileOverlay.receiveDefaultProfileIcons",
74 image_url_list);
75 }
76
77 void ManageProfileHandler::SendProfileNames() {
78 ProfileInfoCache& cache =
79 g_browser_process->profile_manager()->GetProfileInfoCache();
80 DictionaryValue profile_name_dict;
81 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i)
82 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)),
83 true);
84
85 web_ui_->CallJavascriptFunction("ManageProfileOverlay.receiveProfileNames",
86 profile_name_dict);
87 }
88
89 void ManageProfileHandler::SetProfileNameAndIcon(const ListValue* args) {
90 Value* file_path_value;
91 FilePath profile_file_path;
92 if (!args->Get(0, &file_path_value) ||
93 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
94 return;
95
96 ProfileInfoCache& cache =
97 g_browser_process->profile_manager()->GetProfileInfoCache();
98 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
99 if (profile_index == std::string::npos)
100 return;
101
102 string16 new_profile_name;
103 if (!args->GetString(1, &new_profile_name))
104 return;
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 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
115 }
116
117 void ManageProfileHandler::DeleteProfile(const ListValue* args) {
118 Value* file_path_value;
119 FilePath profile_file_path;
120 if (!args->Get(0, &file_path_value) ||
121 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
122 return;
123
124 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
125 profile_file_path);
126 }
127
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/manage_profile_handler.h ('k') | chrome/browser/ui/webui/options/options_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698