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

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

Issue 10667034: [cros] Cache the URL of user's G+ profile photo to prevent redundant downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/user_manager_impl.cc
diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc
index 02ccdfc75eab7f64485893de5708216e521d600c..006b3edc6229b1c7af4251dbc5e86414047432ce 100644
--- a/chrome/browser/chromeos/login/user_manager_impl.cc
+++ b/chrome/browser/chromeos/login/user_manager_impl.cc
@@ -74,6 +74,7 @@ const char kStubUser[] = "stub-user@example.com";
// Names of nodes with info about user image.
const char kImagePathNodeName[] = "path";
const char kImageIndexNodeName[] = "index";
+const char kImageURLNodeName[] = "url";
const char kWallpaperTypeNodeName[] = "type";
const char kWallpaperIndexNodeName[] = "index";
@@ -590,14 +591,16 @@ std::string UserManagerImpl::GetUserDisplayEmail(
void UserManagerImpl::SaveUserDefaultImageIndex(const std::string& username,
int image_index) {
DCHECK(image_index >= 0 && image_index < kDefaultImagesCount);
- SetUserImage(username, image_index, UserImage(GetDefaultImage(image_index)));
- SaveImageToLocalState(username, "", image_index, false);
+ SetUserImage(username, image_index, GURL(),
+ UserImage(GetDefaultImage(image_index)));
+ SaveImageToLocalState(username, "", image_index, GURL(), false);
}
void UserManagerImpl::SaveUserImage(const std::string& username,
const UserImage& user_image) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- SaveUserImageInternal(username, User::kExternalImageIndex, user_image);
+ SaveUserImageInternal(username, User::kExternalImageIndex,
+ GURL(), user_image);
}
void UserManagerImpl::SetLoggedInUserCustomWallpaperLayout(
@@ -646,12 +649,16 @@ void UserManagerImpl::SaveUserImageFromProfileImage(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!downloaded_profile_image_.empty()) {
// Profile image has already been downloaded, so save it to file right now.
- SaveUserImageInternal(username, User::kProfileImageIndex,
+ DCHECK(profile_image_url_.is_valid());
+ SaveUserImageInternal(username,
+ User::kProfileImageIndex, profile_image_url_,
UserImage(downloaded_profile_image_));
} else {
// No profile image - use the stub image (gray avatar).
- SetUserImage(username, User::kProfileImageIndex, UserImage(SkBitmap()));
- SaveImageToLocalState(username, "", User::kProfileImageIndex, false);
+ SetUserImage(username, User::kProfileImageIndex,
+ GURL(), UserImage(SkBitmap()));
+ SaveImageToLocalState(username, "", User::kProfileImageIndex,
+ GURL(), false);
}
}
@@ -852,7 +859,8 @@ void UserManagerImpl::EnsureUsersLoaded() {
image_loader_->Start(
image_path, user_image_size, true,
base::Bind(&UserManagerImpl::SetUserImage,
- base::Unretained(this), email, image_index));
+ base::Unretained(this),
+ email, image_index, GURL()));
}
} else if (prefs_images->GetDictionaryWithoutPathExpansion(
email, &image_properties)) {
@@ -870,14 +878,19 @@ void UserManagerImpl::EnsureUsersLoaded() {
// after user logs in).
DCHECK(!image_path.empty() ||
image_index == User::kProfileImageIndex);
+ std::string image_url;
+ image_properties->GetString(kImageURLNodeName, &image_url);
+ GURL image_gurl(image_url);
// Until image has been loaded, use the stub image (gray avatar).
user->SetStubImage(image_index);
+ user->SetImageURL(image_gurl);
if (!image_path.empty()) {
// Load user image asynchronously.
image_loader_->Start(
image_path, user_image_size, true,
base::Bind(&UserManagerImpl::SetUserImage,
- base::Unretained(this), email, image_index));
+ base::Unretained(this),
+ email, image_index, image_gurl));
}
} else {
NOTREACHED();
@@ -1099,6 +1112,7 @@ void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
void UserManagerImpl::SetUserImage(const std::string& username,
int image_index,
+ const GURL& image_url,
const UserImage& user_image) {
User* user = const_cast<User*>(FindUser(username));
// User may have been removed by now.
@@ -1112,6 +1126,7 @@ void UserManagerImpl::SetUserImage(const std::string& username,
user->SetImage(user_image, image_index);
else
user->SetStubImage(image_index);
+ user->SetImageURL(image_url);
// For the logged-in user with a profile picture, initialize
// |downloaded_profile_picture_|.
if (user == logged_in_user_ && image_index == User::kProfileImageIndex)
@@ -1180,10 +1195,11 @@ void UserManagerImpl::SaveUserWallpaperProperties(const std::string& username,
void UserManagerImpl::SaveUserImageInternal(const std::string& username,
int image_index,
+ const GURL& image_url,
const UserImage& user_image) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- SetUserImage(username, image_index, user_image);
+ SetUserImage(username, image_index, image_url, user_image);
// Ignore for ephemeral users.
if (IsEphemeralUser(username))
@@ -1199,7 +1215,7 @@ void UserManagerImpl::SaveUserImageInternal(const std::string& username,
FROM_HERE,
base::Bind(&UserManagerImpl::SaveImageToFile,
base::Unretained(this),
- username, user_image, image_path, image_index));
+ username, user_image, image_path, image_index, image_url));
}
void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username,
@@ -1296,7 +1312,8 @@ void UserManagerImpl::GenerateUserWallpaperThumbnail(
void UserManagerImpl::SaveImageToFile(const std::string& username,
const UserImage& user_image,
const FilePath& image_path,
- int image_index) {
+ int image_index,
+ const GURL& image_url) {
if (!SaveBitmapToFile(user_image, image_path))
return;
@@ -1305,7 +1322,7 @@ void UserManagerImpl::SaveImageToFile(const std::string& username,
FROM_HERE,
base::Bind(&UserManagerImpl::SaveImageToLocalState,
base::Unretained(this),
- username, image_path.value(), image_index, true));
+ username, image_path.value(), image_index, image_url, true));
}
void UserManagerImpl::SaveWallpaperToFile(const std::string& username,
@@ -1329,6 +1346,7 @@ void UserManagerImpl::SaveWallpaperToFile(const std::string& username,
void UserManagerImpl::SaveImageToLocalState(const std::string& username,
const std::string& image_path,
int image_index,
+ const GURL& image_url,
bool is_async) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -1353,6 +1371,12 @@ void UserManagerImpl::SaveImageToLocalState(const std::string& username,
image_properties->Set(kImagePathNodeName, new StringValue(image_path));
image_properties->Set(kImageIndexNodeName,
new base::FundamentalValue(image_index));
+ if (!image_url.is_empty()) {
+ image_properties->Set(kImageURLNodeName,
+ new StringValue(image_url.spec()));
+ } else {
+ image_properties->Remove(kImageURLNodeName, NULL);
+ }
images_update->SetWithoutPathExpansion(username, image_properties);
DVLOG(1) << "Saving path to user image in Local State.";
@@ -1398,6 +1422,7 @@ void UserManagerImpl::InitDownloadedProfileImage() {
downloaded_profile_image_ = logged_in_user_->image();
downloaded_profile_image_data_url_ =
web_ui_util::GetImageDataUrl(gfx::ImageSkia(downloaded_profile_image_));
+ profile_image_url_ = logged_in_user_->image_url();
}
}
@@ -1439,17 +1464,18 @@ void UserManagerImpl::CheckOwnership() {
is_owner));
}
+// ProfileDownloaderDelegate override.
int UserManagerImpl::GetDesiredImageSideLength() const {
return GetCurrentUserImageSize();
}
-Profile* UserManagerImpl::GetBrowserProfile() {
- return ProfileManager::GetDefaultProfile();
+// ProfileDownloaderDelegate override.
+std::string UserManagerImpl::GetCachedPictureURL() const {
+ return profile_image_url_.spec();
}
-std::string UserManagerImpl::GetCachedPictureURL() const {
- // Currently the profile picture URL is not cached on ChromeOS.
- return std::string();
+Profile* UserManagerImpl::GetBrowserProfile() {
+ return ProfileManager::GetDefaultProfile();
}
void UserManagerImpl::OnDownloadComplete(ProfileDownloader* downloader,
@@ -1495,6 +1521,7 @@ void UserManagerImpl::OnDownloadComplete(ProfileDownloader* downloader,
downloaded_profile_image_data_url_ = new_image_data_url;
downloaded_profile_image_ = downloader->GetProfilePicture();
+ profile_image_url_ = GURL(downloader->GetProfilePictureURL());
if (GetLoggedInUser().image_index() == User::kProfileImageIndex) {
VLOG(1) << "Updating profile image for logged-in user";
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698