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

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

Issue 8771024: Making profile avatars and names sync. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: adding comments and fixing problems Created 9 years 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/profiles/profile_manager_unittest.cc ('k') | chrome/common/pref_names.h » ('j') | 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) 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/gaia_info_update_service.h" 15 #include "chrome/browser/profiles/gaia_info_update_service.h"
16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_info_cache.h" 17 #include "chrome/browser/profiles/profile_info_cache.h"
16 #include "chrome/browser/profiles/profile_info_util.h" 18 #include "chrome/browser/profiles/profile_info_util.h"
17 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/profiles/profile_metrics.h" 20 #include "chrome/browser/profiles/profile_metrics.h"
19 #include "chrome/browser/ui/webui/web_ui_util.h" 21 #include "chrome/browser/ui/webui/web_ui_util.h"
20 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/pref_names.h"
21 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
22 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
23 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
24 27
25 ManageProfileHandler::ManageProfileHandler() { 28 ManageProfileHandler::ManageProfileHandler() {
26 } 29 }
27 30
28 ManageProfileHandler::~ManageProfileHandler() { 31 ManageProfileHandler::~ManageProfileHandler() {
29 } 32 }
30 33
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 135
133 Value* file_path_value; 136 Value* file_path_value;
134 FilePath profile_file_path; 137 FilePath profile_file_path;
135 if (!args->Get(0, &file_path_value) || 138 if (!args->Get(0, &file_path_value) ||
136 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) 139 !base::GetValueAsFilePath(*file_path_value, &profile_file_path))
137 return; 140 return;
138 141
139 ProfileInfoCache& cache = 142 ProfileInfoCache& cache =
140 g_browser_process->profile_manager()->GetProfileInfoCache(); 143 g_browser_process->profile_manager()->GetProfileInfoCache();
141 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 144 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
142 if (profile_index == std::string::npos)
143 return;
144 145
145 string16 new_profile_name; 146 string16 new_profile_name;
146 if (!args->GetString(1, &new_profile_name)) 147 if (!args->GetString(1, &new_profile_name))
147 return; 148 return;
148 149
150 Profile* profile =
151 g_browser_process->profile_manager()->GetProfile(profile_file_path);
152 if (!profile)
153 return;
149 if (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index)) { 154 if (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index)) {
150 // Set the profile to use the GAIA name as the profile name. Note, this 155 // Set the profile to use the GAIA name as the profile name. Note, this
151 // is a little weird if the user typed their GAIA name manually but 156 // is a little weird if the user typed their GAIA name manually but
152 // it's not a big deal. 157 // it's not a big deal.
153 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); 158 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true);
154 // Using the GAIA name as the profile name can invalidate the profile index. 159 // Using the GAIA name as the profile name can invalidate the profile index.
155 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 160 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
156 if (profile_index == std::string::npos) 161 if (profile_index == std::string::npos)
157 return; 162 return;
158 } else { 163 } else {
159 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name); 164 PrefService* pref_service = profile->GetPrefs();
165 pref_service->SetString(prefs::kProfileName,UTF16ToUTF8(new_profile_name));
csilv 2011/12/02 23:40:18 nit: space after comma
jwd 2011/12/03 00:13:10 Done.
166
160 // Changing the profile name can invalidate the profile index. 167 // Changing the profile name can invalidate the profile index.
161 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 168 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
162 if (profile_index == std::string::npos) 169 if (profile_index == std::string::npos)
163 return; 170 return;
164 171
165 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); 172 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false);
166 // Unsetting the GAIA name as the profile name can invalidate the profile 173 // Unsetting the GAIA name as the profile name can invalidate the profile
167 // index. 174 // index.
168 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); 175 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path);
169 if (profile_index == std::string::npos) 176 if (profile_index == std::string::npos)
170 return; 177 return;
171 } 178 }
172 179
173 std::string icon_url; 180 std::string icon_url;
174 if (!args->GetString(2, &icon_url)) 181 if (!args->GetString(2, &icon_url))
175 return; 182 return;
176 183
177 size_t new_icon_index; 184 size_t new_icon_index;
178 if (icon_url == gaia_picture_url_) { 185 if (icon_url == gaia_picture_url_) {
179 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); 186 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true);
180 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { 187 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) {
188 PrefService* pref_service = profile->GetPrefs();
181 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); 189 ProfileMetrics::LogProfileAvatarSelection(new_icon_index);
182 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index); 190 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index);
sail 2011/12/02 23:29:57 can you add a comment that the profile will update
jwd 2011/12/03 00:13:10 Done.
183 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); 191 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false);
184 } 192 }
185 193
186 ProfileMetrics::LogProfileUpdate(profile_file_path); 194 ProfileMetrics::LogProfileUpdate(profile_file_path);
187 } 195 }
188 196
189 void ManageProfileHandler::DeleteProfile(const ListValue* args) { 197 void ManageProfileHandler::DeleteProfile(const ListValue* args) {
190 DCHECK(args); 198 DCHECK(args);
191 199
192 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); 200 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 if (i == std::string::npos) 289 if (i == std::string::npos)
282 return; 290 return;
283 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); 291 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i);
284 if (gaia_name.empty()) 292 if (gaia_name.empty())
285 return; 293 return;
286 294
287 StringValue gaia_name_value(gaia_name); 295 StringValue gaia_name_value(gaia_name);
288 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileName", 296 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileName",
289 gaia_name_value); 297 gaia_name_value);
290 } 298 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager_unittest.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698