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

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

Issue 8511064: GAIA Profile info prototype (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test 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/prefs/pref_service.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"
18 #include "chrome/browser/ui/webui/web_ui_util.h"
17 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/pref_names.h"
18 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
20 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "chrome/browser/profiles/profile_impl.h"
25
26 extern SkBitmap FixGAIABmp(const SkBitmap& bmp);
21 27
22 ManageProfileHandler::ManageProfileHandler() { 28 ManageProfileHandler::ManageProfileHandler() {
23 } 29 }
24 30
25 ManageProfileHandler::~ManageProfileHandler() { 31 ManageProfileHandler::~ManageProfileHandler() {
26 } 32 }
27 33
28 void ManageProfileHandler::GetLocalizedValues( 34 void ManageProfileHandler::GetLocalizedValues(
29 DictionaryValue* localized_strings) { 35 DictionaryValue* localized_strings) {
30 DCHECK(localized_strings); 36 DCHECK(localized_strings);
31 37
32 static OptionsStringResource resources[] = { 38 static OptionsStringResource resources[] = {
33 { "manageProfilesTitle", IDS_PROFILES_MANAGE_TITLE }, 39 { "manageProfilesTitle", IDS_PROFILES_MANAGE_TITLE },
34 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL }, 40 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL },
35 { "manageProfilesDuplicateNameError", 41 { "manageProfilesDuplicateNameError",
36 IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR }, 42 IDS_PROFILES_MANAGE_DUPLICATE_NAME_ERROR },
37 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL }, 43 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL },
38 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE }, 44 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE },
39 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL }, 45 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL },
40 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE }, 46 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE },
41 }; 47 };
42 48
43 RegisterStrings(localized_strings, resources, arraysize(resources)); 49 RegisterStrings(localized_strings, resources, arraysize(resources));
44 } 50 }
45 51
46 void ManageProfileHandler::Initialize() { 52 void ManageProfileHandler::Initialize() {
47 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 53 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
48 content::NotificationService::AllSources()); 54 content::NotificationService::AllSources());
49 SendProfileNames(); 55 SendProfileNames();
56
57 Profile* profile = Profile::FromWebUI(web_ui_);
58 ProfileImpl* profile_impl = static_cast<ProfileImpl*>(profile);
59 profile_impl->UpdateGAIAProfileInfo();
50 } 60 }
51 61
52 void ManageProfileHandler::RegisterMessages() { 62 void ManageProfileHandler::RegisterMessages() {
53 web_ui_->RegisterMessageCallback("setProfileNameAndIcon", 63 web_ui_->RegisterMessageCallback("setProfileNameAndIcon",
54 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon, 64 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon,
55 base::Unretained(this))); 65 base::Unretained(this)));
56 web_ui_->RegisterMessageCallback("deleteProfile", 66 web_ui_->RegisterMessageCallback("deleteProfile",
57 base::Bind(&ManageProfileHandler::DeleteProfile, 67 base::Bind(&ManageProfileHandler::DeleteProfile,
58 base::Unretained(this))); 68 base::Unretained(this)));
59 web_ui_->RegisterMessageCallback("requestDefaultProfileIcons", 69 web_ui_->RegisterMessageCallback("requestDefaultProfileIcons",
60 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, 70 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons,
61 base::Unretained(this))); 71 base::Unretained(this)));
62 web_ui_->RegisterMessageCallback("requestProfileInfo", 72 web_ui_->RegisterMessageCallback("requestProfileInfo",
63 base::Bind(&ManageProfileHandler::RequestProfileInfo, 73 base::Bind(&ManageProfileHandler::RequestProfileInfo,
64 base::Unretained(this))); 74 base::Unretained(this)));
65 } 75 }
66 76
67 void ManageProfileHandler::Observe( 77 void ManageProfileHandler::Observe(
68 int type, 78 int type,
69 const content::NotificationSource& source, 79 const content::NotificationSource& source,
70 const content::NotificationDetails& details) { 80 const content::NotificationDetails& details) {
71 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) 81 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
72 SendProfileNames(); 82 SendProfileNames();
73 else 83 SendProfileIcons();
84 } else {
74 OptionsPageUIHandler::Observe(type, source, details); 85 OptionsPageUIHandler::Observe(type, source, details);
86 }
75 } 87 }
76 88
77 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) { 89 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) {
90 SendProfileIcons();
91 }
92
93 void ManageProfileHandler::SendProfileIcons() {
78 ListValue image_url_list; 94 ListValue image_url_list;
95
96 ProfileInfoCache& cache =
97 g_browser_process->profile_manager()->GetProfileInfoCache();
98 Profile* profile = Profile::FromWebUI(web_ui_);
99 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
100 if (profile_index != std::string::npos) {
101 SkBitmap gaia_bmp = cache.GetGAIAPictureOfProfileAtIndex(profile_index);
102 if (!gaia_bmp.isNull()) {
103 SkBitmap bmp = FixGAIABmp(gaia_bmp);
104 gaia_profile_url_ = web_ui_util::GetImageDataUrl(bmp);
105 image_url_list.Append(Value::CreateStringValue(gaia_profile_url_));
106 }
107 }
108
79 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) { 109 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
80 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); 110 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
81 image_url_list.Append(Value::CreateStringValue(url)); 111 image_url_list.Append(Value::CreateStringValue(url));
82 } 112 }
83 113
84 web_ui_->CallJavascriptFunction( 114 web_ui_->CallJavascriptFunction(
85 "ManageProfileOverlay.receiveDefaultProfileIcons", 115 "ManageProfileOverlay.receiveDefaultProfileIcons",
86 image_url_list); 116 image_url_list);
87 } 117 }
88 118
(...skipping 17 matching lines...) Expand all
106 if (!args->Get(0, &file_path_value) || 136 if (!args->Get(0, &file_path_value) ||
107 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) 137 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
108 return; 138 return;
109 139
110 ProfileInfoCache& cache = 140 ProfileInfoCache& cache =
111 g_browser_process->profile_manager()->GetProfileInfoCache(); 141 g_browser_process->profile_manager()->GetProfileInfoCache();
112 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 142 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
113 if (profile_index == std::string::npos) 143 if (profile_index == std::string::npos)
114 return; 144 return;
115 145
146 cache.SetIsUsingGAIANameForProfileAtIndex(profile_index, false);
147 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
148 if (profile_index == std::string::npos)
149 return;
150
116 string16 new_profile_name; 151 string16 new_profile_name;
117 if (!args->GetString(1, &new_profile_name)) 152 if (!args->GetString(1, &new_profile_name))
118 return; 153 return;
119 154
155
120 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name); 156 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name);
121 // The index in the cache may have changed if a new name triggered an 157 // The index in the cache may have changed if a new name triggered an
122 // alphabetical resort. 158 // alphabetical resort.
123 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 159 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
124 if (profile_index == std::string::npos) 160 if (profile_index == std::string::npos)
125 return; 161 return;
126 162
127 string16 icon_url; 163 std::string icon_url;
128 size_t new_icon_index; 164 if (!args->GetString(2, &icon_url))
129 if (!args->GetString(2, &icon_url) ||
130 !cache.IsDefaultAvatarIconUrl(UTF16ToUTF8(icon_url), &new_icon_index))
131 return; 165 return;
132 166
133 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); 167 size_t new_icon_index;
134 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index); 168 if (icon_url == gaia_profile_url_) {
169 cache.SetIsUsingCustomAvatarIconForProfileAtIndex(
170 profile_index, true);
171 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) {
172 ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
173 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index);
174 cache.SetIsUsingCustomAvatarIconForProfileAtIndex(
175 profile_index, false);
176 } else {
177 return;
178 }
135 179
136 ProfileMetrics::LogProfileUpdate(profile_file_path); 180 ProfileMetrics::LogProfileUpdate(profile_file_path);
137 } 181 }
138 182
139 void ManageProfileHandler::DeleteProfile(const ListValue* args) { 183 void ManageProfileHandler::DeleteProfile(const ListValue* args) {
140 DCHECK(args); 184 DCHECK(args);
141 185
142 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::PROFILE_DELETED); 186 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::PROFILE_DELETED);
143 187
144 Value* file_path_value; 188 Value* file_path_value;
(...skipping 19 matching lines...) Expand all
164 int index = static_cast<int>(index_double); 208 int index = static_cast<int>(index_double);
165 209
166 ProfileInfoCache& cache = 210 ProfileInfoCache& cache =
167 g_browser_process->profile_manager()->GetProfileInfoCache(); 211 g_browser_process->profile_manager()->GetProfileInfoCache();
168 int profile_count = cache.GetNumberOfProfiles(); 212 int profile_count = cache.GetNumberOfProfiles();
169 if (index < 0 && index >= profile_count) 213 if (index < 0 && index >= profile_count)
170 return; 214 return;
171 215
172 FilePath current_profile_path = 216 FilePath current_profile_path =
173 web_ui_->tab_contents()->browser_context()->GetPath(); 217 web_ui_->tab_contents()->browser_context()->GetPath();
174 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
175 FilePath profile_path = cache.GetPathOfProfileAtIndex(index); 218 FilePath profile_path = cache.GetPathOfProfileAtIndex(index);
176 profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index)); 219 profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index));
177 profile_value.SetString("iconURL",
178 cache.GetDefaultAvatarIconUrl(icon_index));
179 profile_value.Set("filePath", base::CreateFilePathValue(profile_path)); 220 profile_value.Set("filePath", base::CreateFilePathValue(profile_path));
180 profile_value.SetBoolean("isCurrentProfile", 221 profile_value.SetBoolean("isCurrentProfile",
181 profile_path == current_profile_path); 222 profile_path == current_profile_path);
182 223
224 std::string bmp_url;
225 if (!cache.IsUsingCustomAvatarIconForProfileAtIndex(index)) {
226 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
227 bmp_url = cache.GetDefaultAvatarIconUrl(icon_index);
228 } else {
229 SkBitmap bmp = cache.GetGAIAPictureOfProfileAtIndex(index);
230 SkBitmap bmp2 = FixGAIABmp(bmp);
231 bmp_url = web_ui_util::GetImageDataUrl(bmp2);
232 }
233 profile_value.SetString("iconURL", bmp_url);
234
183 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo", 235 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo",
184 profile_value); 236 profile_value);
185 } 237 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/manage_profile_handler.h ('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