OLD | NEW |
---|---|
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 // ID of an image resource to use if |file_path_| is empty or unloadable. | 148 // ID of an image resource to use if |file_path_| is empty or unloadable. |
149 int resource_id_; | 149 int resource_id_; |
150 | 150 |
151 // Layout to be used when displaying |resource_id_|. | 151 // Layout to be used when displaying |resource_id_|. |
152 WallpaperLayout resource_layout_; | 152 WallpaperLayout resource_layout_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); | 154 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); |
155 }; | 155 }; |
156 | 156 |
157 DesktopBackgroundController::DesktopBackgroundController() | 157 DesktopBackgroundController::DesktopBackgroundController() |
158 : command_line_for_testing_(NULL), | 158 : locked_(false), |
159 locked_(false), | |
160 desktop_background_mode_(BACKGROUND_NONE), | 159 desktop_background_mode_(BACKGROUND_NONE), |
161 current_default_wallpaper_resource_id_(-1), | 160 current_default_wallpaper_resource_id_(-1), |
162 weak_ptr_factory_(this), | 161 weak_ptr_factory_(this), |
163 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { | 162 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { |
164 Shell::GetInstance()->display_controller()->AddObserver(this); | 163 Shell::GetInstance()->display_controller()->AddObserver(this); |
165 } | 164 } |
166 | 165 |
167 DesktopBackgroundController::~DesktopBackgroundController() { | 166 DesktopBackgroundController::~DesktopBackgroundController() { |
168 CancelDefaultWallpaperLoader(); | 167 CancelDefaultWallpaperLoader(); |
169 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 168 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 if (current_max_display_size_ != max_display_size) { | 200 if (current_max_display_size_ != max_display_size) { |
202 current_max_display_size_ = max_display_size; | 201 current_max_display_size_ = max_display_size; |
203 if (desktop_background_mode_ == BACKGROUND_IMAGE && | 202 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
204 current_wallpaper_.get()) | 203 current_wallpaper_.get()) |
205 UpdateWallpaper(); | 204 UpdateWallpaper(); |
206 } | 205 } |
207 | 206 |
208 InstallDesktopController(root_window); | 207 InstallDesktopController(root_window); |
209 } | 208 } |
210 | 209 |
211 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { | 210 bool DesktopBackgroundController::SetDefaultWallpaper( |
212 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; | 211 const base::FilePath& small_resolution_path, |
212 const base::FilePath& large_resolution_path) { | |
213 VLOG(1) << "SetDefaultWallpaper: small_resolution_path='" | |
214 << small_resolution_path.value() << "' large_resolution_path='" | |
215 << large_resolution_path.value() << "'"; | |
213 const bool use_large = | 216 const bool use_large = |
214 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | 217 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; |
215 | 218 |
216 base::FilePath file_path; | 219 const base::FilePath& file_path = |
217 WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : | 220 use_large ? large_resolution_path : small_resolution_path; |
218 WALLPAPER_LAYOUT_CENTER; | 221 WallpaperLayout file_layout = |
219 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE : | 222 use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : WALLPAPER_LAYOUT_CENTER; |
220 IDR_AURA_WALLPAPER_DEFAULT_SMALL; | 223 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE |
224 : IDR_AURA_WALLPAPER_DEFAULT_SMALL; | |
221 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; | 225 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; |
222 | 226 |
223 CommandLine* command_line = command_line_for_testing_ ? | |
224 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | |
225 const char* switch_name = NULL; | |
226 if (is_guest) { | |
227 switch_name = use_large ? switches::kAshGuestWallpaperLarge : | |
228 switches::kAshGuestWallpaperSmall; | |
229 } else { | |
230 switch_name = use_large ? switches::kAshDefaultWallpaperLarge : | |
231 switches::kAshDefaultWallpaperSmall; | |
232 } | |
233 file_path = command_line->GetSwitchValuePath(switch_name); | |
234 | |
235 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { | 227 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { |
236 VLOG(1) << "Default wallpaper is already loading or loaded"; | 228 VLOG(1) << "Default wallpaper is already loading or loaded"; |
237 return false; | 229 return false; |
238 } | 230 } |
239 | 231 |
240 CancelDefaultWallpaperLoader(); | 232 CancelDefaultWallpaperLoader(); |
241 default_wallpaper_loader_ = new WallpaperLoader( | 233 default_wallpaper_loader_ = new WallpaperLoader( |
242 file_path, file_layout, resource_id, resource_layout); | 234 file_path, file_layout, resource_id, resource_layout); |
243 base::WorkerPool::PostTaskAndReply( | 235 base::WorkerPool::PostTaskAndReply( |
244 FROM_HERE, | 236 FROM_HERE, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 current_wallpaper_.get()) { | 313 current_wallpaper_.get()) { |
322 timer_.Stop(); | 314 timer_.Stop(); |
323 timer_.Start(FROM_HERE, | 315 timer_.Start(FROM_HERE, |
324 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), | 316 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), |
325 this, | 317 this, |
326 &DesktopBackgroundController::UpdateWallpaper); | 318 &DesktopBackgroundController::UpdateWallpaper); |
327 } | 319 } |
328 } | 320 } |
329 } | 321 } |
330 | 322 |
323 // Do not forget to update DefaultWallpaperIsAlreadyLoadingOrLoaded on change! | |
324 bool DesktopBackgroundController::DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
Daniel Erat
2014/03/25 18:32:54
i'm sorry, but i still don't understand why you ne
Alexander Alekseev
2014/03/25 19:09:33
It will work with existing method, but I will have
| |
325 const base::FilePath& image_file) const { | |
326 return (default_wallpaper_loader_.get() && | |
327 !default_wallpaper_loader_->IsCanceled() && | |
328 default_wallpaper_loader_->file_path() == image_file) || | |
329 (current_wallpaper_.get() && | |
330 current_default_wallpaper_path_ == image_file); | |
331 } | |
332 | |
333 // Do not forget to update DefaultWallpaperFileIsAlreadyLoadingOrLoaded | |
334 // on change! | |
331 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( | 335 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( |
332 const base::FilePath& image_file, | 336 const base::FilePath& image_file, |
333 int image_resource_id) const { | 337 int image_resource_id) const { |
334 return (default_wallpaper_loader_.get() && | 338 return (default_wallpaper_loader_.get() && |
335 !default_wallpaper_loader_->IsCanceled() && | 339 !default_wallpaper_loader_->IsCanceled() && |
336 default_wallpaper_loader_->file_path() == image_file && | 340 default_wallpaper_loader_->file_path() == image_file && |
337 default_wallpaper_loader_->resource_id() == image_resource_id) || | 341 default_wallpaper_loader_->resource_id() == image_resource_id) || |
338 (current_wallpaper_.get() && | 342 (current_wallpaper_.get() && |
339 current_default_wallpaper_path_ == image_file && | 343 current_default_wallpaper_path_ == image_file && |
340 current_default_wallpaper_resource_id_ == image_resource_id); | 344 current_default_wallpaper_resource_id_ == image_resource_id); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 iter->rotation() == gfx::Display::ROTATE_270) { | 472 iter->rotation() == gfx::Display::ROTATE_270) { |
469 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); | 473 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
470 } | 474 } |
471 width = std::max(size_in_pixel.width(), width); | 475 width = std::max(size_in_pixel.width(), width); |
472 height = std::max(size_in_pixel.height(), height); | 476 height = std::max(size_in_pixel.height(), height); |
473 } | 477 } |
474 return gfx::Size(width, height); | 478 return gfx::Size(width, height); |
475 } | 479 } |
476 | 480 |
477 } // namespace ash | 481 } // namespace ash |
OLD | NEW |