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

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
« no previous file with comments | « chrome/browser/chromeos/login/user_manager.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6b90367d1ccf204160572a8f8269c228690049a5..b64c68b6df5c8e064f715c5b9948f20d6e7f721f 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:
@@ -454,7 +467,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 no profile image to download.
+ return;
+ }
+
+ profile_image_downloader_.reset(new ProfileDownloader(this));
profile_image_downloader_->Start();
profile_image_load_start_time_ = base::Time::Now();
}
@@ -789,65 +808,65 @@ 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);
+int UserManager::GetDesiredImageSideLength() {
+ return login::kUserImageSize;
+}
- // 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;
+Profile* UserManager::GetBrowserProfile() {
+ return ProfileManager::GetDefaultProfile();
+}
- downloaded_profile_image_data_url_ = new_image_data_url;
- downloaded_profile_image_ = image;
+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("UserImage.ProfileDownloadResult",
+ result, kDownloadResultsCount);
- 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)
+ 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("UserImage.ProfileDownloadResult",
+ 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);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
- content::Source<UserManager>(this),
- content::NotificationService::NoDetails());
- profile_image_downloader_.reset();
-}
+ if (result == kDownloadSuccess) {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
+ content::Source<UserManager>(this),
+ content::Details<const SkBitmap>(&downloader->GetProfilePicture()));
+ } else {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
+ content::Source<UserManager>(this),
+ content::NotificationService::NoDetails());
+ }
-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();
}
« no previous file with comments | « chrome/browser/chromeos/login/user_manager.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698