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

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

Issue 10825126: Valgrind: Fix a leak in ManageProfileHandler::SendProfileIcons(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « chrome/browser/ui/webui/options2/manage_profile_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options2/manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/options2/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/prefs/pref_service.h"
15 #include "chrome/browser/profiles/gaia_info_update_service.h" 15 #include "chrome/browser/profiles/gaia_info_update_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_info_cache.h" 17 #include "chrome/browser/profiles/profile_info_cache.h"
18 #include "chrome/browser/profiles/profile_info_util.h" 18 #include "chrome/browser/profiles/profile_info_util.h"
19 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/profiles/profile_metrics.h" 20 #include "chrome/browser/profiles/profile_metrics.h"
21 #include "chrome/browser/ui/webui/web_ui_util.h" 21 #include "chrome/browser/ui/webui/web_ui_util.h"
22 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 27
28 namespace options2 { 28 namespace options2 {
29 29
30 namespace {
31
32 const char kCreateProfileIconGridName[] = "create-profile-icon-grid";
33 const char kManageProfileIconGridName[] = "manage-profile-icon-grid";
34
35 } // namespace
36
30 ManageProfileHandler::ManageProfileHandler() { 37 ManageProfileHandler::ManageProfileHandler() {
31 } 38 }
32 39
33 ManageProfileHandler::~ManageProfileHandler() { 40 ManageProfileHandler::~ManageProfileHandler() {
34 } 41 }
35 42
36 void ManageProfileHandler::GetLocalizedValues( 43 void ManageProfileHandler::GetLocalizedValues(
37 DictionaryValue* localized_strings) { 44 DictionaryValue* localized_strings) {
38 DCHECK(localized_strings); 45 DCHECK(localized_strings);
39 46
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, 86 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged,
80 base::Unretained(this))); 87 base::Unretained(this)));
81 } 88 }
82 89
83 void ManageProfileHandler::Observe( 90 void ManageProfileHandler::Observe(
84 int type, 91 int type,
85 const content::NotificationSource& source, 92 const content::NotificationSource& source,
86 const content::NotificationDetails& details) { 93 const content::NotificationDetails& details) {
87 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { 94 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
88 SendProfileNames(); 95 SendProfileNames();
89 SendProfileIcons(Value::CreateStringValue("manage-profile-icon-grid")); 96 base::StringValue value(kManageProfileIconGridName);
97 SendProfileIcons(value);
90 } else { 98 } else {
91 OptionsPageUIHandler::Observe(type, source, details); 99 OptionsPageUIHandler::Observe(type, source, details);
92 } 100 }
93 } 101 }
94 102
95 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) { 103 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) {
96 SendProfileIcons(Value::CreateStringValue("manage-profile-icon-grid")); 104 base::StringValue create_value(kCreateProfileIconGridName);
97 SendProfileIcons(Value::CreateStringValue("create-profile-icon-grid")); 105 base::StringValue manage_value(kManageProfileIconGridName);
106 SendProfileIcons(manage_value);
107 SendProfileIcons(create_value);
98 } 108 }
99 109
100 void ManageProfileHandler::SendProfileIcons(base::StringValue* icon_grid) { 110 void ManageProfileHandler::SendProfileIcons(
111 const base::StringValue& icon_grid) {
101 ListValue image_url_list; 112 ListValue image_url_list;
102 113
103 // First add the GAIA picture if it's available. 114 // First add the GAIA picture if it's available.
104 ProfileInfoCache& cache = 115 ProfileInfoCache& cache =
105 g_browser_process->profile_manager()->GetProfileInfoCache(); 116 g_browser_process->profile_manager()->GetProfileInfoCache();
106 Profile* profile = Profile::FromWebUI(web_ui()); 117 Profile* profile = Profile::FromWebUI(web_ui());
107 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 118 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
108 if (profile_index != std::string::npos) { 119 if (profile_index != std::string::npos) {
109 const gfx::Image* icon = 120 const gfx::Image* icon =
110 cache.GetGAIAPictureOfProfileAtIndex(profile_index); 121 cache.GetGAIAPictureOfProfileAtIndex(profile_index);
111 if (icon) { 122 if (icon) {
112 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); 123 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true);
113 gaia_picture_url_ = web_ui_util::GetImageDataUrl(*icon2.ToImageSkia()); 124 gaia_picture_url_ = web_ui_util::GetImageDataUrl(*icon2.ToImageSkia());
114 image_url_list.Append(Value::CreateStringValue(gaia_picture_url_)); 125 image_url_list.Append(Value::CreateStringValue(gaia_picture_url_));
115 } 126 }
116 } 127 }
117 128
118 // Next add the default avatar icons. 129 // Next add the default avatar icons.
119 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) { 130 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
120 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); 131 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
121 image_url_list.Append(Value::CreateStringValue(url)); 132 image_url_list.Append(Value::CreateStringValue(url));
122 } 133 }
123 134
124 web_ui()->CallJavascriptFunction( 135 web_ui()->CallJavascriptFunction(
125 "ManageProfileOverlay.receiveDefaultProfileIcons", *icon_grid, 136 "ManageProfileOverlay.receiveDefaultProfileIcons", icon_grid,
126 image_url_list); 137 image_url_list);
127 } 138 }
128 139
129 void ManageProfileHandler::SendProfileNames() { 140 void ManageProfileHandler::SendProfileNames() {
130 ProfileInfoCache& cache = 141 ProfileInfoCache& cache =
131 g_browser_process->profile_manager()->GetProfileInfoCache(); 142 g_browser_process->profile_manager()->GetProfileInfoCache();
132 DictionaryValue profile_name_dict; 143 DictionaryValue profile_name_dict;
133 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) 144 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i)
134 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), 145 profile_name_dict.SetBoolean(UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)),
135 true); 146 true);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); 281 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i);
271 if (gaia_name.empty()) 282 if (gaia_name.empty())
272 return; 283 return;
273 284
274 StringValue gaia_name_value(gaia_name); 285 StringValue gaia_name_value(gaia_name);
275 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", 286 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName",
276 gaia_name_value); 287 gaia_name_value);
277 } 288 }
278 289
279 } // namespace options2 290 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/manage_profile_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698