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

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: After-review. 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 } 53 }
52 54
53 DesktopBackgroundController::~DesktopBackgroundController() { 55 DesktopBackgroundController::~DesktopBackgroundController() {
54 Shell::GetInstance()->display_controller()->RemoveObserver(this); 56 Shell::GetInstance()->display_controller()->RemoveObserver(this);
55 } 57 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 93 }
92 94
93 InstallDesktopController(root_window); 95 InstallDesktopController(root_window);
94 } 96 }
95 97
96 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, 98 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image,
97 WallpaperLayout layout) { 99 WallpaperLayout layout) {
98 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) 100 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image)
99 << " layout=" << layout; 101 << " layout=" << layout;
100 102
101 if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) { 103 if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, true, layout)) {
Nikita (slow) 2014/04/15 12:39:24 nit: /* compare layouts */
Alexander Alekseev 2014/04/15 22:47:31 Done.
102 VLOG(1) << "Wallpaper is already loaded"; 104 VLOG(1) << "Wallpaper is already loaded";
103 return false; 105 return false;
104 } 106 }
105 107
106 current_wallpaper_.reset( 108 current_wallpaper_.reset(
107 new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout)); 109 new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout));
108 current_wallpaper_->StartResize(); 110 current_wallpaper_->StartResize();
109 111
110 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, 112 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver,
111 observers_, 113 observers_,
112 OnWallpaperDataChanged()); 114 OnWallpaperDataChanged());
113 SetDesktopBackgroundImageMode(); 115 SetDesktopBackgroundImageMode();
114 return true; 116 return true;
115 } 117 }
116 118
117 bool DesktopBackgroundController::SetWallpaperResource(int resource_id, 119 bool DesktopBackgroundController::SetWallpaperResource(int resource_id,
118 WallpaperLayout layout) { 120 WallpaperLayout layout) {
119 VLOG(1) << "SetWallpaper: resource_id=" << resource_id 121 VLOG(1) << "SetWallpaper: resource_id=" << resource_id
120 << " layout=" << layout; 122 << " layout=" << layout;
121 123
122 if (WallpaperIsAlreadyLoaded(NULL, resource_id, layout)) { 124 if (WallpaperIsAlreadyLoaded(NULL, resource_id, true, layout)) {
Nikita (slow) 2014/04/15 12:39:24 nit: /* compare layouts */
Alexander Alekseev 2014/04/15 22:47:31 Done.
123 VLOG(1) << "Wallpaper is already loaded"; 125 VLOG(1) << "Wallpaper is already loaded";
124 return false; 126 return false;
125 } 127 }
126 current_wallpaper_.reset( 128 current_wallpaper_.reset(
127 new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout)); 129 new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout));
128 current_wallpaper_->StartResize(); 130 current_wallpaper_->StartResize();
129 131
130 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, 132 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
131 OnWallpaperDataChanged()); 133 OnWallpaperDataChanged());
132 SetDesktopBackgroundImageMode(); 134 SetDesktopBackgroundImageMode();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 189 }
188 width = std::max(size_in_pixel.width(), width); 190 width = std::max(size_in_pixel.width(), width);
189 height = std::max(size_in_pixel.height(), height); 191 height = std::max(size_in_pixel.height(), height);
190 } 192 }
191 return gfx::Size(width, height); 193 return gfx::Size(width, height);
192 } 194 }
193 195
194 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded( 196 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded(
195 const gfx::ImageSkia* image, 197 const gfx::ImageSkia* image,
196 int resource_id, 198 int resource_id,
199 bool compare_layouts,
197 WallpaperLayout layout) const { 200 WallpaperLayout layout) const {
198 if (!current_wallpaper_.get()) 201 if (!current_wallpaper_.get())
199 return false; 202 return false;
200 203
201 if (layout != current_wallpaper_->layout()) 204 // Compare layouts only if necessary.
205 if (compare_layouts && layout != current_wallpaper_->layout())
202 return false; 206 return false;
203 207
204 if (image) { 208 if (image) {
205 return WallpaperResizer::GetImageId(*image) == 209 return WallpaperResizer::GetImageId(*image) ==
206 current_wallpaper_->original_image_id(); 210 current_wallpaper_->original_image_id();
207 } 211 }
208 212
209 return current_wallpaper_->resource_id() == resource_id; 213 return current_wallpaper_->resource_id() == resource_id;
210 } 214 }
211 215
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 : kShellWindowId_DesktopBackgroundContainer; 292 : kShellWindowId_DesktopBackgroundContainer;
289 } 293 }
290 294
291 void DesktopBackgroundController::UpdateWallpaper() { 295 void DesktopBackgroundController::UpdateWallpaper() {
292 current_wallpaper_.reset(NULL); 296 current_wallpaper_.reset(NULL);
293 ash::Shell::GetInstance()->user_wallpaper_delegate()-> 297 ash::Shell::GetInstance()->user_wallpaper_delegate()->
294 UpdateWallpaper(true /* clear cache */); 298 UpdateWallpaper(true /* clear cache */);
295 } 299 }
296 300
297 } // namespace ash 301 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698