diff options
5 files changed, 36 insertions, 27 deletions
diff --git a/chrome/browser/chromeos/login/mock_user_manager.h b/chrome/browser/chromeos/login/mock_user_manager.h index 365a840..71db774 100644 --- a/chrome/browser/chromeos/login/mock_user_manager.h +++ b/chrome/browser/chromeos/login/mock_user_manager.h @@ -9,6 +9,7 @@ #include <string> #include "base/file_path.h" +#include "base/memory/weak_ptr.h" #include "chrome/browser/chromeos/login/user_image.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "testing/gmock/include/gmock/gmock.h" @@ -50,10 +51,11 @@ class MockUserManager : public UserManager { ash::WallpaperLayout)); MOCK_METHOD2(SaveUserImageFromFile, void(const std::string&, const FilePath&)); - MOCK_METHOD4(SaveUserWallpaperFromFile, void(const std::string&, - const FilePath&, - ash::WallpaperLayout, - WallpaperDelegate*)); + MOCK_METHOD4(SaveUserWallpaperFromFile, void( + const std::string&, + const FilePath&, + ash::WallpaperLayout, + base::WeakPtr<WallpaperDelegate>)); MOCK_METHOD1(SaveUserImageFromProfileImage, void(const std::string&)); MOCK_METHOD1(DownloadProfileImage, void(const std::string&)); MOCK_CONST_METHOD0(IsCurrentUserOwner, bool(void)); diff --git a/chrome/browser/chromeos/login/user_manager.h b/chrome/browser/chromeos/login/user_manager.h index f8be165..fe3f539 100644 --- a/chrome/browser/chromeos/login/user_manager.h +++ b/chrome/browser/chromeos/login/user_manager.h @@ -202,10 +202,11 @@ class UserManager { // Tries to load user image from disk; if successful, sets it for the user, // and updates Local State. - virtual void SaveUserWallpaperFromFile(const std::string& username, - const FilePath& path, - ash::WallpaperLayout layout, - WallpaperDelegate* delegate) = 0; + virtual void SaveUserWallpaperFromFile( + const std::string& username, + const FilePath& path, + ash::WallpaperLayout layout, + base::WeakPtr<WallpaperDelegate> delegate) = 0; // Sets profile image as user image for |username|, sends // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If the user diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc index 1a504b0..f135d69 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.cc +++ b/chrome/browser/chromeos/login/user_manager_impl.cc @@ -609,10 +609,11 @@ void UserManagerImpl::SaveUserImageFromFile(const std::string& username, base::Unretained(this), username)); } -void UserManagerImpl::SaveUserWallpaperFromFile(const std::string& username, - const FilePath& path, - ash::WallpaperLayout layout, - WallpaperDelegate* delegate) { +void UserManagerImpl::SaveUserWallpaperFromFile( + const std::string& username, + const FilePath& path, + ash::WallpaperLayout layout, + base::WeakPtr<WallpaperDelegate> delegate) { // For wallpapers, save the image without resizing. image_loader_->Start( path.value(), 0 /* Original size */, false, @@ -1165,11 +1166,12 @@ void UserManagerImpl::SaveUserImageInternal(const std::string& username, username, user_image, image_path, image_index)); } -void UserManagerImpl::SaveUserWallpaperInternal(const std::string& username, - ash::WallpaperLayout layout, - User::WallpaperType type, - WallpaperDelegate* delegate, - const UserImage& user_image) { +void UserManagerImpl::SaveUserWallpaperInternal( + const std::string& username, + ash::WallpaperLayout layout, + User::WallpaperType type, + base::WeakPtr<WallpaperDelegate> delegate, + const UserImage& user_image) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); const SkBitmap& wallpaper = user_image.image(); @@ -1224,7 +1226,8 @@ void UserManagerImpl::OnCustomWallpaperThumbnailLoaded( user->SetWallpaperThumbnail(wallpaper); } -void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { +void UserManagerImpl::OnThumbnailUpdated( + base::WeakPtr<WallpaperDelegate> delegate) { if (delegate) delegate->SetCustomWallpaperThumbnail(); } @@ -1232,7 +1235,7 @@ void UserManagerImpl::OnThumbnailUpdated(WallpaperDelegate* delegate) { void UserManagerImpl::GenerateUserWallpaperThumbnail( const std::string& username, User::WallpaperType type, - WallpaperDelegate* delegate, + base::WeakPtr<WallpaperDelegate> delegate, const SkBitmap& wallpaper) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); SkBitmap thumbnail = diff --git a/chrome/browser/chromeos/login/user_manager_impl.h b/chrome/browser/chromeos/login/user_manager_impl.h index 15c657f..0ac79ad 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.h +++ b/chrome/browser/chromeos/login/user_manager_impl.h @@ -12,6 +12,7 @@ #include "base/hash_tables.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" +#include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/synchronization/lock.h" #include "base/time.h" @@ -82,10 +83,11 @@ class UserManagerImpl : public UserManager, ash::WallpaperLayout layout) OVERRIDE; virtual void SaveUserImageFromFile(const std::string& username, const FilePath& path) OVERRIDE; - virtual void SaveUserWallpaperFromFile(const std::string& username, - const FilePath& path, - ash::WallpaperLayout layout, - WallpaperDelegate* delegate) OVERRIDE; + virtual void SaveUserWallpaperFromFile( + const std::string& username, + const FilePath& path, + ash::WallpaperLayout layout, + base::WeakPtr<WallpaperDelegate> delegate) OVERRIDE; virtual void SaveUserImageFromProfileImage( const std::string& username) OVERRIDE; virtual void DownloadProfileImage(const std::string& reason) OVERRIDE; @@ -200,7 +202,7 @@ class UserManagerImpl : public UserManager, void SaveUserWallpaperInternal(const std::string& username, ash::WallpaperLayout layout, User::WallpaperType type, - WallpaperDelegate* delegate, + base::WeakPtr<WallpaperDelegate> delegate, const UserImage& user_image); // Sets desktop background to custom wallpaper and loads wallpaper thumbnail @@ -214,12 +216,12 @@ class UserManagerImpl : public UserManager, const UserImage& user_image); // Updates the custom wallpaper thumbnail in wallpaper picker UI. - void OnThumbnailUpdated(WallpaperDelegate* delegate); + void OnThumbnailUpdated(base::WeakPtr<WallpaperDelegate> delegate); // Generates a 128x80 thumbnail and saves it to local file system. void GenerateUserWallpaperThumbnail(const std::string& username, User::WallpaperType type, - WallpaperDelegate* delegate, + base::WeakPtr<WallpaperDelegate> delegate, const SkBitmap& wallpaper); // Saves image to file with specified path and sends LOGIN_USER_IMAGE_CHANGED diff --git a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc index f023781..a70d784 100644 --- a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc +++ b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc @@ -102,7 +102,8 @@ void SetWallpaperOptionsHandler::FileSelected(const FilePath& path, // Default wallpaper layout is CENTER_CROPPED. user_manager->SaveUserWallpaperFromFile( - user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED, this); + user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED, + weak_factory_.GetWeakPtr()); web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile"); } |