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

Side by Side Diff: ash/desktop_background/desktop_background_controller.cc

Issue 236013002: Apply default wallpaper from customization manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove wallpaper URL from ServicesCustomizationDocumentTest. Created 6 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/desktop_background/desktop_background_controller.h" 5 #include "ash/desktop_background/desktop_background_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/desktop_background/desktop_background_controller_observer.h" 8 #include "ash/desktop_background/desktop_background_controller_observer.h"
9 #include "ash/desktop_background/desktop_background_view.h" 9 #include "ash/desktop_background/desktop_background_view.h"
10 #include "ash/desktop_background/desktop_background_widget_controller.h" 10 #include "ash/desktop_background/desktop_background_widget_controller.h"
(...skipping 25 matching lines...) Expand all
36 36
37 namespace ash { 37 namespace ash {
38 namespace { 38 namespace {
39 39
40 // How long to wait reloading the wallpaper after the max display has 40 // How long to wait reloading the wallpaper after the max display has
41 // changed? 41 // changed?
42 const int kWallpaperReloadDelayMs = 2000; 42 const int kWallpaperReloadDelayMs = 2000;
43 43
44 } // namespace 44 } // namespace
45 45
46 const int DesktopBackgroundController::kInvalidResourceID = -1;
47
46 DesktopBackgroundController::DesktopBackgroundController() 48 DesktopBackgroundController::DesktopBackgroundController()
47 : locked_(false), 49 : locked_(false),
48 desktop_background_mode_(BACKGROUND_NONE), 50 desktop_background_mode_(BACKGROUND_NONE),
49 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { 51 wallpaper_reload_delay_(kWallpaperReloadDelayMs) {
50 Shell::GetInstance()->display_controller()->AddObserver(this); 52 Shell::GetInstance()->display_controller()->AddObserver(this);
51 Shell::GetInstance()->AddShellObserver(this); 53 Shell::GetInstance()->AddShellObserver(this);
52 } 54 }
53 55
54 DesktopBackgroundController::~DesktopBackgroundController() { 56 DesktopBackgroundController::~DesktopBackgroundController() {
55 Shell::GetInstance()->display_controller()->RemoveObserver(this); 57 Shell::GetInstance()->display_controller()->RemoveObserver(this);
(...skipping 20 matching lines...) Expand all
76 if (current_wallpaper_) 78 if (current_wallpaper_)
77 return current_wallpaper_->layout(); 79 return current_wallpaper_->layout();
78 return WALLPAPER_LAYOUT_CENTER_CROPPED; 80 return WALLPAPER_LAYOUT_CENTER_CROPPED;
79 } 81 }
80 82
81 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, 83 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image,
82 WallpaperLayout layout) { 84 WallpaperLayout layout) {
83 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) 85 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image)
84 << " layout=" << layout; 86 << " layout=" << layout;
85 87
86 if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) { 88 if (WallpaperIsAlreadyLoaded(
89 &image, kInvalidResourceID, true /* compare_layouts */, layout)) {
87 VLOG(1) << "Wallpaper is already loaded"; 90 VLOG(1) << "Wallpaper is already loaded";
88 return false; 91 return false;
89 } 92 }
90 93
91 current_wallpaper_.reset( 94 current_wallpaper_.reset(
92 new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout)); 95 new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout));
93 current_wallpaper_->StartResize(); 96 current_wallpaper_->StartResize();
94 97
95 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, 98 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver,
96 observers_, 99 observers_,
97 OnWallpaperDataChanged()); 100 OnWallpaperDataChanged());
98 SetDesktopBackgroundImageMode(); 101 SetDesktopBackgroundImageMode();
99 return true; 102 return true;
100 } 103 }
101 104
102 bool DesktopBackgroundController::SetWallpaperResource(int resource_id, 105 bool DesktopBackgroundController::SetWallpaperResource(int resource_id,
103 WallpaperLayout layout) { 106 WallpaperLayout layout) {
104 VLOG(1) << "SetWallpaper: resource_id=" << resource_id 107 VLOG(1) << "SetWallpaper: resource_id=" << resource_id
105 << " layout=" << layout; 108 << " layout=" << layout;
106 109
107 if (WallpaperIsAlreadyLoaded(NULL, resource_id, layout)) { 110 if (WallpaperIsAlreadyLoaded(
111 NULL, resource_id, true /* compare_layouts */, layout)) {
108 VLOG(1) << "Wallpaper is already loaded"; 112 VLOG(1) << "Wallpaper is already loaded";
109 return false; 113 return false;
110 } 114 }
111 current_wallpaper_.reset( 115 current_wallpaper_.reset(
112 new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout)); 116 new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout));
113 current_wallpaper_->StartResize(); 117 current_wallpaper_->StartResize();
114 118
115 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, 119 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
116 OnWallpaperDataChanged()); 120 OnWallpaperDataChanged());
117 SetDesktopBackgroundImageMode(); 121 SetDesktopBackgroundImageMode();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 193 }
190 width = std::max(size_in_pixel.width(), width); 194 width = std::max(size_in_pixel.width(), width);
191 height = std::max(size_in_pixel.height(), height); 195 height = std::max(size_in_pixel.height(), height);
192 } 196 }
193 return gfx::Size(width, height); 197 return gfx::Size(width, height);
194 } 198 }
195 199
196 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded( 200 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded(
197 const gfx::ImageSkia* image, 201 const gfx::ImageSkia* image,
198 int resource_id, 202 int resource_id,
203 bool compare_layouts,
199 WallpaperLayout layout) const { 204 WallpaperLayout layout) const {
200 if (!current_wallpaper_.get()) 205 if (!current_wallpaper_.get())
201 return false; 206 return false;
202 207
203 if (layout != current_wallpaper_->layout()) 208 // Compare layouts only if necessary.
209 if (compare_layouts && layout != current_wallpaper_->layout())
204 return false; 210 return false;
205 211
206 if (image) { 212 if (image) {
207 return WallpaperResizer::GetImageId(*image) == 213 return WallpaperResizer::GetImageId(*image) ==
208 current_wallpaper_->original_image_id(); 214 current_wallpaper_->original_image_id();
209 } 215 }
210 216
211 return current_wallpaper_->resource_id() == resource_id; 217 return current_wallpaper_->resource_id() == resource_id;
212 } 218 }
213 219
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 : kShellWindowId_DesktopBackgroundContainer; 296 : kShellWindowId_DesktopBackgroundContainer;
291 } 297 }
292 298
293 void DesktopBackgroundController::UpdateWallpaper() { 299 void DesktopBackgroundController::UpdateWallpaper() {
294 current_wallpaper_.reset(NULL); 300 current_wallpaper_.reset(NULL);
295 ash::Shell::GetInstance()->user_wallpaper_delegate()-> 301 ash::Shell::GetInstance()->user_wallpaper_delegate()->
296 UpdateWallpaper(true /* clear cache */); 302 UpdateWallpaper(true /* clear cache */);
297 } 303 }
298 304
299 } // namespace ash 305 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698