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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/desktop_background/desktop_background_controller.h" 5 #include "ash/desktop_background/desktop_background_controller.h"
6 6
7 #include "ash/desktop_background/desktop_background_view.h" 7 #include "ash/desktop_background/desktop_background_view.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_factory.h" 9 #include "ash/shell_factory.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/root_window_layout_manager.h" 11 #include "ash/wm/root_window_layout_manager.h"
12 #include "base/bind.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/threading/worker_pool.h"
13 #include "grit/ui_resources.h" 15 #include "grit/ui_resources.h"
14 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
15 #include "ui/gfx/compositor/layer.h" 17 #include "ui/gfx/compositor/layer.h"
16 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
17 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
19 21
20 namespace ash { 22 namespace ash {
21 23
22 DesktopBackgroundController::DesktopBackgroundController() : 24 DesktopBackgroundController::DesktopBackgroundController()
23 desktop_background_mode_(BACKGROUND_IMAGE) { 25 : desktop_background_mode_(BACKGROUND_IMAGE),
26 layout_(CENTER_CROPPED),
27 previous_index_(-1),
28 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
29 wallpaper_ = NULL;
Nikita (slow) 2012/04/25 16:47:48 nit: align
bshe 2012/04/25 23:54:43 Done.
24 } 30 }
25 31
26 DesktopBackgroundController::~DesktopBackgroundController() { 32 DesktopBackgroundController::~DesktopBackgroundController() {
27 } 33 }
28 34
35 void DesktopBackgroundController::SetDefaultWallpaper(int index) {
36 if (previous_index_ == index)
37 return;
38 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
39 FROM_HERE,
40 base::Bind(&DesktopBackgroundController::OnWallpaperLoadStarted,
41 weak_ptr_factory_.GetWeakPtr(),
42 index),
43 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted,
44 weak_ptr_factory_.GetWeakPtr()),
45 true);
Nikita (slow) 2012/04/25 16:47:48 nit: /* task_is_slow */
bshe 2012/04/25 23:54:43 Done.
46 previous_index_ = index;
47 }
48
49 void DesktopBackgroundController::SetGuestWallpaper() {
50 SetDefaultWallpaper(GetGuestWallpaperIndex());
51 }
52
53 void DesktopBackgroundController::SetLoggedInUserWallpaper() {
54 int index = Shell::GetInstance()->user_wallpaper_delegate()->
55 GetUserWallpaperIndex();
56 SetDefaultWallpaper(index);
57 }
58
29 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { 59 void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
30 internal::RootWindowLayoutManager* root_window_layout = 60 internal::RootWindowLayoutManager* root_window_layout =
31 Shell::GetInstance()->root_window_layout(); 61 Shell::GetInstance()->root_window_layout();
32 int index = Shell::GetInstance()->user_wallpaper_delegate()->
33 GetUserWallpaperIndex();
34 root_window_layout->SetBackgroundLayer(NULL); 62 root_window_layout->SetBackgroundLayer(NULL);
35 internal::CreateDesktopBackground(GetWallpaper(index), 63 if(wallpaper_) {
36 GetWallpaperInfo(index).layout); 64 internal::CreateDesktopBackground(*wallpaper_, layout_);
37 desktop_background_mode_ = BACKGROUND_IMAGE; 65 desktop_background_mode_ = BACKGROUND_IMAGE;
66 }
38 } 67 }
39 68
40 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() { 69 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() {
41 // Set a solid black background. 70 // Set a solid black background.
42 // TODO(derat): Remove this in favor of having the compositor only clear the 71 // TODO(derat): Remove this in favor of having the compositor only clear the
43 // viewport when there are regions not covered by a layer: 72 // viewport when there are regions not covered by a layer:
44 // http://crbug.com/113445 73 // http://crbug.com/113445
45 Shell* shell = Shell::GetInstance(); 74 Shell* shell = Shell::GetInstance();
46 ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); 75 ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
47 background_layer->SetColor(SK_ColorBLACK); 76 background_layer->SetColor(SK_ColorBLACK);
48 shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> 77 shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->
49 layer()->Add(background_layer); 78 layer()->Add(background_layer);
50 shell->root_window_layout()->SetBackgroundLayer(background_layer); 79 shell->root_window_layout()->SetBackgroundLayer(background_layer);
51 shell->root_window_layout()->SetBackgroundWidget(NULL); 80 shell->root_window_layout()->SetBackgroundWidget(NULL);
52 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; 81 desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
53 } 82 }
54 83
84 void DesktopBackgroundController::OnWallpaperLoadStarted(int index) {
85 wallpaper_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
86 GetWallpaperInfo(index).id).ToSkBitmap();
87 layout_ = GetWallpaperInfo(index).layout;
88 }
89
90 void DesktopBackgroundController::OnWallpaperLoadCompleted() {
91 SetDesktopBackgroundImageMode();
92 }
93
55 } // namespace ash 94 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698