| 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/people_handler.h" | 5 #include "chrome/browser/ui/webui/settings/people_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/lifetime/application_lifetime.h" | 20 #include "chrome/browser/lifetime/application_lifetime.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 22 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 23 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 23 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 24 #include "chrome/browser/profiles/profile_metrics.h" | 24 #include "chrome/browser/profiles/profile_metrics.h" |
| 25 #include "chrome/browser/profiles/profile_window.h" | 25 #include "chrome/browser/profiles/profile_window.h" |
| 26 #include "chrome/browser/signin/chrome_signin_helper.h" | 26 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 27 #include "chrome/browser/signin/signin_error_controller_factory.h" | 27 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 28 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 29 #include "chrome/browser/signin/signin_promo.h" | 29 #include "chrome/browser/signin/signin_promo.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/browser/sync/sync_ui_util.h" | 31 #include "chrome/browser/sync/sync_ui_util.h" |
| 32 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 33 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 if (!name->empty()) | 176 if (!name->empty()) |
| 177 *name = gaia::SanitizeEmail(gaia::CanonicalizeEmail(*name)); | 177 *name = gaia::SanitizeEmail(gaia::CanonicalizeEmail(*name)); |
| 178 | 178 |
| 179 // Get image as data URL instead of using chrome://userimage source to avoid | 179 // Get image as data URL instead of using chrome://userimage source to avoid |
| 180 // issues with caching. | 180 // issues with caching. |
| 181 const AccountId account_id(AccountId::FromUserEmail(*name)); | 181 const AccountId account_id(AccountId::FromUserEmail(*name)); |
| 182 scoped_refptr<base::RefCountedMemory> image = | 182 scoped_refptr<base::RefCountedMemory> image = |
| 183 chromeos::options::UserImageSource::GetUserImage(account_id); | 183 chromeos::options::UserImageSource::GetUserImage(account_id); |
| 184 *icon_url = webui::GetPngDataUrl(image->front(), image->size()); | 184 *icon_url = webui::GetPngDataUrl(image->front(), image->size()); |
| 185 #else // !defined(OS_CHROMEOS) | 185 #else // !defined(OS_CHROMEOS) |
| 186 ProfileInfoCache& cache = | 186 ProfileAttributesEntry* entry; |
| 187 g_browser_process->profile_manager()->GetProfileInfoCache(); | 187 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 188 ProfileAttributesEntry* entry = nullptr; | 188 GetProfileAttributesWithPath(profile.GetPath(), &entry)) { |
| 189 if (cache.GetProfileAttributesWithPath(profile.GetPath(), &entry)) { | |
| 190 *name = base::UTF16ToUTF8(entry->GetName()); | 189 *name = base::UTF16ToUTF8(entry->GetName()); |
| 191 | 190 |
| 192 if (entry->IsUsingGAIAPicture() && entry->GetGAIAPicture()) { | 191 if (entry->IsUsingGAIAPicture() && entry->GetGAIAPicture()) { |
| 193 gfx::Image icon = | 192 gfx::Image icon = |
| 194 profiles::GetAvatarIconForWebUI(entry->GetAvatarIcon(), true); | 193 profiles::GetAvatarIconForWebUI(entry->GetAvatarIcon(), true); |
| 195 *icon_url = webui::GetBitmapDataUrl(icon.AsBitmap()); | 194 *icon_url = webui::GetBitmapDataUrl(icon.AsBitmap()); |
| 196 } else { | 195 } else { |
| 197 *icon_url = | 196 *icon_url = |
| 198 profiles::GetDefaultAvatarIconUrl(entry->GetAvatarIconIndex()); | 197 profiles::GetDefaultAvatarIconUrl(entry->GetAvatarIconIndex()); |
| 199 } | 198 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 214 profile_pref_registrar_.Add( | 213 profile_pref_registrar_.Add( |
| 215 prefs::kSigninAllowed, | 214 prefs::kSigninAllowed, |
| 216 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange, | 215 base::Bind(&PeopleHandler::OnSigninAllowedPrefChange, |
| 217 base::Unretained(this))); | 216 base::Unretained(this))); |
| 218 | 217 |
| 219 ProfileSyncService* sync_service( | 218 ProfileSyncService* sync_service( |
| 220 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); | 219 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); |
| 221 if (sync_service) | 220 if (sync_service) |
| 222 sync_service_observer_.Add(sync_service); | 221 sync_service_observer_.Add(sync_service); |
| 223 | 222 |
| 224 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 223 g_browser_process->profile_manager()-> |
| 224 GetProfileAttributesStorage().AddObserver(this); |
| 225 | 225 |
| 226 #if defined(OS_CHROMEOS) | 226 #if defined(OS_CHROMEOS) |
| 227 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 227 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
| 228 content::NotificationService::AllSources()); | 228 content::NotificationService::AllSources()); |
| 229 #endif | 229 #endif |
| 230 } | 230 } |
| 231 | 231 |
| 232 PeopleHandler::~PeopleHandler() { | 232 PeopleHandler::~PeopleHandler() { |
| 233 g_browser_process->profile_manager()-> | 233 g_browser_process->profile_manager()-> |
| 234 GetProfileInfoCache().RemoveObserver(this); | 234 GetProfileAttributesStorage().RemoveObserver(this); |
| 235 | 235 |
| 236 // Early exit if running unit tests (no actual WebUI is attached). | 236 // Early exit if running unit tests (no actual WebUI is attached). |
| 237 if (!web_ui()) | 237 if (!web_ui()) |
| 238 return; | 238 return; |
| 239 | 239 |
| 240 // This case is hit when the user performs a back navigation. | 240 // This case is hit when the user performs a back navigation. |
| 241 CloseSyncSetup(); | 241 CloseSyncSetup(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void PeopleHandler::ConfigureSyncDone() { | 244 void PeopleHandler::ConfigureSyncDone() { |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 void PeopleHandler::UpdateSyncState() { | 1018 void PeopleHandler::UpdateSyncState() { |
| 1019 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", | 1019 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", |
| 1020 *GetSyncStateDictionary()); | 1020 *GetSyncStateDictionary()); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 void PeopleHandler::OnSigninAllowedPrefChange() { | 1023 void PeopleHandler::OnSigninAllowedPrefChange() { |
| 1024 UpdateSyncState(); | 1024 UpdateSyncState(); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 } // namespace settings | 1027 } // namespace settings |
| OLD | NEW |