Commit 46a6ece8 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros: Use profile image as avatar for new users on the device

It's used only  when sync does not provide image details.
I could not create a browser test for this.

Fixed: 1081249
Test: manual
Change-Id: I81ba0db7ae2ba79faa0e92318bc9138f7c1c7aeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419013Reviewed-by: default avatarRoman Aleksandrov <raleksandrov@google.com>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808822}
parent 78ae0493
...@@ -545,21 +545,25 @@ void UserImageManagerImpl::LoadUserImage() { ...@@ -545,21 +545,25 @@ void UserImageManagerImpl::LoadUserImage() {
} }
void UserImageManagerImpl::UserLoggedIn(bool user_is_new, bool user_is_local) { void UserImageManagerImpl::UserLoggedIn(bool user_is_new, bool user_is_local) {
// Reset the downloaded profile image as a new user logged in.
downloaded_profile_image_ = gfx::ImageSkia();
profile_image_url_ = GURL();
profile_image_requested_ = false;
is_random_image_set_ = false;
const user_manager::User* user = GetUser(); const user_manager::User* user = GetUser();
if (user_is_new) { if (user_is_new) {
if (!user_is_local) if (!user_is_local) {
SetInitialUserImage(); SetInitialUserImage();
is_random_image_set_ = true;
DownloadProfileImage();
}
} else { } else {
UMA_HISTOGRAM_EXACT_LINEAR("UserImage.LoggedIn", UMA_HISTOGRAM_EXACT_LINEAR("UserImage.LoggedIn",
ImageIndexToHistogramIndex(user->image_index()), ImageIndexToHistogramIndex(user->image_index()),
default_user_image::kHistogramImagesCount); default_user_image::kHistogramImagesCount);
} }
// Reset the downloaded profile image as a new user logged in.
downloaded_profile_image_ = gfx::ImageSkia();
profile_image_url_ = GURL();
profile_image_requested_ = false;
user_image_sync_observer_.reset(); user_image_sync_observer_.reset();
TryToCreateImageSyncObserver(); TryToCreateImageSyncObserver();
} }
...@@ -589,6 +593,7 @@ void UserImageManagerImpl::UserProfileCreated() { ...@@ -589,6 +593,7 @@ void UserImageManagerImpl::UserProfileCreated() {
} }
void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) {
is_random_image_set_ = false;
if (IsUserImageManaged()) if (IsUserImageManaged())
return; return;
job_.reset(new Job(this)); job_.reset(new Job(this));
...@@ -762,7 +767,9 @@ void UserImageManagerImpl::OnProfileDownloadSuccess( ...@@ -762,7 +767,9 @@ void UserImageManagerImpl::OnProfileDownloadSuccess(
gfx::ImageSkia::CreateFrom1xBitmap(downloader->GetProfilePicture()); gfx::ImageSkia::CreateFrom1xBitmap(downloader->GetProfilePicture());
profile_image_url_ = GURL(downloader->GetProfilePictureURL()); profile_image_url_ = GURL(downloader->GetProfilePictureURL());
if (user->image_index() == user_manager::User::USER_IMAGE_PROFILE) { if (user->image_index() == user_manager::User::USER_IMAGE_PROFILE ||
is_random_image_set_) {
is_random_image_set_ = false;
VLOG(1) << "Updating profile image for logged-in user."; VLOG(1) << "Updating profile image for logged-in user.";
// This will persist |downloaded_profile_image_| to disk. // This will persist |downloaded_profile_image_| to disk.
SaveUserImageFromProfileImage(); SaveUserImageFromProfileImage();
......
...@@ -203,6 +203,10 @@ class UserImageManagerImpl : public UserImageManager, ...@@ -203,6 +203,10 @@ class UserImageManagerImpl : public UserImageManager,
bool has_managed_image_; bool has_managed_image_;
// If true user image manager trying to download and set profile image instead
// of the random one.
bool is_random_image_set_ = false;
base::WeakPtrFactory<UserImageManagerImpl> weak_factory_{this}; base::WeakPtrFactory<UserImageManagerImpl> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(UserImageManagerImpl); DISALLOW_COPY_AND_ASSIGN(UserImageManagerImpl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment