Index: ash/desktop_background/desktop_background_controller.cc |
diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc |
index 7673f29aa6a48d9439e9397c4663105e09f001b3..a84cb52753533564d2f2257368a4295022a37cbd 100644 |
--- a/ash/desktop_background/desktop_background_controller.cc |
+++ b/ash/desktop_background/desktop_background_controller.cc |
@@ -33,6 +33,10 @@ |
#include "ui/gfx/rect.h" |
#include "ui/views/widget/widget.h" |
+#if defined(OS_CHROMEOS) |
+#include "chrome/browser/chromeos/login/wallpaper_manager.h" |
Daniel Erat
2014/03/24 16:25:48
ash isn't allowed to depend on chrome. you need to
Alexander Alekseev
2014/03/24 17:33:43
Done.
|
+#endif |
+ |
using ash::internal::DesktopBackgroundWidgetController; |
using content::BrowserThread; |
@@ -160,7 +164,8 @@ DesktopBackgroundController::DesktopBackgroundController() |
desktop_background_mode_(BACKGROUND_NONE), |
current_default_wallpaper_resource_id_(-1), |
weak_ptr_factory_(this), |
- wallpaper_reload_delay_(kWallpaperReloadDelayMs) { |
+ wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
+ customization_applied_(false) { |
Shell::GetInstance()->display_controller()->AddObserver(this); |
} |
@@ -208,29 +213,59 @@ void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) { |
InstallDesktopController(root_window); |
} |
+void DesktopBackgroundController::CheckForCustomization() { |
+#if defined(OS_CHROMEOS) |
+ if (customization_applied_) |
+ return; |
+ customization_applied_ = true; |
+ |
+ if (chromeos::WallpaperManager::ShouldUseCustomizedDefaultWallpaper()) { |
+ customized_default_wallpaper_file_small_ = chromeos::WallpaperManager:: |
+ GetCustomizedWallpaperDefaultRescaledSmallFileName(); |
+ customized_default_wallpaper_file_large_ = chromeos::WallpaperManager:: |
+ GetCustomizedWallpaperDefaultRescaledLargeFileName(); |
+ VLOG(1) << "Start with customized wallpapers: small_file_name = '" |
+ << customized_default_wallpaper_file_small_.value() |
+ << "', large_file_name = '" |
+ << customized_default_wallpaper_file_large_.value() << "'"; |
+ } |
+#endif |
+} |
+ |
bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { |
VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; |
const bool use_large = |
GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; |
- |
- base::FilePath file_path; |
- WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : |
- WALLPAPER_LAYOUT_CENTER; |
- int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE : |
- IDR_AURA_WALLPAPER_DEFAULT_SMALL; |
- WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; |
- |
CommandLine* command_line = command_line_for_testing_ ? |
command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
- const char* switch_name = NULL; |
+ |
+ CheckForCustomization(); |
+ |
+ base::FilePath file_path; |
if (is_guest) { |
- switch_name = use_large ? switches::kAshGuestWallpaperLarge : |
- switches::kAshGuestWallpaperSmall; |
+ const char* switch_name = use_large ? switches::kAshGuestWallpaperLarge |
+ : switches::kAshGuestWallpaperSmall; |
+ file_path = command_line->GetSwitchValuePath(switch_name); |
+ } else if (use_large && !customized_default_wallpaper_file_large_.empty()) { |
+ file_path = customized_default_wallpaper_file_large_; |
+ } else if (!use_large && !customized_default_wallpaper_file_small_.empty()) { |
+ file_path = customized_default_wallpaper_file_small_; |
} else { |
- switch_name = use_large ? switches::kAshDefaultWallpaperLarge : |
- switches::kAshDefaultWallpaperSmall; |
+ const char* switch_name = use_large ? switches::kAshDefaultWallpaperLarge |
+ : switches::kAshDefaultWallpaperSmall; |
+ file_path = command_line->GetSwitchValuePath(switch_name); |
} |
- file_path = command_line->GetSwitchValuePath(switch_name); |
+ return DoSetDefaultWallpaper(file_path, use_large); |
+} |
+ |
+bool DesktopBackgroundController::DoSetDefaultWallpaper( |
+ const base::FilePath& file_path, |
+ const bool use_large) { |
+ WallpaperLayout file_layout = |
+ use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : WALLPAPER_LAYOUT_CENTER; |
+ int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE |
+ : IDR_AURA_WALLPAPER_DEFAULT_SMALL; |
+ WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; |
if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { |
VLOG(1) << "Default wallpaper is already loading or loaded"; |
@@ -251,6 +286,28 @@ bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { |
return true; |
} |
+void DesktopBackgroundController::SetDefaultWallpaperPath( |
+ const base::FilePath& customized_default_wallpaper_file_small, |
+ const base::FilePath& customized_default_wallpaper_file_large) { |
+ customization_applied_ = true; |
+ const bool need_reset = DefaultWallpaperFileIsAlreadyLoadingOrLoaded( |
+ customized_default_wallpaper_file_small_) || |
+ DefaultWallpaperFileIsAlreadyLoadingOrLoaded( |
+ customized_default_wallpaper_file_large_); |
Daniel Erat
2014/03/24 16:25:48
why is all this stuff necessary? does the followin
Alexander Alekseev
2014/03/24 17:33:43
Done.
|
+ customized_default_wallpaper_file_small_ = |
+ customized_default_wallpaper_file_small; |
+ customized_default_wallpaper_file_large_ = |
+ customized_default_wallpaper_file_large; |
+ if (need_reset) { |
+ const bool use_large = |
+ GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; |
+ DoSetDefaultWallpaper( |
+ (use_large ? customized_default_wallpaper_file_large_ |
+ : customized_default_wallpaper_file_small_), |
+ use_large); |
+ } |
+} |
+ |
void DesktopBackgroundController::SetCustomWallpaper( |
const gfx::ImageSkia& image, |
WallpaperLayout layout) { |
@@ -340,6 +397,15 @@ bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( |
current_default_wallpaper_resource_id_ == image_resource_id); |
} |
+bool DesktopBackgroundController::DefaultWallpaperFileIsAlreadyLoadingOrLoaded( |
+ const base::FilePath& image_file) const { |
Daniel Erat
2014/03/24 16:25:48
why do you need this method? it looks like it's mo
Alexander Alekseev
2014/03/24 17:33:43
I need to detect the usage of default wallpaper re
Daniel Erat
2014/03/24 19:19:43
resource_id is just a fallback that we use if we c
Alexander Alekseev
2014/03/24 19:52:58
bool DesktopBackgroundController::DoSetDefaultWall
|
+ return (default_wallpaper_loader_.get() && |
+ !default_wallpaper_loader_->IsCanceled() && |
+ default_wallpaper_loader_->file_path() == image_file) || |
+ (current_wallpaper_.get() && |
+ current_default_wallpaper_path_ == image_file); |
+} |
+ |
bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( |
const gfx::ImageSkia& image) const { |
return current_wallpaper_.get() && |