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

Unified Diff: ash/desktop_background/desktop_background_controller.cc

Issue 10207030: Asynchronously load wallpapers when user pod is selected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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: 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 f6b56fd07a8cbb414f65d1662a2830edefa74d7c..95d3553e329524ceef693e04856ef2e4ac30d424 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -9,7 +9,9 @@
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/root_window_layout_manager.h"
+#include "base/bind.h"
#include "base/logging.h"
+#include "base/threading/worker_pool.h"
#include "grit/ui_resources.h"
#include "ui/aura/window.h"
#include "ui/gfx/compositor/layer.h"
@@ -19,22 +21,49 @@
namespace ash {
-DesktopBackgroundController::DesktopBackgroundController() :
- desktop_background_mode_(BACKGROUND_IMAGE) {
+DesktopBackgroundController::DesktopBackgroundController()
+ : desktop_background_mode_(BACKGROUND_IMAGE),
+ layout_(CENTER_CROPPED),
+ previous_index_(-1),
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ wallpaper_ = NULL;
Nikita (slow) 2012/04/25 16:47:48 nit: align
bshe 2012/04/25 23:54:43 Done.
}
DesktopBackgroundController::~DesktopBackgroundController() {
}
+void DesktopBackgroundController::SetDefaultWallpaper(int index) {
+ if (previous_index_ == index)
+ return;
+ base::WorkerPool::PostTaskAndReply(
Nikita (slow) 2012/04/25 16:47:48 We should somehow cancel previous wallpaper load i
bshe 2012/04/25 23:54:43 Done. The new wallpaper loading always make sure t
+ FROM_HERE,
+ base::Bind(&DesktopBackgroundController::OnWallpaperLoadStarted,
+ weak_ptr_factory_.GetWeakPtr(),
+ index),
+ base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted,
+ weak_ptr_factory_.GetWeakPtr()),
+ true);
Nikita (slow) 2012/04/25 16:47:48 nit: /* task_is_slow */
bshe 2012/04/25 23:54:43 Done.
+ previous_index_ = index;
+}
+
+void DesktopBackgroundController::SetGuestWallpaper() {
+ SetDefaultWallpaper(GetGuestWallpaperIndex());
+}
+
+void DesktopBackgroundController::SetLoggedInUserWallpaper() {
+ int index = Shell::GetInstance()->user_wallpaper_delegate()->
+ GetUserWallpaperIndex();
+ SetDefaultWallpaper(index);
+}
+
void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
internal::RootWindowLayoutManager* root_window_layout =
Shell::GetInstance()->root_window_layout();
- int index = Shell::GetInstance()->user_wallpaper_delegate()->
- GetUserWallpaperIndex();
root_window_layout->SetBackgroundLayer(NULL);
- internal::CreateDesktopBackground(GetWallpaper(index),
- GetWallpaperInfo(index).layout);
- desktop_background_mode_ = BACKGROUND_IMAGE;
+ if(wallpaper_) {
+ internal::CreateDesktopBackground(*wallpaper_, layout_);
+ desktop_background_mode_ = BACKGROUND_IMAGE;
+ }
}
void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() {
@@ -52,4 +81,14 @@ void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() {
desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
}
+void DesktopBackgroundController::OnWallpaperLoadStarted(int index) {
+ wallpaper_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ GetWallpaperInfo(index).id).ToSkBitmap();
+ layout_ = GetWallpaperInfo(index).layout;
+}
+
+void DesktopBackgroundController::OnWallpaperLoadCompleted() {
+ SetDesktopBackgroundImageMode();
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698