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

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

Issue 10459003: Load user custom wallpaper after browser crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit Created 8 years, 6 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 DesktopBackgroundController::~DesktopBackgroundController() { 86 DesktopBackgroundController::~DesktopBackgroundController() {
87 CancelPendingWallpaperOperation(); 87 CancelPendingWallpaperOperation();
88 } 88 }
89 89
90 void DesktopBackgroundController::SetDefaultWallpaper(int index) { 90 void DesktopBackgroundController::SetDefaultWallpaper(int index) {
91 if (previous_index_ == index) 91 if (previous_index_ == index)
92 return; 92 return;
93 93
94 // We should not change background when index is invalid. For instance, at
95 // login screen or stub_user login.
96 if (index == ash::GetInvalidWallpaperIndex()) {
97 CreateEmptyWallpaper();
98 return;
99 }
100
94 CancelPendingWallpaperOperation(); 101 CancelPendingWallpaperOperation();
95 102
96 wallpaper_op_ = new WallpaperOperation(index); 103 wallpaper_op_ = new WallpaperOperation(index);
97 base::WorkerPool::PostTaskAndReply( 104 base::WorkerPool::PostTaskAndReply(
98 FROM_HERE, 105 FROM_HERE,
99 base::Bind(&WallpaperOperation::Run, wallpaper_op_), 106 base::Bind(&WallpaperOperation::Run, wallpaper_op_),
100 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, 107 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted,
101 weak_ptr_factory_.GetWeakPtr(), 108 weak_ptr_factory_.GetWeakPtr(),
102 wallpaper_op_), 109 wallpaper_op_),
103 true /* task_is_slow */); 110 true /* task_is_slow */);
(...skipping 10 matching lines...) Expand all
114 121
115 void DesktopBackgroundController::CancelPendingWallpaperOperation() { 122 void DesktopBackgroundController::CancelPendingWallpaperOperation() {
116 // Set canceled flag of previous request to skip unneeded loading. 123 // Set canceled flag of previous request to skip unneeded loading.
117 if (wallpaper_op_.get()) 124 if (wallpaper_op_.get())
118 wallpaper_op_->Cancel(); 125 wallpaper_op_->Cancel();
119 126
120 // Cancel reply callback for previous request. 127 // Cancel reply callback for previous request.
121 weak_ptr_factory_.InvalidateWeakPtrs(); 128 weak_ptr_factory_.InvalidateWeakPtrs();
122 } 129 }
123 130
124 void DesktopBackgroundController::SetLoggedInUserWallpaper() {
125 int index = Shell::GetInstance()->user_wallpaper_delegate()->
126 GetUserWallpaperIndex();
127 // We should not change background when index is invalid. For instance, at
128 // login screen or stub_user login.
129 if (index == ash::GetInvalidWallpaperIndex()) {
130 CreateEmptyWallpaper();
131 return;
132 }
133
134 SetDefaultWallpaper(index);
135 }
136
137 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() { 131 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() {
138 // Set a solid black background. 132 // Set a solid black background.
139 // TODO(derat): Remove this in favor of having the compositor only clear the 133 // TODO(derat): Remove this in favor of having the compositor only clear the
140 // viewport when there are regions not covered by a layer: 134 // viewport when there are regions not covered by a layer:
141 // http://crbug.com/113445 135 // http://crbug.com/113445
142 Shell* shell = Shell::GetInstance(); 136 Shell* shell = Shell::GetInstance();
143 ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); 137 ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
144 background_layer->SetColor(SK_ColorBLACK); 138 background_layer->SetColor(SK_ColorBLACK);
145 shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> 139 shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->
146 layer()->Add(background_layer); 140 layer()->Add(background_layer);
(...skipping 16 matching lines...) Expand all
163 void DesktopBackgroundController::OnWallpaperLoadCompleted( 157 void DesktopBackgroundController::OnWallpaperLoadCompleted(
164 scoped_refptr<WallpaperOperation> wo) { 158 scoped_refptr<WallpaperOperation> wo) {
165 SetDesktopBackgroundImageMode(wo); 159 SetDesktopBackgroundImageMode(wo);
166 previous_index_ = wo->index(); 160 previous_index_ = wo->index();
167 161
168 DCHECK(wo.get() == wallpaper_op_.get()); 162 DCHECK(wo.get() == wallpaper_op_.get());
169 wallpaper_op_ = NULL; 163 wallpaper_op_ = NULL;
170 } 164 }
171 165
172 void DesktopBackgroundController::CreateEmptyWallpaper() { 166 void DesktopBackgroundController::CreateEmptyWallpaper() {
173 SkBitmap dummy; 167 SkBitmap dummy;
Nikita (slow) 2012/05/30 17:25:06 related question: So is this a black background by
bshe 2012/05/30 23:33:05 Yes, this creates a black background for stub user
174 internal::CreateDesktopBackground(dummy, CENTER); 168 internal::CreateDesktopBackground(dummy, CENTER);
175 desktop_background_mode_ = BACKGROUND_IMAGE; 169 desktop_background_mode_ = BACKGROUND_IMAGE;
176 } 170 }
177 171
178 } // namespace ash 172 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698