| 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/chromeos/login/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 void UserManagerImpl::AddObserver(Observer* obs) { | 677 void UserManagerImpl::AddObserver(Observer* obs) { |
| 678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 679 observer_list_.AddObserver(obs); | 679 observer_list_.AddObserver(obs); |
| 680 } | 680 } |
| 681 | 681 |
| 682 void UserManagerImpl::RemoveObserver(Observer* obs) { | 682 void UserManagerImpl::RemoveObserver(Observer* obs) { |
| 683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 684 observer_list_.RemoveObserver(obs); | 684 observer_list_.RemoveObserver(obs); |
| 685 } | 685 } |
| 686 | 686 |
| 687 const SkBitmap& UserManagerImpl::DownloadedProfileImage() const { | 687 const gfx::ImageSkia& UserManagerImpl::DownloadedProfileImage() const { |
| 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 689 return downloaded_profile_image_; | 689 return downloaded_profile_image_; |
| 690 } | 690 } |
| 691 | 691 |
| 692 void UserManagerImpl::NotifyLocalStateChanged() { | 692 void UserManagerImpl::NotifyLocalStateChanged() { |
| 693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 694 FOR_EACH_OBSERVER( | 694 FOR_EACH_OBSERVER( |
| 695 Observer, | 695 Observer, |
| 696 observer_list_, | 696 observer_list_, |
| 697 LocalStateChanged(this)); | 697 LocalStateChanged(this)); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 return true; | 1103 return true; |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 void UserManagerImpl::InitDownloadedProfileImage() { | 1106 void UserManagerImpl::InitDownloadedProfileImage() { |
| 1107 DCHECK(logged_in_user_); | 1107 DCHECK(logged_in_user_); |
| 1108 DCHECK_EQ(logged_in_user_->image_index(), User::kProfileImageIndex); | 1108 DCHECK_EQ(logged_in_user_->image_index(), User::kProfileImageIndex); |
| 1109 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { | 1109 if (downloaded_profile_image_.empty() && !logged_in_user_->image_is_stub()) { |
| 1110 VLOG(1) << "Profile image initialized"; | 1110 VLOG(1) << "Profile image initialized"; |
| 1111 downloaded_profile_image_ = logged_in_user_->image(); | 1111 downloaded_profile_image_ = logged_in_user_->image(); |
| 1112 downloaded_profile_image_data_url_ = | 1112 downloaded_profile_image_data_url_ = |
| 1113 web_ui_util::GetImageDataUrl(gfx::ImageSkia(downloaded_profile_image_)); | 1113 web_ui_util::GetImageDataUrl(downloaded_profile_image_); |
| 1114 profile_image_url_ = logged_in_user_->image_url(); | 1114 profile_image_url_ = logged_in_user_->image_url(); |
| 1115 } | 1115 } |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 void UserManagerImpl::DownloadProfileData(const std::string& reason, | 1118 void UserManagerImpl::DownloadProfileData(const std::string& reason, |
| 1119 bool download_image) { | 1119 bool download_image) { |
| 1120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1121 | 1121 |
| 1122 // For guest login there's no profile image to download. | 1122 // For guest login there's no profile image to download. |
| 1123 if (IsLoggedInAsGuest()) | 1123 if (IsLoggedInAsGuest()) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 return; | 1248 return; |
| 1249 | 1249 |
| 1250 // Check if this image is not the same as already downloaded. | 1250 // Check if this image is not the same as already downloaded. |
| 1251 gfx::ImageSkia new_image(downloader->GetProfilePicture()); | 1251 gfx::ImageSkia new_image(downloader->GetProfilePicture()); |
| 1252 std::string new_image_data_url = web_ui_util::GetImageDataUrl(new_image); | 1252 std::string new_image_data_url = web_ui_util::GetImageDataUrl(new_image); |
| 1253 if (!downloaded_profile_image_data_url_.empty() && | 1253 if (!downloaded_profile_image_data_url_.empty() && |
| 1254 new_image_data_url == downloaded_profile_image_data_url_) | 1254 new_image_data_url == downloaded_profile_image_data_url_) |
| 1255 return; | 1255 return; |
| 1256 | 1256 |
| 1257 downloaded_profile_image_data_url_ = new_image_data_url; | 1257 downloaded_profile_image_data_url_ = new_image_data_url; |
| 1258 downloaded_profile_image_ = downloader->GetProfilePicture(); | 1258 downloaded_profile_image_ = gfx::ImageSkia(downloader->GetProfilePicture()); |
| 1259 profile_image_url_ = GURL(downloader->GetProfilePictureURL()); | 1259 profile_image_url_ = GURL(downloader->GetProfilePictureURL()); |
| 1260 | 1260 |
| 1261 if (GetLoggedInUser().image_index() == User::kProfileImageIndex) { | 1261 if (GetLoggedInUser().image_index() == User::kProfileImageIndex) { |
| 1262 VLOG(1) << "Updating profile image for logged-in user"; | 1262 VLOG(1) << "Updating profile image for logged-in user"; |
| 1263 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", | 1263 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", |
| 1264 kDownloadSuccessChanged, | 1264 kDownloadSuccessChanged, |
| 1265 kDownloadResultsCount); | 1265 kDownloadResultsCount); |
| 1266 // This will persist |downloaded_profile_image_| to file. | 1266 // This will persist |downloaded_profile_image_| to file. |
| 1267 SaveUserImageFromProfileImage(GetLoggedInUser().email()); | 1267 SaveUserImageFromProfileImage(GetLoggedInUser().email()); |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 // TODO(ivankr): temporary measure until UserManager is fully migrated | |
| 1271 // to use ImageSkia instead of SkBitmap. | |
| 1272 gfx::ImageSkia profile_image(downloaded_profile_image_); | |
| 1273 content::NotificationService::current()->Notify( | 1270 content::NotificationService::current()->Notify( |
| 1274 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | 1271 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, |
| 1275 content::Source<UserManagerImpl>(this), | 1272 content::Source<UserManagerImpl>(this), |
| 1276 content::Details<const gfx::ImageSkia>(&profile_image)); | 1273 content::Details<const gfx::ImageSkia>(&downloaded_profile_image_)); |
| 1277 } | 1274 } |
| 1278 | 1275 |
| 1279 void UserManagerImpl::OnProfileDownloadFailure(ProfileDownloader* downloader) { | 1276 void UserManagerImpl::OnProfileDownloadFailure(ProfileDownloader* downloader) { |
| 1280 DCHECK_EQ(downloader, profile_image_downloader_.get()); | 1277 DCHECK_EQ(downloader, profile_image_downloader_.get()); |
| 1281 profile_image_downloader_.reset(); | 1278 profile_image_downloader_.reset(); |
| 1282 | 1279 |
| 1283 downloading_profile_image_ = false; | 1280 downloading_profile_image_ = false; |
| 1284 | 1281 |
| 1285 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", | 1282 UMA_HISTOGRAM_ENUMERATION("UserImage.ProfileDownloadResult", |
| 1286 kDownloadFailure, kDownloadResultsCount); | 1283 kDownloadFailure, kDownloadResultsCount); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 BrowserThread::PostTask( | 1368 BrowserThread::PostTask( |
| 1372 BrowserThread::FILE, | 1369 BrowserThread::FILE, |
| 1373 FROM_HERE, | 1370 FROM_HERE, |
| 1374 base::Bind(&UserManagerImpl::DeleteUserImage, | 1371 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1375 base::Unretained(this), | 1372 base::Unretained(this), |
| 1376 image_path)); | 1373 image_path)); |
| 1377 } | 1374 } |
| 1378 } | 1375 } |
| 1379 | 1376 |
| 1380 } // namespace chromeos | 1377 } // namespace chromeos |
| OLD | NEW |