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

Unified Diff: ash/desktop_background/desktop_background_controller.cc

Issue 110463004: ash: Fix DesktopBackgroundController getting stuck. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update a comment Created 7 years 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
« no previous file with comments | « ash/desktop_background/desktop_background_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d1c67a93f0db256e4869c6aaf645fcb014347b39..81174c2db2b08739bf5ce6027ea2485d376ba982 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -70,9 +70,25 @@ class DesktopBackgroundController::WallpaperLoader
resource_layout_(resource_layout) {
}
- static void LoadOnWorkerPoolThread(scoped_refptr<WallpaperLoader> loader) {
+ void LoadOnWorkerPoolThread() {
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
- loader->LoadWallpaper();
+ if (cancel_flag_.IsSet())
+ return;
+
+ if (!file_path_.empty())
+ file_bitmap_ = LoadSkBitmapFromJPEGFile(file_path_);
+
+ if (cancel_flag_.IsSet())
+ return;
+
+ if (file_bitmap_) {
+ gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*file_bitmap_);
+ wallpaper_resizer_.reset(new WallpaperResizer(
+ image, GetMaxDisplaySizeInNative(), file_layout_));
+ } else {
+ wallpaper_resizer_.reset(new WallpaperResizer(
+ resource_id_, GetMaxDisplaySizeInNative(), resource_layout_));
+ }
}
const base::FilePath& file_path() const { return file_path_; }
@@ -82,6 +98,10 @@ class DesktopBackgroundController::WallpaperLoader
cancel_flag_.Set();
}
+ bool IsCanceled() {
+ return cancel_flag_.IsSet();
+ }
+
WallpaperResizer* ReleaseWallpaperResizer() {
return wallpaper_resizer_.release();
}
@@ -108,26 +128,6 @@ class DesktopBackgroundController::WallpaperLoader
return bitmap.Pass();
}
- void LoadWallpaper() {
- if (cancel_flag_.IsSet())
- return;
-
- if (!file_path_.empty())
- file_bitmap_ = LoadSkBitmapFromJPEGFile(file_path_);
-
- if (cancel_flag_.IsSet())
- return;
-
- if (file_bitmap_) {
- gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*file_bitmap_);
- wallpaper_resizer_.reset(new WallpaperResizer(
- image, GetMaxDisplaySizeInNative(), file_layout_));
- } else {
- wallpaper_resizer_.reset(new WallpaperResizer(
- resource_id_, GetMaxDisplaySizeInNative(), resource_layout_));
- }
- }
-
~WallpaperLoader() {}
base::CancellationFlag cancel_flag_;
@@ -163,7 +163,7 @@ DesktopBackgroundController::DesktopBackgroundController()
}
DesktopBackgroundController::~DesktopBackgroundController() {
- CancelPendingWallpaperOperation();
+ CancelDefaultWallpaperLoader();
Shell::GetInstance()->display_controller()->RemoveObserver(this);
}
@@ -232,15 +232,16 @@ bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) {
if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id))
return false;
- CancelPendingWallpaperOperation();
- wallpaper_loader_ = new WallpaperLoader(
+ CancelDefaultWallpaperLoader();
+ default_wallpaper_loader_ = new WallpaperLoader(
file_path, file_layout, resource_id, resource_layout);
base::WorkerPool::PostTaskAndReply(
FROM_HERE,
- base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread, wallpaper_loader_),
+ base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread,
+ default_wallpaper_loader_),
base::Bind(&DesktopBackgroundController::OnDefaultWallpaperLoadCompleted,
weak_ptr_factory_.GetWeakPtr(),
- wallpaper_loader_),
+ default_wallpaper_loader_),
true /* task_is_slow */);
return true;
}
@@ -248,7 +249,8 @@ bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) {
void DesktopBackgroundController::SetCustomWallpaper(
const gfx::ImageSkia& image,
WallpaperLayout layout) {
- CancelPendingWallpaperOperation();
+ CancelDefaultWallpaperLoader();
+
if (CustomWallpaperIsAlreadyLoaded(image))
return;
@@ -264,10 +266,10 @@ void DesktopBackgroundController::SetCustomWallpaper(
SetDesktopBackgroundImageMode();
}
-void DesktopBackgroundController::CancelPendingWallpaperOperation() {
+void DesktopBackgroundController::CancelDefaultWallpaperLoader() {
// Set canceled flag of previous request to skip unneeded loading.
- if (wallpaper_loader_.get())
- wallpaper_loader_->Cancel();
+ if (default_wallpaper_loader_.get())
+ default_wallpaper_loader_->Cancel();
// Cancel reply callback for previous request.
weak_ptr_factory_.InvalidateWeakPtrs();
@@ -318,10 +320,12 @@ void DesktopBackgroundController::OnDisplayConfigurationChanged() {
}
bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded(
- const base::FilePath& image_file, int image_resource_id) const {
- return (wallpaper_loader_.get() &&
- wallpaper_loader_->file_path() == image_file &&
- wallpaper_loader_->resource_id() == image_resource_id) ||
+ const base::FilePath& image_file,
+ int image_resource_id) const {
+ return (default_wallpaper_loader_.get() &&
+ !default_wallpaper_loader_->IsCanceled() &&
+ default_wallpaper_loader_->file_path() == image_file &&
+ default_wallpaper_loader_->resource_id() == image_resource_id) ||
(current_wallpaper_.get() &&
current_default_wallpaper_path_ == image_file &&
current_default_wallpaper_resource_id_ == image_resource_id);
@@ -350,8 +354,8 @@ void DesktopBackgroundController::OnDefaultWallpaperLoadCompleted(
SetDesktopBackgroundImageMode();
- DCHECK(loader.get() == wallpaper_loader_.get());
- wallpaper_loader_ = NULL;
+ DCHECK(loader.get() == default_wallpaper_loader_.get());
+ default_wallpaper_loader_ = NULL;
}
void DesktopBackgroundController::InstallDesktopController(
« no previous file with comments | « ash/desktop_background/desktop_background_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698