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

Unified Diff: chrome/browser/chromeos/login/wallpaper_manager.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/wallpaper_manager.cc
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc
index d59ae0a73bc81ef7fe553538e3b1f7f486cbaf51..cadcbb10c5bb3adbe47f84b2dae12e85c4598c6e 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager.cc
@@ -29,6 +29,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/customization_document.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/login/user_manager.h"
@@ -117,6 +118,18 @@ bool MoveCustomWallpaperDirectory(const char* sub_dir,
return false;
}
+void CheckCustomizedWallpaperFilesExist(
+ const base::FilePath& downloaded_file,
+ const WallpaperManager::CustomizedWallpaperRescaledFiles* rescaled_files,
+ WallpaperManager::CustomizedWallpaperFilesExist* exist) {
+ DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
+ DCHECK(rescaled_files);
+ DCHECK(exist);
+ exist->downloaded = base::PathExists(downloaded_file);
+ exist->rescaled_small = base::PathExists(rescaled_files->path_rescaled_small);
+ exist->rescaled_large = base::PathExists(rescaled_files->path_rescaled_large);
+}
+
} // namespace
const char kWallpaperSequenceTokenName[] = "wallpaper-sequence";
@@ -276,6 +289,21 @@ void WallpaperManager::PendingWallpaper::OnWallpaperSet() {
// WallpaperManager, public: ---------------------------------------------------
+WallpaperManager::CustomizedWallpaperRescaledFiles::
+ CustomizedWallpaperRescaledFiles(const base::FilePath& path_rescaled_small,
+ const base::FilePath& path_rescaled_large)
+ : path_rescaled_small(path_rescaled_small),
+ path_rescaled_large(path_rescaled_large) {
+}
+
+WallpaperManager::CustomizedWallpaperFilesExist::CustomizedWallpaperFilesExist()
+ : downloaded(false), rescaled_small(false), rescaled_large(false) {
+}
+
+bool WallpaperManager::CustomizedWallpaperFilesExist::AllRescaledExist() const {
+ return rescaled_small && rescaled_large;
+}
+
// TestApi. For testing purpose
WallpaperManager::TestApi::TestApi(WallpaperManager* wallpaper_manager)
: wallpaper_manager_(wallpaper_manager) {
@@ -444,6 +472,15 @@ void WallpaperManager::InitializeWallpaper() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
UserManager* user_manager = UserManager::Get();
+ // eApply device nustomization.
Daniel Erat 2014/04/14 15:26:15 nit: Apply device customization.
Alexander Alekseev 2014/04/15 01:57:16 Done.
+ if (ShouldUseCustomizedDefaultWallpaper()) {
+ SetDefaultWallpaperPath(
+ GetCustomizedWallpaperDefaultRescaledFileName(kSmallWallpaperSuffix),
+ scoped_ptr<gfx::ImageSkia>().Pass(),
+ GetCustomizedWallpaperDefaultRescaledFileName(kLargeWallpaperSuffix),
+ scoped_ptr<gfx::ImageSkia>().Pass());
+ }
+
CommandLine* command_line = GetCommandLine();
if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
// Guest wallpaper should be initialized when guest login.
@@ -797,7 +834,7 @@ void WallpaperManager::DoSetDefaultWallpaper(
: ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
DCHECK(file);
if (!default_wallpaper_image_.get() ||
- default_wallpaper_image_->url().spec() != file->value()) {
+ default_wallpaper_image_->file_path() != file->value()) {
default_wallpaper_image_.reset();
if (!file->empty()) {
loaded_wallpapers_++;
@@ -1520,6 +1557,128 @@ base::TimeDelta WallpaperManager::GetWallpaperLoadDelay() const {
return delay;
}
+void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck(
+ const GURL& wallpaper_url,
+ const base::FilePath& downloaded_file,
+ scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
+ scoped_ptr<CustomizedWallpaperFilesExist> exist) {
+ PrefService* pref_service = g_browser_process->local_state();
+
+ std::string current_url =
+ pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL);
+ if (current_url != wallpaper_url.spec() || !exist->AllRescaledExist()) {
+ DCHECK(exist->downloaded);
+ // Need rescale
+ wallpaper_loader_->Start(
+ downloaded_file.value(),
+ 0, // Do not crop.
+ base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded,
+ weak_factory_.GetWeakPtr(),
+ wallpaper_url,
+ base::Passed(rescaled_files.Pass())));
+ } else {
+ SetDefaultWallpaperPath(rescaled_files->path_rescaled_small,
+ scoped_ptr<gfx::ImageSkia>().Pass(),
+ rescaled_files->path_rescaled_large,
+ scoped_ptr<gfx::ImageSkia>().Pass());
+ }
+}
+
+void WallpaperManager::OnCustomizedDefaultWallpaperDecoded(
+ const GURL& wallpaper_url,
+ scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
+ const UserImage& wallpaper) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ // If decoded wallpaper is empty, we have probably failed to decode the file.
+ if (wallpaper.image().isNull()) {
+ LOG(WARNING) << "Failed to decode customized wallpaper.";
+ return;
+ }
+
+ wallpaper.image().EnsureRepsForSupportedScales();
+ scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
+
+ scoped_ptr<bool> success(new bool(false));
+ scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia);
+ scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia);
+
+ // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
+ base::Closure resize_closure =
+ base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper,
+ base::Unretained(this),
+ base::Passed(&deep_copy),
+ wallpaper.raw_image(),
+ base::Unretained(rescaled_files.get()),
+ base::Unretained(success.get()),
+ base::Unretained(small_wallpaper_image.get()),
+ base::Unretained(large_wallpaper_image.get()));
+ base::Closure on_resized_closure =
+ base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized,
+ weak_factory_.GetWeakPtr(),
+ wallpaper_url,
+ base::Passed(rescaled_files.Pass()),
+ base::Passed(success.Pass()),
+ base::Passed(small_wallpaper_image.Pass()),
+ base::Passed(large_wallpaper_image.Pass()));
+
+ if (!task_runner_->PostTaskAndReply(
+ FROM_HERE, resize_closure, on_resized_closure)) {
+ LOG(WARNING) << "Failed to start Customized Wallpaper resize.";
+ }
+}
+
+void WallpaperManager::ResizeCustomizedDefaultWallpaper(
+ scoped_ptr<gfx::ImageSkia> image,
+ const UserImage::RawImage& raw_image,
+ const CustomizedWallpaperRescaledFiles* rescaled_files,
+ bool* success,
+ gfx::ImageSkia* small_wallpaper_image,
+ gfx::ImageSkia* large_wallpaper_image) {
+ DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
+ sequence_token_));
+ UserImage wallpaper(*image.get(), raw_image);
+
+ *success = true;
+
+ *success &= ResizeAndSaveWallpaper(wallpaper,
+ rescaled_files->path_rescaled_small,
+ ash::WALLPAPER_LAYOUT_STRETCH,
+ kSmallWallpaperMaxWidth,
+ kSmallWallpaperMaxHeight,
+ small_wallpaper_image);
+
+ *success &= ResizeAndSaveWallpaper(wallpaper,
+ rescaled_files->path_rescaled_large,
+ ash::WALLPAPER_LAYOUT_STRETCH,
+ kLargeWallpaperMaxWidth,
+ kLargeWallpaperMaxHeight,
+ large_wallpaper_image);
+}
+
+void WallpaperManager::OnCustomizedDefaultWallpaperResized(
+ const GURL& wallpaper_url,
+ scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
+ scoped_ptr<bool> success,
+ scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
+ scoped_ptr<gfx::ImageSkia> large_wallpaper_image) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(rescaled_files.get());
+ DCHECK(success.get());
+ if (!*success) {
+ LOG(WARNING) << "Failed to save Resized Customized Default Wallpaper";
Daniel Erat 2014/04/14 15:26:15 nit: "resized customized default wallpaper" (capit
Alexander Alekseev 2014/04/15 01:57:16 Done.
+ return;
+ }
+ PrefService* pref_service = g_browser_process->local_state();
+ pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL,
+ wallpaper_url.spec());
+ SetDefaultWallpaperPath(rescaled_files->path_rescaled_small,
+ small_wallpaper_image.Pass(),
+ rescaled_files->path_rescaled_large,
+ large_wallpaper_image.Pass());
+ VLOG(1) << "Customized Default Wallpaper applied.";
+}
+
WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper(
const std::string& user_id,
bool delayed) {
@@ -1533,6 +1692,68 @@ WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper(
return pending_inactive_;
}
+// static
+base::FilePath WallpaperManager::GetCustomizedWallpaperDefaultRescaledFileName(
+ const char* suffix) {
+ const base::FilePath default_downloaded_file_name =
+ ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName();
+ const base::FilePath default_cache_dir =
+ ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir();
+ if (default_downloaded_file_name.empty() || default_cache_dir.empty())
+ return base::FilePath();
+ return default_cache_dir.Append(
+ default_downloaded_file_name.BaseName().value() + suffix);
+}
+
+void WallpaperManager::SetCustomizedDefaultWallpaper(
+ const GURL& wallpaper_url,
+ const base::FilePath& downloaded_file,
+ const base::FilePath& resized_directory) {
+ // Should fail if this ever happens in tests.
+ DCHECK(wallpaper_url.is_valid() || wallpaper_url.is_empty());
Daniel Erat 2014/04/14 15:26:15 same comment as before about is_empty
Alexander Alekseev 2014/04/15 01:57:16 Done.
+ if (!wallpaper_url.is_valid()) {
+ if (!wallpaper_url.is_empty()) {
+ LOG(WARNING) << "Invalid Customized Wallpaper URL.";
+ }
+ return;
+ }
+ std::string downloaded_file_name = downloaded_file.BaseName().value();
+ scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files(
+ new CustomizedWallpaperRescaledFiles(
+ resized_directory.Append(downloaded_file_name +
+ kSmallWallpaperSuffix),
+ resized_directory.Append(downloaded_file_name +
+ kLargeWallpaperSuffix)));
+ scoped_ptr<CustomizedWallpaperFilesExist> exist(
+ new CustomizedWallpaperFilesExist);
+
+ base::Closure check_file_exists =
+ base::Bind(&CheckCustomizedWallpaperFilesExist,
+ downloaded_file,
+ base::Unretained(rescaled_files.get()),
+ base::Unretained(exist.get()));
+ base::Closure on_checked_closure =
+ base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck,
+ weak_factory_.GetWeakPtr(),
+ wallpaper_url,
+ downloaded_file,
+ base::Passed(rescaled_files.Pass()),
+ base::Passed(exist.Pass()));
+ if (!BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE, check_file_exists, on_checked_closure)) {
+ LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist.";
+ }
+}
+
+// static
+bool WallpaperManager::ShouldUseCustomizedDefaultWallpaper() {
+ PrefService* pref_service = g_browser_process->local_state();
+
+ return !(pref_service->FindPreference(
+ prefs::kCustomizationDefaultWallpaperURL)
+ ->IsDefaultValue());
+}
+
void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine(
base::CommandLine* command_line) {
default_small_wallpaper_file_ = command_line->GetSwitchValuePath(
@@ -1552,8 +1773,7 @@ void WallpaperManager::OnDefaultWallpaperDecoded(
scoped_ptr<chromeos::UserImage>* result_out,
MovableOnDestroyCallbackHolder on_finish,
const UserImage& wallpaper) {
- result_out->reset(new UserImage(wallpaper.image()));
- (*result_out)->set_url(GURL(path.value()));
+ result_out->reset(new UserImage(wallpaper));
ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
wallpaper.image(), layout);
}
@@ -1580,4 +1800,41 @@ const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() {
: kLargeWallpaperSubDir;
}
+void WallpaperManager::SetDefaultWallpaperPath(
+ const base::FilePath& default_small_wallpaper_file,
+ scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
+ const base::FilePath& default_large_wallpaper_file,
+ scoped_ptr<gfx::ImageSkia> large_wallpaper_image) {
+ default_small_wallpaper_file_ = default_small_wallpaper_file;
+ default_large_wallpaper_file_ = default_large_wallpaper_file;
+
+ ash::DesktopBackgroundController* dbc =
+ ash::Shell::GetInstance()->desktop_background_controller();
+ const bool need_reload =
+ default_wallpaper_image_.get() &&
+ dbc->WallpaperIsAlreadyLoaded(&(default_wallpaper_image_->image()),
+ ash::kInvalidResourceID,
+ ash::WALLPAPER_LAYOUT_UNKNOWN);
+
+ default_wallpaper_image_.reset();
+ if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) {
+ if (small_wallpaper_image) {
+ default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image));
+ default_wallpaper_image_->set_file_path(
+ default_small_wallpaper_file.value());
+ }
+ } else {
+ if (large_wallpaper_image) {
+ default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image));
+ default_wallpaper_image_->set_file_path(
+ default_large_wallpaper_file.value());
+ }
+ }
+
+ if (need_reload) {
+ DoSetDefaultWallpaper(std::string(),
+ MovableOnDestroyCallbackHolder().Pass());
+ }
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698