Skip to content

Commit

Permalink
Apply default wallpaper from customization manifest.
Browse files Browse the repository at this point in the history
This CL also fixes bug with default wallpaper cache.

BUG=348136,363134 
TEST=manual

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265636 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
alemate@chromium.org committed Apr 23, 2014
1 parent 9b9ed01 commit 9436582
Show file tree
Hide file tree
Showing 21 changed files with 1,132 additions and 75 deletions.
12 changes: 9 additions & 3 deletions ash/desktop_background/desktop_background_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const int kWallpaperReloadDelayMs = 2000;

} // namespace

const int DesktopBackgroundController::kInvalidResourceID = -1;

DesktopBackgroundController::DesktopBackgroundController()
: locked_(false),
desktop_background_mode_(BACKGROUND_NONE),
Expand Down Expand Up @@ -83,7 +85,8 @@ bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image,
VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image)
<< " layout=" << layout;

if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) {
if (WallpaperIsAlreadyLoaded(
&image, kInvalidResourceID, true /* compare_layouts */, layout)) {
VLOG(1) << "Wallpaper is already loaded";
return false;
}
Expand All @@ -104,7 +107,8 @@ bool DesktopBackgroundController::SetWallpaperResource(int resource_id,
VLOG(1) << "SetWallpaper: resource_id=" << resource_id
<< " layout=" << layout;

if (WallpaperIsAlreadyLoaded(NULL, resource_id, layout)) {
if (WallpaperIsAlreadyLoaded(
NULL, resource_id, true /* compare_layouts */, layout)) {
VLOG(1) << "Wallpaper is already loaded";
return false;
}
Expand Down Expand Up @@ -196,11 +200,13 @@ gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() {
bool DesktopBackgroundController::WallpaperIsAlreadyLoaded(
const gfx::ImageSkia* image,
int resource_id,
bool compare_layouts,
WallpaperLayout layout) const {
if (!current_wallpaper_.get())
return false;

if (layout != current_wallpaper_->layout())
// Compare layouts only if necessary.
if (compare_layouts && layout != current_wallpaper_->layout())
return false;

if (image) {
Expand Down
18 changes: 12 additions & 6 deletions ash/desktop_background/desktop_background_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum WallpaperLayout {
// desktop's size.
WALLPAPER_LAYOUT_STRETCH,
// Tile the wallpaper over the background without scaling it.
WALLPAPER_LAYOUT_TILE,
WALLPAPER_LAYOUT_TILE
};

const SkColor kLoginWallpaperColor = 0xFEFEFE;
Expand All @@ -57,6 +57,10 @@ class ASH_EXPORT DesktopBackgroundController
BACKGROUND_IMAGE,
};

// This is used to initialize Resource ID variables and to denote "no
// resource ID" in parameters.
static const int kInvalidResourceID;

DesktopBackgroundController();
virtual ~DesktopBackgroundController();

Expand Down Expand Up @@ -110,18 +114,20 @@ class ASH_EXPORT DesktopBackgroundController
// maximum width of all displays, and the maximum height of all displays.
static gfx::Size GetMaxDisplaySizeInNative();

private:
friend class DesktopBackgroundControllerTest;
// friend class chromeos::WallpaperManagerBrowserTestDefaultWallpaper;
FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize);

// Returns true if the specified wallpaper is already stored
// in |current_wallpaper_|.
// If |image| is NULL, resource_id is compared.
// If |compare_layouts| is false, layout is ignored.
bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia* image,
int resource_id,
bool compare_layouts,
WallpaperLayout layout) const;

private:
friend class DesktopBackgroundControllerTest;
// friend class chromeos::WallpaperManagerBrowserTestDefaultWallpaper;
FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize);

// Creates view for all root windows, or notifies them to repaint if they
// already exist.
void SetDesktopBackgroundImageMode();
Expand Down
4 changes: 1 addition & 3 deletions ash/desktop_background/wallpaper_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ void Resize(SkBitmap orig_bitmap,

} // namespace

const int kInvalidResourceID = -1;

// static
uint32_t WallpaperResizer::GetImageId(const gfx::ImageSkia& image) {
const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(1.0f);
Expand All @@ -120,7 +118,7 @@ WallpaperResizer::WallpaperResizer(const gfx::ImageSkia& image,
WallpaperLayout layout)
: image_(image),
original_image_id_(GetImageId(image_)),
resource_id_(kInvalidResourceID),
resource_id_(DesktopBackgroundController::kInvalidResourceID),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
Expand Down
2 changes: 0 additions & 2 deletions ash/desktop_background/wallpaper_resizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace ash {

class WallpaperResizerObserver;

extern const int kInvalidResourceID;

// Stores the current wallpaper data and resize it to |target_size| if needed.
class ASH_EXPORT WallpaperResizer {
public:
Expand Down
Loading

0 comments on commit 9436582

Please sign in to comment.