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

Unified Diff: ash/desktop_background/desktop_background_controller.cc

Issue 208273005: If customization includes default wallpaper, download and apply it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Start customization manifest fetch on EULA accepted. Never re-fetch wallpaper. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
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..8d10b47743b9c94d3d8b87a3feee8928feff96b2 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -14,6 +14,7 @@
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
+#include "ash/shell_delegate.h"
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/root_window_layout_manager.h"
@@ -154,14 +155,29 @@ class DesktopBackgroundController::WallpaperLoader
DISALLOW_COPY_AND_ASSIGN(WallpaperLoader);
};
+void DesktopBackgroundController::SetDefaultWallpaperPathFromCommandLine(
+ base::CommandLine* command_line) {
+ default_small_wallpaper_file_ =
+ command_line->GetSwitchValuePath(switches::kAshDefaultWallpaperSmall);
+ default_large_wallpaper_file_ =
+ command_line->GetSwitchValuePath(switches::kAshDefaultWallpaperLarge);
+ guest_default_small_wallpaper_file_ =
+ command_line->GetSwitchValuePath(switches::kAshGuestWallpaperSmall);
+ guest_default_large_wallpaper_file_ =
+ command_line->GetSwitchValuePath(switches::kAshGuestWallpaperLarge);
+}
+
DesktopBackgroundController::DesktopBackgroundController()
: command_line_for_testing_(NULL),
locked_(false),
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);
+ SetDefaultWallpaperPathFromCommandLine(
+ base::CommandLine::ForCurrentProcess());
}
DesktopBackgroundController::~DesktopBackgroundController() {
@@ -175,6 +191,12 @@ gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const {
return gfx::ImageSkia();
}
+void DesktopBackgroundController::set_command_line_for_testing(
+ base::CommandLine* command_line) {
+ command_line_for_testing_ = command_line;
+ SetDefaultWallpaperPathFromCommandLine(command_line);
+}
+
void DesktopBackgroundController::AddObserver(
DesktopBackgroundControllerObserver* observer) {
observers_.AddObserver(observer);
@@ -208,29 +230,49 @@ void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) {
InstallDesktopController(root_window);
}
+void DesktopBackgroundController::CheckForCustomization() {
+ if (customization_applied_)
+ return;
+ customization_applied_ = true;
+
+ ShellDelegate* delegate = ash::Shell::GetInstance()->delegate();
+ if (delegate->ShouldUseCustomizedDefaultWallpaper()) {
+ default_small_wallpaper_file_ =
+ delegate->GetCustomizedWallpaperDefaultRescaledSmallFileName();
+ default_large_wallpaper_file_ =
+ delegate->GetCustomizedWallpaperDefaultRescaledLargeFileName();
+ VLOG(1) << "Start with customized wallpapers: small_file_name = '"
+ << default_small_wallpaper_file_.value() << "', large_file_name = '"
+ << default_large_wallpaper_file_.value() << "'";
+ }
+}
+
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.
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;
+ CheckForCustomization();
- CommandLine* command_line = command_line_for_testing_ ?
- command_line_for_testing_ : CommandLine::ForCurrentProcess();
- const char* switch_name = NULL;
+ base::FilePath file_path;
if (is_guest) {
- switch_name = use_large ? switches::kAshGuestWallpaperLarge :
- switches::kAshGuestWallpaperSmall;
+ file_path = use_large ? guest_default_large_wallpaper_file_
+ : guest_default_small_wallpaper_file_;
} else {
- switch_name = use_large ? switches::kAshDefaultWallpaperLarge :
- switches::kAshDefaultWallpaperSmall;
+ file_path = use_large ? default_large_wallpaper_file_
+ : default_small_wallpaper_file_;
}
- 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";
@@ -313,6 +355,25 @@ bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() {
GetBackgroundContainerId(false));
}
+void DesktopBackgroundController::SetDefaultWallpaperPath(
+ const base::FilePath& default_small_wallpaper_file,
+ const base::FilePath& default_large_wallpaper_file) {
+ customization_applied_ = true;
+ const bool need_reset = DefaultWallpaperFileIsAlreadyLoadingOrLoaded(
+ default_small_wallpaper_file_) ||
+ DefaultWallpaperFileIsAlreadyLoadingOrLoaded(
+ default_large_wallpaper_file_);
+ default_small_wallpaper_file_ = default_small_wallpaper_file;
+ default_large_wallpaper_file_ = default_large_wallpaper_file;
+ if (need_reset) {
+ const bool use_large =
+ GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE;
+ DoSetDefaultWallpaper((use_large ? default_large_wallpaper_file_
+ : default_small_wallpaper_file_),
+ use_large);
+ }
+}
+
void DesktopBackgroundController::OnDisplayConfigurationChanged() {
gfx::Size max_display_size = GetMaxDisplaySizeInNative();
if (current_max_display_size_ != max_display_size) {
@@ -340,6 +401,15 @@ bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded(
current_default_wallpaper_resource_id_ == image_resource_id);
}
+bool DesktopBackgroundController::DefaultWallpaperFileIsAlreadyLoadingOrLoaded(
+ const base::FilePath& image_file) const {
+ 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() &&

Powered by Google App Engine
This is Rietveld 408576698