OLD | NEW |
---|---|
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/desktop_background/desktop_background_widget_controller.h" | 8 #include "ash/desktop_background/desktop_background_widget_controller.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_factory.h" | 10 #include "ash/shell_factory.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 wallpaper_height < root_window_size.height()) && | 143 wallpaper_height < root_window_size.height()) && |
144 current_wallpaper_->wallpaper_index != -1 && | 144 current_wallpaper_->wallpaper_index != -1 && |
145 current_wallpaper_->wallpaper_layout != TILE) | 145 current_wallpaper_->wallpaper_layout != TILE) |
146 SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true); | 146 SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 InstallComponent(root_window); | 150 InstallComponent(root_window); |
151 } | 151 } |
152 | 152 |
153 void DesktopBackgroundController::CacheDefaultWallpaper(int index) { | |
154 if (index < 0) | |
sky
2012/08/07 20:44:18
Should this be a DCHECK?
bshe
2012/08/07 22:00:01
Done
On 2012/08/07 20:44:18, sky wrote:
| |
155 return; | |
156 | |
157 WallpaperResolution resolution = GetAppropriateResolution(); | |
158 scoped_refptr<WallpaperOperation> wallpaper_op = | |
159 new WallpaperOperation(index, resolution); | |
160 base::WorkerPool::PostTask( | |
161 FROM_HERE, | |
162 base::Bind(&WallpaperOperation::Run, wallpaper_op), | |
163 true); | |
164 } | |
165 | |
153 void DesktopBackgroundController::SetDefaultWallpaper(int index, | 166 void DesktopBackgroundController::SetDefaultWallpaper(int index, |
154 bool force_reload) { | 167 bool force_reload) { |
155 // We should not change background when index is invalid. For instance, at | 168 // We should not change background when index is invalid. For instance, at |
156 // login screen or stub_user login. | 169 // login screen or stub_user login. |
157 if (index == GetInvalidWallpaperIndex()) { | 170 if (index == GetInvalidWallpaperIndex()) { |
158 CreateEmptyWallpaper(); | 171 CreateEmptyWallpaper(); |
159 return; | 172 return; |
160 } else if (index == GetSolidColorIndex()) { | 173 } else if (index == GetSolidColorIndex()) { |
161 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); | 174 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); |
162 return; | 175 return; |
163 } | 176 } |
164 | 177 |
165 if (!force_reload && current_wallpaper_.get() && | 178 if (!force_reload && current_wallpaper_.get() && |
166 current_wallpaper_->wallpaper_index == index) | 179 current_wallpaper_->wallpaper_index == index) |
167 return; | 180 return; |
168 | 181 |
169 CancelPendingWallpaperOperation(); | 182 CancelPendingWallpaperOperation(); |
170 | 183 |
171 WallpaperResolution resolution = SMALL; | 184 WallpaperResolution resolution = GetAppropriateResolution(); |
172 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
173 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | |
174 iter != root_windows.end(); ++iter) { | |
175 gfx::Size root_window_size = (*iter)->GetHostSize(); | |
176 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | |
177 root_window_size.height() > kSmallWallpaperMaximalHeight) | |
178 resolution = LARGE; | |
179 } | |
180 | 185 |
181 wallpaper_op_ = new WallpaperOperation(index, resolution); | 186 wallpaper_op_ = new WallpaperOperation(index, resolution); |
182 base::WorkerPool::PostTaskAndReply( | 187 base::WorkerPool::PostTaskAndReply( |
183 FROM_HERE, | 188 FROM_HERE, |
184 base::Bind(&WallpaperOperation::Run, wallpaper_op_), | 189 base::Bind(&WallpaperOperation::Run, wallpaper_op_), |
185 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, | 190 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, |
186 weak_ptr_factory_.GetWeakPtr(), | 191 weak_ptr_factory_.GetWeakPtr(), |
187 wallpaper_op_), | 192 wallpaper_op_), |
188 true /* task_is_slow */); | 193 true /* task_is_slow */); |
189 } | 194 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 src_container, | 352 src_container, |
348 dst_container); | 353 dst_container); |
349 } | 354 } |
350 } | 355 } |
351 | 356 |
352 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { | 357 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { |
353 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : | 358 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : |
354 internal::kShellWindowId_DesktopBackgroundContainer; | 359 internal::kShellWindowId_DesktopBackgroundContainer; |
355 } | 360 } |
356 | 361 |
362 WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() { | |
363 WallpaperResolution resolution = SMALL; | |
364 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
sky
2012/08/07 20:44:18
None of the ui code is thread safe.
bshe
2012/08/07 22:00:01
Sorry. do you mean the code that I add is not thre
| |
365 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | |
366 iter != root_windows.end(); ++iter) { | |
367 gfx::Size root_window_size = (*iter)->GetHostSize(); | |
368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | |
369 root_window_size.height() > kSmallWallpaperMaximalHeight) | |
370 resolution = LARGE; | |
371 } | |
372 return resolution; | |
373 } | |
374 | |
357 } // namespace ash | 375 } // namespace ash |
OLD | NEW |