OLD | NEW |
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 Loading... |
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 // Updating the profile preference will cause the cache to be updated for |
| 166 // this preference. |
| 167 pref_service->SetString(prefs::kProfileName, UTF16ToUTF8(new_profile_name)); |
| 168 |
160 // Changing the profile name can invalidate the profile index. | 169 // Changing the profile name can invalidate the profile index. |
161 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 170 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
162 if (profile_index == std::string::npos) | 171 if (profile_index == std::string::npos) |
163 return; | 172 return; |
164 | 173 |
165 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); | 174 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); |
166 // Unsetting the GAIA name as the profile name can invalidate the profile | 175 // Unsetting the GAIA name as the profile name can invalidate the profile |
167 // index. | 176 // index. |
168 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 177 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
169 if (profile_index == std::string::npos) | 178 if (profile_index == std::string::npos) |
(...skipping 11 matching lines...) Expand all Loading... |
181 size_t new_icon_index; | 190 size_t new_icon_index; |
182 if (icon_url == gaia_picture_url_) { | 191 if (icon_url == gaia_picture_url_) { |
183 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); | 192 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); |
184 if (!previously_using_gaia_icon) { | 193 if (!previously_using_gaia_icon) { |
185 // Only log if they changed to the GAIA photo. | 194 // Only log if they changed to the GAIA photo. |
186 // Selection of GAIA photo as avatar is logged as part of the function | 195 // Selection of GAIA photo as avatar is logged as part of the function |
187 // below. | 196 // below. |
188 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); | 197 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); |
189 } | 198 } |
190 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { | 199 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { |
| 200 PrefService* pref_service = profile->GetPrefs(); |
191 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); | 201 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); |
192 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index); | 202 // Updating the profile preference will cause the cache to be updated for |
| 203 // this preference. |
| 204 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); |
193 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); | 205 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); |
194 } | 206 } |
195 | 207 |
196 ProfileMetrics::LogProfileUpdate(profile_file_path); | 208 ProfileMetrics::LogProfileUpdate(profile_file_path); |
197 } | 209 } |
198 | 210 |
199 void ManageProfileHandler::DeleteProfile(const ListValue* args) { | 211 void ManageProfileHandler::DeleteProfile(const ListValue* args) { |
200 DCHECK(args); | 212 DCHECK(args); |
201 | 213 |
202 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); | 214 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (i == std::string::npos) | 303 if (i == std::string::npos) |
292 return; | 304 return; |
293 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); | 305 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); |
294 if (gaia_name.empty()) | 306 if (gaia_name.empty()) |
295 return; | 307 return; |
296 | 308 |
297 StringValue gaia_name_value(gaia_name); | 309 StringValue gaia_name_value(gaia_name); |
298 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileName", | 310 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileName", |
299 gaia_name_value); | 311 gaia_name_value); |
300 } | 312 } |
OLD | NEW |