Chromium Code Reviews| 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* prof = | |
|
sail
2011/12/02 19:07:10
abbreviating names is bad, profile would be better
jwd
2011/12/02 21:10:16
Done.
| |
| 151 g_browser_process->profile_manager()->GetProfile(profile_file_path); | |
| 152 if (!prof) | |
| 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 cache.SetNameOfProfileAtIndex(profile_index, new_profile_name); |
| 160 // Changing the profile name can invalidate the profile index. | 165 // Changing the profile name can invalidate the profile index. |
| 161 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 166 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
| 162 if (profile_index == std::string::npos) | 167 if (profile_index == std::string::npos) |
| 163 return; | 168 return; |
| 164 | 169 |
| 165 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); | 170 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, false); |
| 166 // Unsetting the GAIA name as the profile name can invalidate the profile | 171 // Unsetting the GAIA name as the profile name can invalidate the profile |
| 167 // index. | 172 // index. |
| 168 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 173 profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); |
| 169 if (profile_index == std::string::npos) | 174 if (profile_index == std::string::npos) |
| 170 return; | 175 return; |
| 171 } | 176 } |
| 172 | 177 |
| 173 std::string icon_url; | 178 std::string icon_url; |
| 174 if (!args->GetString(2, &icon_url)) | 179 if (!args->GetString(2, &icon_url)) |
| 175 return; | 180 return; |
| 176 | 181 |
| 182 PrefService* pref_service = prof->GetPrefs(); | |
| 183 pref_service->SetString(prefs::kProfileName,UTF16ToUTF8(new_profile_name)); | |
|
sail
2011/12/02 19:07:10
I don't think this is a good place to set this pre
jwd
2011/12/02 21:10:16
This code was actually in the wrong place. In the
| |
| 184 | |
| 177 size_t new_icon_index; | 185 size_t new_icon_index; |
| 178 if (icon_url == gaia_picture_url_) { | 186 if (icon_url == gaia_picture_url_) { |
| 179 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); | 187 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); |
| 180 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { | 188 } else if (cache.IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { |
| 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); |
| 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 Loading... | |
| 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 } |
| OLD | NEW |