Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9039)

Unified Diff: chrome/browser/chromeos/login/user_manager.cc

Issue 8510069: Make ProfileImageDownloader available to non-chromeos code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/user_manager.cc
diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc
index d4d598feb833b5e7c31af76bed6f132f9ac50d15..21ed6b8c46be7143a38d32e22d0bdaa8ae7bfcf5 100644
--- a/chrome/browser/chromeos/login/user_manager.cc
+++ b/chrome/browser/chromeos/login/user_manager.cc
@@ -36,6 +36,8 @@
#include "chrome/browser/defaults.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/profiles/profile_downloader.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
@@ -85,6 +87,17 @@ const long kProfileImageDownloadDelayMs = 10000;
base::LazyInstance<UserManager> g_user_manager = LAZY_INSTANCE_INITIALIZER;
+// Enum for reporting histograms about profile picture download.
+enum ProfileDownloadResult {
+ kDownloadSuccessChanged,
+ kDownloadSuccess,
+ kDownloadFailure,
+ kDownloadDefault,
+
+ // Must be the last, convenient count.
+ kDownloadResultsCount
+};
+
// Used to handle the asynchronous response of deleting a cryptohome directory.
class RemoveAttempt : public CryptohomeLibrary::Delegate {
public:
@@ -457,7 +470,13 @@ void UserManager::DownloadProfileImage() {
// Another download is already in progress
return;
}
- profile_image_downloader_.reset(new ProfileImageDownloader(this));
+
+ if (logged_in_user().email().empty()) {
+ // This is a guest login so there's profile image to download.
Ivan Korotkov 2011/11/17 08:37:12 ... there's no...
sail 2011/11/21 22:01:00 Done.
+ return;
+ }
+
+ profile_image_downloader_.reset(new ProfileDownloader(this));
profile_image_downloader_->Start();
profile_image_load_start_time_ = base::Time::Now();
}
@@ -793,65 +812,60 @@ void UserManager::CheckOwnership() {
is_owner));
}
-void UserManager::OnDownloadSuccess(const SkBitmap& image) {
- VLOG(1) << "Downloaded profile image for logged-in user.";
- UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
- ProfileImageDownloader::kDownloadSuccess,
- ProfileImageDownloader::kDownloadResultsCount);
-
- // Check if this image is not the same as already downloaded.
- std::string new_image_data_url = web_ui_util::GetImageDataUrl(image);
- if (!downloaded_profile_image_data_url_.empty() &&
- new_image_data_url == downloaded_profile_image_data_url_)
- return;
+int UserManager::GetDesiredImageSize() {
+ return login::kUserImageSize;
+}
- downloaded_profile_image_data_url_ = new_image_data_url;
- downloaded_profile_image_ = image;
+Profile* UserManager::GetBrowserProfile() {
+ return ProfileManager::GetDefaultProfile();
+}
- if (logged_in_user().image_index() == User::kProfileImageIndex) {
- std::string current_image_data_url =
- web_ui_util::GetImageDataUrl(logged_in_user().image());
- if (current_image_data_url == new_image_data_url)
+void UserManager::OnDownloadComplete(ProfileDownloader* downloader,
+ bool success) {
+ ProfileDownloadResult result;
+ if (!success)
+ result = kDownloadFailure;
+ else if (downloader->GetProfilePicture().isNull())
+ result = kDownloadDefault;
+ else
+ result = kDownloadSuccess;
+ UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
Ivan Korotkov 2011/11/17 08:37:12 Can you please rename this to "UserImage.ProfileDo
sail 2011/11/21 22:01:00 Done.
+ result, kDownloadResultsCount);
+
+ if (result == kDownloadSuccess) {
+ // Check if this image is not the same as already downloaded.
+ std::string new_image_data_url =
+ web_ui_util::GetImageDataUrl(downloader->GetProfilePicture());
+ if (!downloaded_profile_image_data_url_.empty() &&
+ new_image_data_url == downloaded_profile_image_data_url_)
return;
- VLOG(1) << "Updating profile image for logged-in user";
- UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
- ProfileImageDownloader::kDownloadSuccessChanged,
- ProfileImageDownloader::kDownloadResultsCount);
+ downloaded_profile_image_data_url_ = new_image_data_url;
+ downloaded_profile_image_ = downloader->GetProfilePicture();
- // This will persist |downloaded_profile_image_| to file.
- SaveUserImageFromProfileImage(logged_in_user().email());
- }
+ if (logged_in_user().image_index() == User::kProfileImageIndex) {
+ std::string current_image_data_url =
+ web_ui_util::GetImageDataUrl(logged_in_user().image());
+ if (current_image_data_url == new_image_data_url)
+ return;
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
- content::Source<UserManager>(this),
- content::Details<const SkBitmap>(&image));
+ VLOG(1) << "Updating profile image for logged-in user";
+ UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
+ kDownloadSuccessChanged,
+ kDownloadResultsCount);
- profile_image_downloader_.reset();
-}
+ // This will persist |downloaded_profile_image_| to file.
+ SaveUserImageFromProfileImage(logged_in_user().email());
+ }
+ }
-void UserManager::OnDownloadFailure() {
- VLOG(1) << "Download of profile image for logged-in user failed.";
- UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
- ProfileImageDownloader::kDownloadFailure,
- ProfileImageDownloader::kDownloadResultsCount);
+ chrome::NotificationType type = result == kDownloadSuccess ?
+ chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED :
+ chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED;
content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
- content::Source<UserManager>(this),
+ type, content::Source<UserManager>(this),
content::NotificationService::NoDetails());
Ivan Korotkov 2011/11/17 08:37:12 For NOTIFICATION_PROFILE_IMAGE_UPDATED, details sh
sail 2011/11/21 22:01:00 Done.
- profile_image_downloader_.reset();
-}
-void UserManager::OnDownloadDefaultImage() {
- VLOG(1) << "Logged-in user still has the default profile image.";
- UMA_HISTOGRAM_ENUMERATION("UserImageDownloadResult.LoggedIn",
- ProfileImageDownloader::kDownloadDefault,
- ProfileImageDownloader::kDownloadResultsCount);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
- content::Source<UserManager>(this),
- content::NotificationService::NoDetails());
profile_image_downloader_.reset();
}

Powered by Google App Engine
This is Rietveld 408576698