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

Side by Side Diff: ash/desktop_background/desktop_background_controller.cc

Issue 10375010: Implement user selected wallpaper feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 7 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"
(...skipping 23 matching lines...) Expand all
34 index_(index) { 34 index_(index) {
35 } 35 }
36 36
37 static void Run(scoped_refptr<WallpaperOperation> wo) { 37 static void Run(scoped_refptr<WallpaperOperation> wo) {
38 wo->LoadingWallpaper(); 38 wo->LoadingWallpaper();
39 } 39 }
40 40
41 void LoadingWallpaper() { 41 void LoadingWallpaper() {
42 if (cancel_flag_.IsSet()) 42 if (cancel_flag_.IsSet())
43 return; 43 return;
44
45 wallpaper_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( 44 wallpaper_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
46 GetWallpaperInfo(index_).id).ToSkBitmap(); 45 GetWallpaperInfo(index_).id).ToSkBitmap();
47
48 if (cancel_flag_.IsSet()) 46 if (cancel_flag_.IsSet())
49 return; 47 return;
50 layout_ = GetWallpaperInfo(index_).layout; 48 layout_ = GetWallpaperInfo(index_).layout;
51 } 49 }
52 50
53 void Cancel() { 51 void Cancel() {
54 cancel_flag_.Set(); 52 cancel_flag_.Set();
55 } 53 }
56 54
57 const SkBitmap* wallpaper() { 55 const SkBitmap* wallpaper() {
58 return wallpaper_; 56 return wallpaper_;
59 } 57 }
60 58
61 ImageLayout image_layout() { 59 WallpaperLayout wallpaper_layout() {
62 return layout_; 60 return layout_;
63 } 61 }
64 62
65 int index() { 63 int index() {
66 return index_; 64 return index_;
67 } 65 }
68 66
69 private: 67 private:
70 friend class base::RefCountedThreadSafe< 68 friend class base::RefCountedThreadSafe<
71 DesktopBackgroundController::WallpaperOperation>; 69 DesktopBackgroundController::WallpaperOperation>;
72 ~WallpaperOperation(){};
73 70
74 base::CancellationFlag cancel_flag_; 71 base::CancellationFlag cancel_flag_;
75 72
76 const SkBitmap* wallpaper_; 73 const SkBitmap* wallpaper_;
77 ImageLayout layout_; 74 WallpaperLayout layout_;
78 int index_; 75 int index_;
79 76
80 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); 77 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation);
81 }; 78 };
82 79
83 DesktopBackgroundController::DesktopBackgroundController() 80 DesktopBackgroundController::DesktopBackgroundController()
84 : desktop_background_mode_(BACKGROUND_IMAGE), 81 : desktop_background_mode_(BACKGROUND_IMAGE),
85 previous_index_(-1), 82 previous_index_(-1),
86 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 83 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
87 } 84 }
88 85
89 DesktopBackgroundController::~DesktopBackgroundController() { 86 DesktopBackgroundController::~DesktopBackgroundController() {
90 CancelPendingWallpaperOperation(); 87 CancelPendingWallpaperOperation();
91 } 88 }
92 89
93 void DesktopBackgroundController::SetDefaultWallpaper(int index) { 90 void DesktopBackgroundController::SetDefaultWallpaper(int index) {
94 if (previous_index_ == index) 91 if (previous_index_ == index)
95 return; 92 return;
93
96 CancelPendingWallpaperOperation(); 94 CancelPendingWallpaperOperation();
97 95
98 wallpaper_op_ = new WallpaperOperation(index); 96 wallpaper_op_ = new WallpaperOperation(index);
99 base::WorkerPool::PostTaskAndReply( 97 base::WorkerPool::PostTaskAndReply(
100 FROM_HERE, 98 FROM_HERE,
101 base::Bind(&WallpaperOperation::Run, wallpaper_op_), 99 base::Bind(&WallpaperOperation::Run, wallpaper_op_),
102 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, 100 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted,
103 weak_ptr_factory_.GetWeakPtr(), 101 weak_ptr_factory_.GetWeakPtr(),
104 wallpaper_op_), 102 wallpaper_op_),
105 true /* task_is_slow */); 103 true /* task_is_slow */);
106 } 104 }
107 105
106 void DesktopBackgroundController::SetCustomWallpaper(const SkBitmap& wallpaper,
107 WallpaperLayout layout) {
108 internal::RootWindowLayoutManager* root_window_layout =
109 Shell::GetInstance()->root_window_layout();
110 root_window_layout->SetBackgroundLayer(NULL);
111 internal::CreateDesktopBackground(wallpaper, layout);
112 desktop_background_mode_ = BACKGROUND_IMAGE;
113 }
114
108 void DesktopBackgroundController::CancelPendingWallpaperOperation() { 115 void DesktopBackgroundController::CancelPendingWallpaperOperation() {
109 // Set canceled flag of previous request to skip unneeded loading. 116 // Set canceled flag of previous request to skip unneeded loading.
110 if (wallpaper_op_.get()) 117 if (wallpaper_op_.get())
111 wallpaper_op_->Cancel(); 118 wallpaper_op_->Cancel();
112 119
113 // Cancel reply callback for previous request. 120 // Cancel reply callback for previous request.
114 weak_ptr_factory_.InvalidateWeakPtrs(); 121 weak_ptr_factory_.InvalidateWeakPtrs();
115 } 122 }
116 123
117 void DesktopBackgroundController::SetLoggedInUserWallpaper() { 124 void DesktopBackgroundController::SetLoggedInUserWallpaper() {
(...skipping 23 matching lines...) Expand all
141 shell->root_window_layout()->SetBackgroundWidget(NULL); 148 shell->root_window_layout()->SetBackgroundWidget(NULL);
142 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; 149 desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
143 } 150 }
144 151
145 void DesktopBackgroundController::SetDesktopBackgroundImageMode( 152 void DesktopBackgroundController::SetDesktopBackgroundImageMode(
146 scoped_refptr<WallpaperOperation> wo) { 153 scoped_refptr<WallpaperOperation> wo) {
147 internal::RootWindowLayoutManager* root_window_layout = 154 internal::RootWindowLayoutManager* root_window_layout =
148 Shell::GetInstance()->root_window_layout(); 155 Shell::GetInstance()->root_window_layout();
149 root_window_layout->SetBackgroundLayer(NULL); 156 root_window_layout->SetBackgroundLayer(NULL);
150 if(wo->wallpaper()) { 157 if(wo->wallpaper()) {
151 internal::CreateDesktopBackground(*wo->wallpaper(), wo->image_layout()); 158 internal::CreateDesktopBackground(*wo->wallpaper(), wo->wallpaper_layout());
152 desktop_background_mode_ = BACKGROUND_IMAGE; 159 desktop_background_mode_ = BACKGROUND_IMAGE;
153 } 160 }
154 } 161 }
155 162
156 void DesktopBackgroundController::OnWallpaperLoadCompleted( 163 void DesktopBackgroundController::OnWallpaperLoadCompleted(
157 scoped_refptr<WallpaperOperation> wo) { 164 scoped_refptr<WallpaperOperation> wo) {
158 SetDesktopBackgroundImageMode(wo); 165 SetDesktopBackgroundImageMode(wo);
159 previous_index_ = wo->index(); 166 previous_index_ = wo->index();
160 167
161 DCHECK(wo.get() == wallpaper_op_.get()); 168 DCHECK(wo.get() == wallpaper_op_.get());
162 wallpaper_op_ = NULL; 169 wallpaper_op_ = NULL;
163 } 170 }
164 171
165 void DesktopBackgroundController::CreateEmptyWallpaper() { 172 void DesktopBackgroundController::CreateEmptyWallpaper() {
166 SkBitmap dummy; 173 SkBitmap dummy;
167 internal::CreateDesktopBackground(dummy, CENTER); 174 internal::CreateDesktopBackground(dummy, CENTER);
168 desktop_background_mode_ = BACKGROUND_IMAGE; 175 desktop_background_mode_ = BACKGROUND_IMAGE;
169 } 176 }
170 177
171 } // namespace ash 178 } // namespace ash
OLDNEW
« no previous file with comments | « ash/desktop_background/desktop_background_controller.h ('k') | ash/desktop_background/desktop_background_resources.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698