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" | |
15 #include "chrome/browser/profiles/gaia_info_update_service.h" | 14 #include "chrome/browser/profiles/gaia_info_update_service.h" |
16 #include "chrome/browser/profiles/profile.h" | |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_info_util.h" | 16 #include "chrome/browser/profiles/profile_info_util.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/profiles/profile_metrics.h" | 18 #include "chrome/browser/profiles/profile_metrics.h" |
21 #include "chrome/browser/ui/webui/web_ui_util.h" | 19 #include "chrome/browser/ui/webui/web_ui_util.h" |
22 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/pref_names.h" | |
24 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
25 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
26 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
27 | 24 |
28 ManageProfileHandler::ManageProfileHandler() { | 25 ManageProfileHandler::ManageProfileHandler() { |
29 } | 26 } |
30 | 27 |
31 ManageProfileHandler::~ManageProfileHandler() { | 28 ManageProfileHandler::~ManageProfileHandler() { |
32 } | 29 } |
33 | 30 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 132 |
136 Value* file_path_value; | 133 Value* file_path_value; |
137 FilePath profile_file_path; | 134 FilePath profile_file_path; |
138 if (!args->Get(0, &file_path_value) || | 135 if (!args->Get(0, &file_path_value) || |
139 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) | 136 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) |
140 return; | 137 return; |
141 | 138 |
142 ProfileInfoCache& cache = | 139 ProfileInfoCache& cache = |
143 g_browser_process->profile_manager()->GetProfileInfoCache(); | 140 g_browser_process->profile_manager()->GetProfileInfoCache(); |
144 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 141 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
| 142 if (profile_index == std::string::npos) |
| 143 return; |
145 | 144 |
146 string16 new_profile_name; | 145 string16 new_profile_name; |
147 if (!args->GetString(1, &new_profile_name)) | 146 if (!args->GetString(1, &new_profile_name)) |
148 return; | 147 return; |
149 | 148 |
150 Profile* profile = | |
151 g_browser_process->profile_manager()->GetProfile(profile_file_path); | |
152 if (!profile) | |
153 return; | |
154 if (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index)) { | 149 if (new_profile_name == cache.GetGAIANameOfProfileAtIndex(profile_index)) { |
155 // Set the profile to use the GAIA name as the profile name. Note, this | 150 // Set the profile to use the GAIA name as the profile name. Note, this |
156 // is a little weird if the user typed their GAIA name manually but | 151 // is a little weird if the user typed their GAIA name manually but |
157 // it's not a big deal. | 152 // it's not a big deal. |
158 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); | 153 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); |
159 // Using the GAIA name as the profile name can invalidate the profile index. | 154 // Using the GAIA name as the profile name can invalidate the profile index. |
160 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 155 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
161 if (profile_index == std::string::npos) | 156 if (profile_index == std::string::npos) |
162 return; | 157 return; |
163 } else { | 158 } else { |
164 PrefService* pref_service = profile->GetPrefs(); | 159 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name); |
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 | |
169 // Changing the profile name can invalidate the profile index. | 160 // Changing the profile name can invalidate the profile index. |
170 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 161 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
171 if (profile_index == std::string::npos) | 162 if (profile_index == std::string::npos) |
172 return; | 163 return; |
173 | 164 |
174 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); | 165 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); |
175 // Unsetting the GAIA name as the profile name can invalidate the profile | 166 // Unsetting the GAIA name as the profile name can invalidate the profile |
176 // index. | 167 // index. |
177 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 168 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
178 if (profile_index == std::string::npos) | 169 if (profile_index == std::string::npos) |
179 return; | 170 return; |
180 } | 171 } |
181 | 172 |
182 std::string icon_url; | 173 std::string icon_url; |
183 if (!args->GetString(2, &icon_url)) | 174 if (!args->GetString(2, &icon_url)) |
184 return; | 175 return; |
185 | 176 |
186 size_t new_icon_index; | 177 size_t new_icon_index; |
187 if (icon_url == gaia_picture_url_) { | 178 if (icon_url == gaia_picture_url_) { |
188 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); | 179 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); |
189 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { | 180 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { |
190 PrefService* pref_service = profile->GetPrefs(); | |
191 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); | 181 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); |
192 // Updating the profile preference will cause the cache to be updated for | 182 cache.SetAvatarIconOfProfileAtIndex(profile_index, new_icon_index); |
193 // this preference. | |
194 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); | |
195 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); | 183 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, false); |
196 } | 184 } |
197 | 185 |
198 ProfileMetrics::LogProfileUpdate(profile_file_path); | 186 ProfileMetrics::LogProfileUpdate(profile_file_path); |
199 } | 187 } |
200 | 188 |
201 void ManageProfileHandler::DeleteProfile(const ListValue* args) { | 189 void ManageProfileHandler::DeleteProfile(const ListValue* args) { |
202 DCHECK(args); | 190 DCHECK(args); |
203 | 191 |
204 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); | 192 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 if (i == std::string::npos) | 281 if (i == std::string::npos) |
294 return; | 282 return; |
295 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); | 283 string16 gaia_name = cache.GetGAIANameOfProfileAtIndex(i); |
296 if (gaia_name.empty()) | 284 if (gaia_name.empty()) |
297 return; | 285 return; |
298 | 286 |
299 StringValue gaia_name_value(gaia_name); | 287 StringValue gaia_name_value(gaia_name); |
300 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileName", | 288 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileName", |
301 gaia_name_value); | 289 gaia_name_value); |
302 } | 290 } |
OLD | NEW |