Skip to content

Commit

Permalink
Some cleanup of WallpaperManager.
Browse files Browse the repository at this point in the history
* Add const, static and/or private in some places.
* Integrate ProcessCustomWallpaper() into SetCustomWallpaper() to avoid PostTask() and deep copy of wallpaper in case it is not persistent.
* Replace UserImage by gfx::ImageSkia in some places to simplify code and to avoid useless temporary objects.
* Remove unused DAILY User::WallpaperType.
* Remove unused GetOriginalWallpaperPathForUser().
* Replace SetLastSelectedUser() by direct member access.
* Add initialization of WallpaperInfo.date that was missing in one case.
* Rename all ImageSkia method parameters to "image" and all UserImage method parameters to "user_image" for consistency.
* Rename ResizeWallpaper() to ResizeImage().
* Improve some comments.

BUG=none

Review URL: https://codereview.chromium.org/221873005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266026 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tnagel@chromium.org committed Apr 24, 2014
1 parent c6afb98 commit 7a654c5
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 309 deletions.
25 changes: 11 additions & 14 deletions chrome/browser/chromeos/extensions/wallpaper_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,9 @@ bool WallpaperSetWallpaperFunction::RunImpl() {
}

void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
const gfx::ImageSkia& wallpaper) {
const gfx::ImageSkia& image) {
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();
chromeos::UserImage::RawImage raw_image(
params_->details.wallpaper_data->begin(),
params_->details.wallpaper_data->end());
chromeos::UserImage image(wallpaper, raw_image);
base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath(
chromeos::kThumbnailWallpaperSubDir,
user_id_hash_,
Expand All @@ -151,14 +147,16 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
unsafe_wallpaper_decoder_ = NULL;

if (params_->details.thumbnail) {
wallpaper.EnsureRepsForSupportedScales();
scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
image.EnsureRepsForSupportedScales();
scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy());
// Generates thumbnail before call api function callback. We can then
// request thumbnail in the javascript callback.
task_runner->PostTask(FROM_HERE,
base::Bind(
&WallpaperSetWallpaperFunction::GenerateThumbnail,
this, thumbnail_path, base::Passed(&deep_copy)));
task_runner->PostTask(
FROM_HERE,
base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail,
this,
thumbnail_path,
base::Passed(deep_copy.Pass())));
} else {
SendResponse(true);
}
Expand All @@ -168,13 +166,12 @@ void WallpaperSetWallpaperFunction::GenerateThumbnail(
const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) {
DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
sequence_token_));
chromeos::UserImage wallpaper(*image.get());
if (!base::PathExists(thumbnail_path.DirName()))
base::CreateDirectory(thumbnail_path.DirName());

scoped_refptr<base::RefCountedBytes> data;
chromeos::WallpaperManager::Get()->ResizeWallpaper(
wallpaper,
chromeos::WallpaperManager::Get()->ResizeImage(
*image,
ash::WALLPAPER_LAYOUT_STRETCH,
chromeos::kWallpaperThumbnailWidth,
chromeos::kWallpaperThumbnailHeight,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/extensions/wallpaper_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WallpaperSetWallpaperFunction : public WallpaperFunctionBase {
virtual bool RunImpl() OVERRIDE;

private:
virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE;

// Generates thumbnail of custom wallpaper. A simple STRETCH is used for
// generating thumbnail.
Expand Down
35 changes: 16 additions & 19 deletions chrome/browser/chromeos/extensions/wallpaper_private_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void WallpaperPrivateSetWallpaperIfExistsFunction::
}

void WallpaperPrivateSetWallpaperIfExistsFunction::OnWallpaperDecoded(
const gfx::ImageSkia& wallpaper) {
const gfx::ImageSkia& image) {
// Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
unsafe_wallpaper_decoder_ = NULL;

Expand All @@ -362,7 +362,7 @@ void WallpaperPrivateSetWallpaperIfExistsFunction::OnWallpaperDecoded(
bool update_wallpaper =
user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email();
wallpaper_manager->SetWallpaperFromImageSkia(
user_id_, wallpaper, layout, update_wallpaper);
user_id_, image, layout, update_wallpaper);
bool is_persistent =
!chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral();
chromeos::WallpaperInfo info = {
Expand Down Expand Up @@ -401,8 +401,8 @@ bool WallpaperPrivateSetWallpaperFunction::RunImpl() {
}

void WallpaperPrivateSetWallpaperFunction::OnWallpaperDecoded(
const gfx::ImageSkia& wallpaper) {
wallpaper_ = wallpaper;
const gfx::ImageSkia& image) {
wallpaper_ = image;
// Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
unsafe_wallpaper_decoder_ = NULL;

Expand All @@ -427,10 +427,11 @@ void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
// ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if
// post to another thread.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
BrowserThread::UI,
FROM_HERE,
base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper,
this, base::Passed(&deep_copy)));
chromeos::UserImage wallpaper(wallpaper_);
this,
base::Passed(deep_copy.Pass())));

base::FilePath wallpaper_dir;
CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
Expand All @@ -441,7 +442,7 @@ void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
// Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to
// maintain the aspect ratio after resize.
chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
wallpaper,
wallpaper_,
file_path,
ash::WALLPAPER_LAYOUT_CENTER_CROPPED,
chromeos::kSmallWallpaperMaxWidth,
Expand All @@ -458,7 +459,7 @@ void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
}

void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper(
scoped_ptr<gfx::ImageSkia> wallpaper) {
scoped_ptr<gfx::ImageSkia> image) {
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();

Expand All @@ -468,7 +469,7 @@ void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper(
bool update_wallpaper =
user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email();
wallpaper_manager->SetWallpaperFromImageSkia(
user_id_, *wallpaper.get(), layout, update_wallpaper);
user_id_, *image.get(), layout, update_wallpaper);

bool is_persistent =
!chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral();
Expand Down Expand Up @@ -531,12 +532,9 @@ bool WallpaperPrivateSetCustomWallpaperFunction::RunImpl() {
}

void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
const gfx::ImageSkia& wallpaper) {
const gfx::ImageSkia& image) {
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();
chromeos::UserImage::RawImage raw_image(params->wallpaper.begin(),
params->wallpaper.end());
chromeos::UserImage image(wallpaper, raw_image);
base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath(
chromeos::kThumbnailWallpaperSubDir, user_id_hash_, params->file_name);

Expand All @@ -562,8 +560,8 @@ void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
unsafe_wallpaper_decoder_ = NULL;

if (params->generate_thumbnail) {
wallpaper.EnsureRepsForSupportedScales();
scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
image.EnsureRepsForSupportedScales();
scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy());
// Generates thumbnail before call api function callback. We can then
// request thumbnail in the javascript callback.
task_runner->PostTask(FROM_HERE,
Expand All @@ -579,13 +577,12 @@ void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) {
DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
sequence_token_));
chromeos::UserImage wallpaper(*image.get());
if (!base::PathExists(thumbnail_path.DirName()))
base::CreateDirectory(thumbnail_path.DirName());

scoped_refptr<base::RefCountedBytes> data;
chromeos::WallpaperManager::Get()->ResizeWallpaper(
wallpaper,
chromeos::WallpaperManager::Get()->ResizeImage(
*image,
ash::WALLPAPER_LAYOUT_STRETCH,
chromeos::kWallpaperThumbnailWidth,
chromeos::kWallpaperThumbnailHeight,
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/extensions/wallpaper_private_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WallpaperPrivateSetWallpaperIfExistsFunction
virtual bool RunImpl() OVERRIDE;

private:
virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE;

// File doesn't exist. Sets javascript callback parameter to false.
void OnFileNotExists(const std::string& error);
Expand Down Expand Up @@ -77,13 +77,13 @@ class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase {
virtual bool RunImpl() OVERRIDE;

private:
virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE;

// Saves the image data to a file.
void SaveToFile();

// Sets wallpaper to the decoded image.
void SetDecodedWallpaper(scoped_ptr<gfx::ImageSkia> wallpaper);
void SetDecodedWallpaper(scoped_ptr<gfx::ImageSkia> image);

scoped_ptr<extensions::api::wallpaper_private::SetWallpaper::Params> params;

Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/chromeos/login/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class User {
static const int kInvalidImageIndex = -3;

enum WallpaperType {
DAILY = 0,
CUSTOMIZED = 1,
DEFAULT = 2,
/* DAILY = 0 */ // Removed. Do not re-use the id!
CUSTOMIZED = 1, // Selected by user.
DEFAULT = 2, // Default.
/* UNKNOWN = 3 */ // Removed. Do not re-use the id!
ONLINE = 4,
ONLINE = 4, // WallpaperInfo.file denotes an URL.
POLICY = 5, // Controlled by policy, can't be changed by the user.
WALLPAPER_TYPE_COUNT = 6
};
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/user_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class UserManagerImpl
// Update the global LoginState.
void UpdateLoginState();

// Insert |user| at the front of the LRU user list..
// Insert |user| at the front of the LRU user list.
void SetLRUUser(User* user);

// Adds |user| to users list, and adds it to front of LRU list. It is assumed
Expand Down
Loading

0 comments on commit 7a654c5

Please sign in to comment.