| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/settings/settings_manage_profile_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/value_conversions.h" | 12 #include "base/value_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/profiles/gaia_info_update_service.h" | 16 #include "chrome/browser/profiles/gaia_info_update_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 18 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 19 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/profiles/profile_metrics.h" | 21 #include "chrome/browser/profiles/profile_metrics.h" |
| 22 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 22 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 23 #include "chrome/browser/profiles/profile_window.h" | 23 #include "chrome/browser/profiles/profile_window.h" |
| 24 #include "chrome/browser/profiles/profiles_state.h" | 24 #include "chrome/browser/profiles/profiles_state.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 25 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 27 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 30 #include "chrome/grit/chromium_strings.h" | 30 #include "chrome/grit/chromium_strings.h" |
| 31 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 32 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 33 #include "components/prefs/scoped_user_pref_update.h" | 33 #include "components/prefs/scoped_user_pref_update.h" |
| 34 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
| 35 #include "components/signin/core/common/profile_management_switches.h" | 35 #include "components/signin/core/common/profile_management_switches.h" |
| 36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/web_ui.h" | 38 #include "content/public/browser/web_ui.h" |
| 39 #include "google_apis/gaia/gaia_auth_util.h" | 39 #include "google_apis/gaia/gaia_auth_util.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/base/webui/web_ui_util.h" | 41 #include "ui/base/webui/web_ui_util.h" |
| 42 | 42 |
| 43 namespace settings { | 43 namespace settings { |
| 44 | 44 |
| 45 ManageProfileHandler::ManageProfileHandler(Profile* profile) | 45 ManageProfileHandler::ManageProfileHandler(Profile* profile) |
| 46 : profile_(profile), weak_factory_(this) { | 46 : profile_(profile), weak_factory_(this) { |
| 47 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 47 g_browser_process->profile_manager()-> |
| 48 GetProfileAttributesStorage().AddObserver(this); |
| 48 } | 49 } |
| 49 | 50 |
| 50 ManageProfileHandler::~ManageProfileHandler() { | 51 ManageProfileHandler::~ManageProfileHandler() { |
| 51 g_browser_process->profile_manager()-> | 52 g_browser_process->profile_manager()-> |
| 52 GetProfileInfoCache().RemoveObserver(this); | 53 GetProfileAttributesStorage().RemoveObserver(this); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void ManageProfileHandler::RegisterMessages() { | 56 void ManageProfileHandler::RegisterMessages() { |
| 56 web_ui()->RegisterMessageCallback("setProfileIconAndName", | 57 web_ui()->RegisterMessageCallback("setProfileIconAndName", |
| 57 base::Bind(&ManageProfileHandler::SetProfileIconAndName, | 58 base::Bind(&ManageProfileHandler::SetProfileIconAndName, |
| 58 base::Unretained(this))); | 59 base::Unretained(this))); |
| 59 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", | 60 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", |
| 60 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, | 61 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, |
| 61 base::Unretained(this))); | 62 base::Unretained(this))); |
| 62 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", | 63 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 87 SendAvailableIcons(); | 88 SendAvailableIcons(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void ManageProfileHandler::RequestDefaultProfileIcons( | 91 void ManageProfileHandler::RequestDefaultProfileIcons( |
| 91 const base::ListValue* args) { | 92 const base::ListValue* args) { |
| 92 SendAvailableIcons(); | 93 SendAvailableIcons(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void ManageProfileHandler::SendAvailableIcons() { | 96 void ManageProfileHandler::SendAvailableIcons() { |
| 96 base::ListValue image_url_list; | 97 base::ListValue image_url_list; |
| 97 const ProfileInfoCache& cache = | |
| 98 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 99 | 98 |
| 100 // First add the GAIA picture if it is available. | 99 // First add the GAIA picture if it is available. |
| 101 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 100 ProfileAttributesEntry* entry; |
| 102 if (profile_index != std::string::npos) { | 101 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 103 const gfx::Image* icon = | 102 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { |
| 104 cache.GetGAIAPictureOfProfileAtIndex(profile_index); | 103 const gfx::Image* icon = entry->GetGAIAPicture(); |
| 105 if (icon) { | 104 if (icon) { |
| 106 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); | 105 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); |
| 107 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); | 106 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); |
| 108 image_url_list.AppendString(gaia_picture_url_); | 107 image_url_list.AppendString(gaia_picture_url_); |
| 109 } | 108 } |
| 110 } | 109 } |
| 111 | 110 |
| 112 // Next add the default avatar icons and names. | 111 // Next add the default avatar icons and names. |
| 113 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { | 112 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { |
| 114 std::string url = profiles::GetDefaultAvatarIconUrl(i); | 113 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 std::string icon_url; | 173 std::string icon_url; |
| 175 if (!args->GetString(0, &icon_url)) | 174 if (!args->GetString(0, &icon_url)) |
| 176 return; | 175 return; |
| 177 | 176 |
| 178 if (icon_url != gaia_picture_url_) | 177 if (icon_url != gaia_picture_url_) |
| 179 return; | 178 return; |
| 180 | 179 |
| 181 // If the selection is the GAIA picture then also show the profile name in the | 180 // If the selection is the GAIA picture then also show the profile name in the |
| 182 // text field. This will display either the GAIA given name, if available, | 181 // text field. This will display either the GAIA given name, if available, |
| 183 // or the first name. | 182 // or the first name. |
| 184 ProfileInfoCache& cache = | 183 ProfileAttributesEntry* entry; |
| 185 g_browser_process->profile_manager()->GetProfileInfoCache(); | 184 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 186 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 185 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { |
| 187 if (profile_index == std::string::npos) | |
| 188 return; | 186 return; |
| 189 base::string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index); | 187 } |
| 188 base::string16 gaia_name = entry->GetName(); |
| 190 if (gaia_name.empty()) | 189 if (gaia_name.empty()) |
| 191 return; | 190 return; |
| 192 | 191 |
| 193 base::StringValue gaia_name_value(gaia_name); | |
| 194 web_ui()->CallJavascriptFunction( | 192 web_ui()->CallJavascriptFunction( |
| 195 "settings.SyncPrivateApi.setProfileName", | 193 "settings.SyncPrivateApi.setProfileName", |
| 196 gaia_name_value); | 194 base::StringValue(gaia_name)); |
| 197 } | 195 } |
| 198 | 196 |
| 199 void ManageProfileHandler::RequestHasProfileShortcuts( | 197 void ManageProfileHandler::RequestHasProfileShortcuts( |
| 200 const base::ListValue* args) { | 198 const base::ListValue* args) { |
| 201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 199 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 202 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 200 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 203 | 201 |
| 204 const ProfileInfoCache& cache = | 202 ProfileAttributesStorage& storage = |
| 205 g_browser_process->profile_manager()->GetProfileInfoCache(); | 203 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 206 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 204 ProfileAttributesEntry* entry; |
| 207 if (profile_index == std::string::npos) | 205 if (!storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) |
| 208 return; | 206 return; |
| 209 | 207 |
| 210 // Don't show the add/remove desktop shortcut button in the single user case. | 208 // Don't show the add/remove desktop shortcut button in the single user case. |
| 211 if (cache.GetNumberOfProfiles() <= 1) | 209 if (storage.GetNumberOfProfiles() <= 1u) |
| 212 return; | 210 return; |
| 213 | 211 |
| 214 const base::FilePath profile_path = | |
| 215 cache.GetPathOfProfileAtIndex(profile_index); | |
| 216 ProfileShortcutManager* shortcut_manager = | 212 ProfileShortcutManager* shortcut_manager = |
| 217 g_browser_process->profile_manager()->profile_shortcut_manager(); | 213 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 218 shortcut_manager->HasProfileShortcuts( | 214 shortcut_manager->HasProfileShortcuts( |
| 219 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, | 215 profile_->GetPath(), |
| 220 weak_factory_.GetWeakPtr())); | 216 base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, |
| 217 weak_factory_.GetWeakPtr())); |
| 221 } | 218 } |
| 222 | 219 |
| 223 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 220 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { |
| 224 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 221 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 225 | 222 |
| 226 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 223 const base::FundamentalValue has_shortcuts_value(has_shortcuts); |
| 227 web_ui()->CallJavascriptFunction( | 224 web_ui()->CallJavascriptFunction( |
| 228 "settings.SyncPrivateApi.receiveHasProfileShortcuts", | 225 "settings.SyncPrivateApi.receiveHasProfileShortcuts", |
| 229 has_shortcuts_value); | 226 has_shortcuts_value); |
| 230 } | 227 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 251 | 248 |
| 252 // Update the UI buttons. | 249 // Update the UI buttons. |
| 253 OnHasProfileShortcuts(false); | 250 OnHasProfileShortcuts(false); |
| 254 } | 251 } |
| 255 | 252 |
| 256 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { | 253 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { |
| 257 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); | 254 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); |
| 258 } | 255 } |
| 259 | 256 |
| 260 } // namespace settings | 257 } // namespace settings |
| OLD | NEW |