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" |
11 #include "ash/desktop_background/user_wallpaper_delegate.h" | 11 #include "ash/desktop_background/user_wallpaper_delegate.h" |
12 #include "ash/desktop_background/wallpaper_resizer.h" | 12 #include "ash/desktop_background/wallpaper_resizer.h" |
13 #include "ash/display/display_info.h" | 13 #include "ash/display/display_info.h" |
14 #include "ash/display/display_manager.h" | 14 #include "ash/display/display_manager.h" |
15 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "ash/shell_delegate.h" | |
17 #include "ash/shell_factory.h" | 18 #include "ash/shell_factory.h" |
18 #include "ash/shell_window_ids.h" | 19 #include "ash/shell_window_ids.h" |
19 #include "ash/wm/root_window_layout_manager.h" | 20 #include "ash/wm/root_window_layout_manager.h" |
20 #include "base/bind.h" | 21 #include "base/bind.h" |
21 #include "base/command_line.h" | 22 #include "base/command_line.h" |
22 #include "base/file_util.h" | 23 #include "base/file_util.h" |
23 #include "base/logging.h" | 24 #include "base/logging.h" |
24 #include "base/synchronization/cancellation_flag.h" | 25 #include "base/synchronization/cancellation_flag.h" |
25 #include "base/threading/worker_pool.h" | 26 #include "base/threading/worker_pool.h" |
26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 148 |
148 // ID of an image resource to use if |file_path_| is empty or unloadable. | 149 // ID of an image resource to use if |file_path_| is empty or unloadable. |
149 int resource_id_; | 150 int resource_id_; |
150 | 151 |
151 // Layout to be used when displaying |resource_id_|. | 152 // Layout to be used when displaying |resource_id_|. |
152 WallpaperLayout resource_layout_; | 153 WallpaperLayout resource_layout_; |
153 | 154 |
154 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); | 155 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); |
155 }; | 156 }; |
156 | 157 |
158 void DesktopBackgroundController::SetDefaultWallpaperPathFromCommandLine( | |
159 base::CommandLine* command_line) { | |
160 default_small_wallpaper_file_ = | |
161 command_line->GetSwitchValuePath(switches::kAshDefaultWallpaperSmall); | |
162 default_large_wallpaper_file_ = | |
163 command_line->GetSwitchValuePath(switches::kAshDefaultWallpaperLarge); | |
164 guest_default_small_wallpaper_file_ = | |
165 command_line->GetSwitchValuePath(switches::kAshGuestWallpaperSmall); | |
166 guest_default_large_wallpaper_file_ = | |
167 command_line->GetSwitchValuePath(switches::kAshGuestWallpaperLarge); | |
168 } | |
169 | |
157 DesktopBackgroundController::DesktopBackgroundController() | 170 DesktopBackgroundController::DesktopBackgroundController() |
158 : command_line_for_testing_(NULL), | 171 : command_line_for_testing_(NULL), |
159 locked_(false), | 172 locked_(false), |
160 desktop_background_mode_(BACKGROUND_NONE), | 173 desktop_background_mode_(BACKGROUND_NONE), |
161 current_default_wallpaper_resource_id_(-1), | 174 current_default_wallpaper_resource_id_(-1), |
162 weak_ptr_factory_(this), | 175 weak_ptr_factory_(this), |
163 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { | 176 wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
177 customization_applied_(false) { | |
164 Shell::GetInstance()->display_controller()->AddObserver(this); | 178 Shell::GetInstance()->display_controller()->AddObserver(this); |
179 SetDefaultWallpaperPathFromCommandLine( | |
180 base::CommandLine::ForCurrentProcess()); | |
165 } | 181 } |
166 | 182 |
167 DesktopBackgroundController::~DesktopBackgroundController() { | 183 DesktopBackgroundController::~DesktopBackgroundController() { |
168 CancelDefaultWallpaperLoader(); | 184 CancelDefaultWallpaperLoader(); |
169 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 185 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
170 } | 186 } |
171 | 187 |
172 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 188 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
173 if (current_wallpaper_) | 189 if (current_wallpaper_) |
174 return current_wallpaper_->image(); | 190 return current_wallpaper_->image(); |
175 return gfx::ImageSkia(); | 191 return gfx::ImageSkia(); |
176 } | 192 } |
177 | 193 |
194 void DesktopBackgroundController::set_command_line_for_testing( | |
195 base::CommandLine* command_line) { | |
196 command_line_for_testing_ = command_line; | |
197 SetDefaultWallpaperPathFromCommandLine(command_line); | |
198 } | |
199 | |
178 void DesktopBackgroundController::AddObserver( | 200 void DesktopBackgroundController::AddObserver( |
179 DesktopBackgroundControllerObserver* observer) { | 201 DesktopBackgroundControllerObserver* observer) { |
180 observers_.AddObserver(observer); | 202 observers_.AddObserver(observer); |
181 } | 203 } |
182 | 204 |
183 void DesktopBackgroundController::RemoveObserver( | 205 void DesktopBackgroundController::RemoveObserver( |
184 DesktopBackgroundControllerObserver* observer) { | 206 DesktopBackgroundControllerObserver* observer) { |
185 observers_.RemoveObserver(observer); | 207 observers_.RemoveObserver(observer); |
186 } | 208 } |
187 | 209 |
(...skipping 13 matching lines...) Expand all Loading... | |
201 if (current_max_display_size_ != max_display_size) { | 223 if (current_max_display_size_ != max_display_size) { |
202 current_max_display_size_ = max_display_size; | 224 current_max_display_size_ = max_display_size; |
203 if (desktop_background_mode_ == BACKGROUND_IMAGE && | 225 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
204 current_wallpaper_.get()) | 226 current_wallpaper_.get()) |
205 UpdateWallpaper(); | 227 UpdateWallpaper(); |
206 } | 228 } |
207 | 229 |
208 InstallDesktopController(root_window); | 230 InstallDesktopController(root_window); |
209 } | 231 } |
210 | 232 |
233 void DesktopBackgroundController::CheckForCustomization() { | |
234 if (customization_applied_) | |
235 return; | |
236 customization_applied_ = true; | |
237 | |
238 ShellDelegate* delegate = ash::Shell::GetInstance()->delegate(); | |
239 if (delegate->ShouldUseCustomizedDefaultWallpaper()) { | |
240 default_small_wallpaper_file_ = | |
241 delegate->GetCustomizedWallpaperDefaultRescaledSmallFileName(); | |
242 default_large_wallpaper_file_ = | |
243 delegate->GetCustomizedWallpaperDefaultRescaledLargeFileName(); | |
244 VLOG(1) << "Start with customized wallpapers: small_file_name = '" | |
245 << default_small_wallpaper_file_.value() << "', large_file_name = '" | |
246 << default_large_wallpaper_file_.value() << "'"; | |
247 } | |
248 } | |
249 | |
211 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { | 250 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { |
bshe
2014/03/24 21:30:49
SetDefaultWallpaper is only called in wallpaper_ma
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
212 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; | 251 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; |
213 const bool use_large = | 252 const bool use_large = |
214 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | 253 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; |
215 | 254 |
255 CheckForCustomization(); | |
256 | |
216 base::FilePath file_path; | 257 base::FilePath file_path; |
217 WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : | 258 if (is_guest) { |
218 WALLPAPER_LAYOUT_CENTER; | 259 file_path = use_large ? guest_default_large_wallpaper_file_ |
219 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE : | 260 : guest_default_small_wallpaper_file_; |
220 IDR_AURA_WALLPAPER_DEFAULT_SMALL; | 261 } else { |
262 file_path = use_large ? default_large_wallpaper_file_ | |
263 : default_small_wallpaper_file_; | |
264 } | |
265 return DoSetDefaultWallpaper(file_path, use_large); | |
266 } | |
267 | |
268 bool DesktopBackgroundController::DoSetDefaultWallpaper( | |
269 const base::FilePath& file_path, | |
270 const bool use_large) { | |
271 WallpaperLayout file_layout = | |
272 use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : WALLPAPER_LAYOUT_CENTER; | |
273 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE | |
274 : IDR_AURA_WALLPAPER_DEFAULT_SMALL; | |
221 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; | 275 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; |
222 | 276 |
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)) { | 277 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { |
236 VLOG(1) << "Default wallpaper is already loading or loaded"; | 278 VLOG(1) << "Default wallpaper is already loading or loaded"; |
237 return false; | 279 return false; |
238 } | 280 } |
239 | 281 |
240 CancelDefaultWallpaperLoader(); | 282 CancelDefaultWallpaperLoader(); |
241 default_wallpaper_loader_ = new WallpaperLoader( | 283 default_wallpaper_loader_ = new WallpaperLoader( |
242 file_path, file_layout, resource_id, resource_layout); | 284 file_path, file_layout, resource_id, resource_layout); |
243 base::WorkerPool::PostTaskAndReply( | 285 base::WorkerPool::PostTaskAndReply( |
244 FROM_HERE, | 286 FROM_HERE, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 } | 348 } |
307 | 349 |
308 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { | 350 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { |
309 if (!locked_) | 351 if (!locked_) |
310 return false; | 352 return false; |
311 locked_ = false; | 353 locked_ = false; |
312 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), | 354 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), |
313 GetBackgroundContainerId(false)); | 355 GetBackgroundContainerId(false)); |
314 } | 356 } |
315 | 357 |
358 void DesktopBackgroundController::SetDefaultWallpaperPath( | |
359 const base::FilePath& default_small_wallpaper_file, | |
360 const base::FilePath& default_large_wallpaper_file) { | |
361 customization_applied_ = true; | |
362 const bool need_reset = DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
363 default_small_wallpaper_file_) || | |
364 DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
365 default_large_wallpaper_file_); | |
366 default_small_wallpaper_file_ = default_small_wallpaper_file; | |
367 default_large_wallpaper_file_ = default_large_wallpaper_file; | |
368 if (need_reset) { | |
369 const bool use_large = | |
370 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | |
371 DoSetDefaultWallpaper((use_large ? default_large_wallpaper_file_ | |
372 : default_small_wallpaper_file_), | |
373 use_large); | |
374 } | |
375 } | |
376 | |
316 void DesktopBackgroundController::OnDisplayConfigurationChanged() { | 377 void DesktopBackgroundController::OnDisplayConfigurationChanged() { |
317 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | 378 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
318 if (current_max_display_size_ != max_display_size) { | 379 if (current_max_display_size_ != max_display_size) { |
319 current_max_display_size_ = max_display_size; | 380 current_max_display_size_ = max_display_size; |
320 if (desktop_background_mode_ == BACKGROUND_IMAGE && | 381 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
321 current_wallpaper_.get()) { | 382 current_wallpaper_.get()) { |
322 timer_.Stop(); | 383 timer_.Stop(); |
323 timer_.Start(FROM_HERE, | 384 timer_.Start(FROM_HERE, |
324 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), | 385 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), |
325 this, | 386 this, |
326 &DesktopBackgroundController::UpdateWallpaper); | 387 &DesktopBackgroundController::UpdateWallpaper); |
327 } | 388 } |
328 } | 389 } |
329 } | 390 } |
330 | 391 |
331 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( | 392 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( |
332 const base::FilePath& image_file, | 393 const base::FilePath& image_file, |
333 int image_resource_id) const { | 394 int image_resource_id) const { |
334 return (default_wallpaper_loader_.get() && | 395 return (default_wallpaper_loader_.get() && |
335 !default_wallpaper_loader_->IsCanceled() && | 396 !default_wallpaper_loader_->IsCanceled() && |
336 default_wallpaper_loader_->file_path() == image_file && | 397 default_wallpaper_loader_->file_path() == image_file && |
337 default_wallpaper_loader_->resource_id() == image_resource_id) || | 398 default_wallpaper_loader_->resource_id() == image_resource_id) || |
338 (current_wallpaper_.get() && | 399 (current_wallpaper_.get() && |
339 current_default_wallpaper_path_ == image_file && | 400 current_default_wallpaper_path_ == image_file && |
340 current_default_wallpaper_resource_id_ == image_resource_id); | 401 current_default_wallpaper_resource_id_ == image_resource_id); |
341 } | 402 } |
342 | 403 |
404 bool DesktopBackgroundController::DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
405 const base::FilePath& image_file) const { | |
406 return (default_wallpaper_loader_.get() && | |
407 !default_wallpaper_loader_->IsCanceled() && | |
408 default_wallpaper_loader_->file_path() == image_file) || | |
409 (current_wallpaper_.get() && | |
410 current_default_wallpaper_path_ == image_file); | |
411 } | |
412 | |
343 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( | 413 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( |
344 const gfx::ImageSkia& image) const { | 414 const gfx::ImageSkia& image) const { |
345 return current_wallpaper_.get() && | 415 return current_wallpaper_.get() && |
346 (WallpaperResizer::GetImageId(image) == | 416 (WallpaperResizer::GetImageId(image) == |
347 current_wallpaper_->original_image_id()); | 417 current_wallpaper_->original_image_id()); |
348 } | 418 } |
349 | 419 |
350 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 420 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
351 desktop_background_mode_ = BACKGROUND_IMAGE; | 421 desktop_background_mode_ = BACKGROUND_IMAGE; |
352 InstallDesktopControllerForAllWindows(); | 422 InstallDesktopControllerForAllWindows(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 iter->rotation() == gfx::Display::ROTATE_270) { | 538 iter->rotation() == gfx::Display::ROTATE_270) { |
469 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); | 539 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
470 } | 540 } |
471 width = std::max(size_in_pixel.width(), width); | 541 width = std::max(size_in_pixel.width(), width); |
472 height = std::max(size_in_pixel.height(), height); | 542 height = std::max(size_in_pixel.height(), height); |
473 } | 543 } |
474 return gfx::Size(width, height); | 544 return gfx::Size(width, height); |
475 } | 545 } |
476 | 546 |
477 } // namespace ash | 547 } // namespace ash |
OLD | NEW |