| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profiles/gaia_info_update_service.h" | 5 #include "chrome/browser/profiles/gaia_info_update_service.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 13 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/profiles/profile_metrics.h" | 15 #include "chrome/browser/profiles/profile_metrics.h" |
| 15 #include "chrome/browser/profiles/profiles_state.h" | 16 #include "chrome/browser/profiles/profiles_state.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "components/signin/core/common/profile_management_switches.h" | 19 #include "components/signin/core/common/profile_management_switches.h" |
| 19 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 22 | 23 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 last_updated_.ToInternalValue()); | 106 last_updated_.ToInternalValue()); |
| 106 ScheduleNextUpdate(); | 107 ScheduleNextUpdate(); |
| 107 | 108 |
| 108 base::string16 full_name = downloader->GetProfileFullName(); | 109 base::string16 full_name = downloader->GetProfileFullName(); |
| 109 base::string16 given_name = downloader->GetProfileGivenName(); | 110 base::string16 given_name = downloader->GetProfileGivenName(); |
| 110 SkBitmap bitmap = downloader->GetProfilePicture(); | 111 SkBitmap bitmap = downloader->GetProfilePicture(); |
| 111 ProfileDownloader::PictureStatus picture_status = | 112 ProfileDownloader::PictureStatus picture_status = |
| 112 downloader->GetProfilePictureStatus(); | 113 downloader->GetProfilePictureStatus(); |
| 113 std::string picture_url = downloader->GetProfilePictureURL(); | 114 std::string picture_url = downloader->GetProfilePictureURL(); |
| 114 | 115 |
| 115 ProfileInfoCache& cache = | 116 ProfileAttributesStorage& storage = |
| 116 g_browser_process->profile_manager()->GetProfileInfoCache(); | 117 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 117 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 118 ProfileAttributesEntry* entry; |
| 118 if (profile_index == std::string::npos) | 119 if (!storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) |
| 119 return; | 120 return; |
| 120 | 121 |
| 121 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name); | 122 entry->SetGAIAName(full_name); |
| 122 // The profile index may have changed. | 123 entry->SetGAIAGivenName(given_name); |
| 123 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 124 DCHECK_NE(profile_index, std::string::npos); | |
| 125 | |
| 126 cache.SetGAIAGivenNameOfProfileAtIndex(profile_index, given_name); | |
| 127 // The profile index may have changed. | |
| 128 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 129 DCHECK_NE(profile_index, std::string::npos); | |
| 130 | 124 |
| 131 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { | 125 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { |
| 132 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, | 126 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, |
| 133 picture_url); | 127 picture_url); |
| 134 gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(bitmap); | 128 gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(bitmap); |
| 135 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); | 129 entry->SetGAIAPicture(&gfx_image); |
| 136 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { | 130 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { |
| 137 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); | 131 entry->SetGAIAPicture(NULL); |
| 138 } | 132 } |
| 139 | 133 |
| 140 const base::string16 hosted_domain = downloader->GetProfileHostedDomain(); | 134 const base::string16 hosted_domain = downloader->GetProfileHostedDomain(); |
| 141 profile_->GetPrefs()->SetString(prefs::kGoogleServicesHostedDomain, | 135 profile_->GetPrefs()->SetString(prefs::kGoogleServicesHostedDomain, |
| 142 (hosted_domain.empty() ? Profile::kNoHostedDomainFound : | 136 (hosted_domain.empty() ? Profile::kNoHostedDomainFound : |
| 143 base::UTF16ToUTF8(hosted_domain))); | 137 base::UTF16ToUTF8(hosted_domain))); |
| 144 } | 138 } |
| 145 | 139 |
| 146 void GAIAInfoUpdateService::OnProfileDownloadFailure( | 140 void GAIAInfoUpdateService::OnProfileDownloadFailure( |
| 147 ProfileDownloader* downloader, | 141 ProfileDownloader* downloader, |
| 148 ProfileDownloaderDelegate::FailureReason reason) { | 142 ProfileDownloaderDelegate::FailureReason reason) { |
| 149 profile_image_downloader_.reset(); | 143 profile_image_downloader_.reset(); |
| 150 | 144 |
| 151 // Save the last updated time. | 145 // Save the last updated time. |
| 152 last_updated_ = base::Time::Now(); | 146 last_updated_ = base::Time::Now(); |
| 153 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, | 147 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, |
| 154 last_updated_.ToInternalValue()); | 148 last_updated_.ToInternalValue()); |
| 155 ScheduleNextUpdate(); | 149 ScheduleNextUpdate(); |
| 156 } | 150 } |
| 157 | 151 |
| 158 void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) { | 152 void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) { |
| 159 ProfileInfoCache& cache = | 153 ProfileAttributesStorage& storage = |
| 160 g_browser_process->profile_manager()->GetProfileInfoCache(); | 154 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 161 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 155 ProfileAttributesEntry* entry; |
| 162 if (profile_index == std::string::npos) | 156 if (!storage.GetProfileAttributesWithPath(profile_->GetPath(), &entry)) |
| 163 return; | 157 return; |
| 164 | 158 |
| 165 if (username.empty()) { | 159 if (username.empty()) { |
| 166 // Unset the old user's GAIA info. | 160 // Unset the old user's GAIA info. |
| 167 cache.SetGAIANameOfProfileAtIndex(profile_index, base::string16()); | 161 entry->SetGAIAName(base::string16()); |
| 168 cache.SetGAIAGivenNameOfProfileAtIndex(profile_index, base::string16()); | 162 entry->SetGAIAGivenName(base::string16()); |
| 169 // The profile index may have changed. | 163 entry->SetGAIAPicture(NULL); |
| 170 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 171 if (profile_index == std::string::npos) | |
| 172 return; | |
| 173 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); | |
| 174 // Unset the cached URL. | 164 // Unset the cached URL. |
| 175 profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL); | 165 profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL); |
| 176 } else { | 166 } else { |
| 177 // Update the new user's GAIA info. | 167 // Update the new user's GAIA info. |
| 178 Update(); | 168 Update(); |
| 179 } | 169 } |
| 180 } | 170 } |
| 181 | 171 |
| 182 void GAIAInfoUpdateService::Shutdown() { | 172 void GAIAInfoUpdateService::Shutdown() { |
| 183 timer_.Stop(); | 173 timer_.Stop(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 213 const std::string& account_id, | 203 const std::string& account_id, |
| 214 const std::string& username, | 204 const std::string& username, |
| 215 const std::string& password) { | 205 const std::string& password) { |
| 216 OnUsernameChanged(username); | 206 OnUsernameChanged(username); |
| 217 } | 207 } |
| 218 | 208 |
| 219 void GAIAInfoUpdateService::GoogleSignedOut(const std::string& account_id, | 209 void GAIAInfoUpdateService::GoogleSignedOut(const std::string& account_id, |
| 220 const std::string& username) { | 210 const std::string& username) { |
| 221 OnUsernameChanged(std::string()); | 211 OnUsernameChanged(std::string()); |
| 222 } | 212 } |
| OLD | NEW |