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

Side by Side Diff: chrome/browser/chromeos/extensions/wallpaper_private_api.cc

Issue 11092078: Add some error messages for setting wallpaper failures on Chrome(c++) side. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: nits Created 8 years, 2 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
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 "chrome/browser/chromeos/extensions/wallpaper_private_api.h" 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
6 6
7 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 void Cancel() { 93 void Cancel() {
94 cancel_flag_.Set(); 94 cancel_flag_.Set();
95 } 95 }
96 96
97 virtual void OnImageDecoded(const ImageDecoder* decoder, 97 virtual void OnImageDecoded(const ImageDecoder* decoder,
98 const SkBitmap& decoded_image) OVERRIDE { 98 const SkBitmap& decoded_image) OVERRIDE {
99 gfx::ImageSkia final_image(decoded_image); 99 gfx::ImageSkia final_image(decoded_image);
100 final_image.MakeThreadSafe(); 100 final_image.MakeThreadSafe();
101 if (cancel_flag_.IsSet()) { 101 if (cancel_flag_.IsSet()) {
102 function_->OnFailureOrCancel(); 102 function_->OnFailureOrCancel("Loading canceled");
Nikita (slow) 2012/10/15 15:14:11 I believe these should be taken from strings i.e.
bshe 2012/10/17 00:13:51 Pre discussion with kuscher, when wallpaper decodi
103 delete this; 103 delete this;
104 return; 104 return;
105 } 105 }
106 function_->OnWallpaperDecoded(final_image); 106 function_->OnWallpaperDecoded(final_image);
107 delete this; 107 delete this;
108 } 108 }
109 109
110 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE { 110 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE {
111 function_->OnFailureOrCancel(); 111 function_->OnFailureOrCancel("Loading failed");
bshe 2012/10/17 00:13:51 Changed to localized string.
112 // TODO(bshe): Dispatches an encoding error event.
113 delete this; 112 delete this;
114 } 113 }
115 114
116 private: 115 private:
117 scoped_refptr<WallpaperFunctionBase> function_; 116 scoped_refptr<WallpaperFunctionBase> function_;
118 scoped_refptr<ImageDecoder> image_decoder_; 117 scoped_refptr<ImageDecoder> image_decoder_;
119 base::CancellationFlag cancel_flag_; 118 base::CancellationFlag cancel_flag_;
120 119
121 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder); 120 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder);
122 }; 121 };
123 122
124 WallpaperFunctionBase::WallpaperDecoder* 123 WallpaperFunctionBase::WallpaperDecoder*
125 WallpaperFunctionBase::wallpaper_decoder_; 124 WallpaperFunctionBase::wallpaper_decoder_;
126 125
127 WallpaperFunctionBase::WallpaperFunctionBase() { 126 WallpaperFunctionBase::WallpaperFunctionBase() {
128 } 127 }
129 128
130 WallpaperFunctionBase::~WallpaperFunctionBase() { 129 WallpaperFunctionBase::~WallpaperFunctionBase() {
131 } 130 }
132 131
132 void WallpaperFunctionBase::OnFailureOrCancel(const std::string& error) {
133 wallpaper_decoder_ = NULL;
134 SetResult(Value::CreateStringValue(error));
135 SendResponse(false);
136 }
137
133 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { 138 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() {
134 } 139 }
135 140
136 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { 141 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() {
137 } 142 }
138 143
139 bool WallpaperSetWallpaperFunction::RunImpl() { 144 bool WallpaperSetWallpaperFunction::RunImpl() {
140 BinaryValue* input = NULL; 145 BinaryValue* input = NULL;
141 if (args_ == NULL || !args_->GetBinary(0, &input)) { 146 if (args_ == NULL || !args_->GetBinary(0, &input)) {
142 return false; 147 return false;
(...skipping 22 matching lines...) Expand all
165 const gfx::ImageSkia& wallpaper) { 170 const gfx::ImageSkia& wallpaper) {
166 wallpaper_ = wallpaper; 171 wallpaper_ = wallpaper;
167 // Set wallpaper_decoder_ to null since the decoding already finished. 172 // Set wallpaper_decoder_ to null since the decoding already finished.
168 wallpaper_decoder_ = NULL; 173 wallpaper_decoder_ = NULL;
169 BrowserThread::PostTask( 174 BrowserThread::PostTask(
170 BrowserThread::FILE, FROM_HERE, 175 BrowserThread::FILE, FROM_HERE,
171 base::Bind(&WallpaperSetWallpaperFunction::SaveToFile, 176 base::Bind(&WallpaperSetWallpaperFunction::SaveToFile,
172 this)); 177 this));
173 } 178 }
174 179
175 void WallpaperSetWallpaperFunction::OnFailureOrCancel() {
176 wallpaper_decoder_ = NULL;
177 SendResponse(false);
178 }
179
180 void WallpaperSetWallpaperFunction::SaveToFile() { 180 void WallpaperSetWallpaperFunction::SaveToFile() {
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
182 FilePath wallpaper_dir; 182 FilePath wallpaper_dir;
183 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 183 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
184 if (!file_util::DirectoryExists(wallpaper_dir) && 184 if (!file_util::DirectoryExists(wallpaper_dir) &&
185 !file_util::CreateDirectory(wallpaper_dir)) { 185 !file_util::CreateDirectory(wallpaper_dir)) {
186 BrowserThread::PostTask( 186 BrowserThread::PostTask(
187 BrowserThread::UI, FROM_HERE, 187 BrowserThread::UI, FROM_HERE,
188 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, 188 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel,
189 this)); 189 this, "Failed to create directory"));
bshe 2012/10/17 00:13:51 Pre discussion with kuscher, this case should be r
190 return; 190 return;
191 } 191 }
192 std::string file_name = GURL(url_).ExtractFileName(); 192 std::string file_name = GURL(url_).ExtractFileName();
193 FilePath file_path = wallpaper_dir.Append(file_name); 193 FilePath file_path = wallpaper_dir.Append(file_name);
194 if (file_util::PathExists(file_path) || 194 if (file_util::PathExists(file_path) ||
195 file_util::WriteFile(file_path, image_data_.c_str(), 195 file_util::WriteFile(file_path, image_data_.c_str(),
196 image_data_.size()) != -1 ) { 196 image_data_.size()) != -1 ) {
197 BrowserThread::PostTask( 197 BrowserThread::PostTask(
198 BrowserThread::UI, FROM_HERE, 198 BrowserThread::UI, FROM_HERE,
199 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper, 199 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper,
200 this)); 200 this));
201 chromeos::UserImage wallpaper(wallpaper_); 201 chromeos::UserImage wallpaper(wallpaper_);
202 202
203 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to 203 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to
204 // maintain the aspect ratio after resize. 204 // maintain the aspect ratio after resize.
205 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( 205 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
206 wallpaper, 206 wallpaper,
207 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix), 207 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix),
208 ash::CENTER_CROPPED, 208 ash::CENTER_CROPPED,
209 ash::kSmallWallpaperMaxWidth, 209 ash::kSmallWallpaperMaxWidth,
210 ash::kSmallWallpaperMaxHeight); 210 ash::kSmallWallpaperMaxHeight);
211 } else { 211 } else {
212 BrowserThread::PostTask( 212 BrowserThread::PostTask(
213 BrowserThread::UI, FROM_HERE, 213 BrowserThread::UI, FROM_HERE,
214 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, 214 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel,
215 this)); 215 this, "Failed to save downloaded wallpaper"));
216 } 216 }
217 } 217 }
218 218
219 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() { 219 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() {
220 chromeos::WallpaperManager* wallpaper_manager = 220 chromeos::WallpaperManager* wallpaper_manager =
221 chromeos::WallpaperManager::Get(); 221 chromeos::WallpaperManager::Get();
222 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_); 222 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_);
223 bool is_persistent = 223 bool is_persistent =
224 !chromeos::UserManager::Get()->IsCurrentUserEphemeral(); 224 !chromeos::UserManager::Get()->IsCurrentUserEphemeral();
225 chromeos::WallpaperInfo info = { 225 chromeos::WallpaperInfo info = {
226 url_, 226 url_,
227 layout_, 227 layout_,
228 chromeos::User::ONLINE, 228 chromeos::User::ONLINE,
229 base::Time::Now().LocalMidnight() 229 base::Time::Now().LocalMidnight()
230 }; 230 };
231 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent); 231 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent);
232 SetResult(Value::CreateStringValue(""));
232 SendResponse(true); 233 SendResponse(true);
233 } 234 }
234 235
235 WallpaperSetCustomWallpaperFunction::WallpaperSetCustomWallpaperFunction() { 236 WallpaperSetCustomWallpaperFunction::WallpaperSetCustomWallpaperFunction() {
236 } 237 }
237 238
238 WallpaperSetCustomWallpaperFunction::~WallpaperSetCustomWallpaperFunction() { 239 WallpaperSetCustomWallpaperFunction::~WallpaperSetCustomWallpaperFunction() {
239 } 240 }
240 241
241 bool WallpaperSetCustomWallpaperFunction::RunImpl() { 242 bool WallpaperSetCustomWallpaperFunction::RunImpl() {
(...skipping 23 matching lines...) Expand all
265 const gfx::ImageSkia& wallpaper) { 266 const gfx::ImageSkia& wallpaper) {
266 chromeos::UserImage::RawImage raw_image(image_data_.begin(), 267 chromeos::UserImage::RawImage raw_image(image_data_.begin(),
267 image_data_.end()); 268 image_data_.end());
268 chromeos::UserImage image(wallpaper, raw_image); 269 chromeos::UserImage image(wallpaper, raw_image);
269 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate 270 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate
270 // to refresh thumbnail. Uses a null delegate here. 271 // to refresh thumbnail. Uses a null delegate here.
271 chromeos::WallpaperManager::Get()->SetCustomWallpaper( 272 chromeos::WallpaperManager::Get()->SetCustomWallpaper(
272 email_, layout_, chromeos::User::CUSTOMIZED, 273 email_, layout_, chromeos::User::CUSTOMIZED,
273 base::WeakPtr<chromeos::WallpaperDelegate>(), image); 274 base::WeakPtr<chromeos::WallpaperDelegate>(), image);
274 wallpaper_decoder_ = NULL; 275 wallpaper_decoder_ = NULL;
276 SetResult(Value::CreateStringValue(""));
275 SendResponse(true); 277 SendResponse(true);
276 } 278 }
277
278 void WallpaperSetCustomWallpaperFunction::OnFailureOrCancel() {
279 wallpaper_decoder_ = NULL;
280 SendResponse(false);
281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698