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

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: Using localized string 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 void Cancel() { 95 void Cancel() {
96 cancel_flag_.Set(); 96 cancel_flag_.Set();
97 } 97 }
98 98
99 virtual void OnImageDecoded(const ImageDecoder* decoder, 99 virtual void OnImageDecoded(const ImageDecoder* decoder,
100 const SkBitmap& decoded_image) OVERRIDE { 100 const SkBitmap& decoded_image) OVERRIDE {
101 gfx::ImageSkia final_image(decoded_image); 101 gfx::ImageSkia final_image(decoded_image);
102 final_image.MakeThreadSafe(); 102 final_image.MakeThreadSafe();
103 if (cancel_flag_.IsSet()) { 103 if (cancel_flag_.IsSet()) {
104 function_->OnFailureOrCancel(); 104 function_->OnFailureOrCancel("");
105 delete this; 105 delete this;
106 return; 106 return;
107 } 107 }
108 function_->OnWallpaperDecoded(final_image); 108 function_->OnWallpaperDecoded(final_image);
109 delete this; 109 delete this;
110 } 110 }
111 111
112 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE { 112 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE {
113 function_->OnFailureOrCancel(); 113 function_->OnFailureOrCancel(
114 // TODO(bshe): Dispatches an encoding error event. 114 l10n_util::GetStringUTF8(IDS_WALLPAPER_MANAGER_INVALID_FORMAT));
115 delete this; 115 delete this;
116 } 116 }
117 117
118 private: 118 private:
119 scoped_refptr<WallpaperFunctionBase> function_; 119 scoped_refptr<WallpaperFunctionBase> function_;
120 scoped_refptr<ImageDecoder> image_decoder_; 120 scoped_refptr<ImageDecoder> image_decoder_;
121 base::CancellationFlag cancel_flag_; 121 base::CancellationFlag cancel_flag_;
122 122
123 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder); 123 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder);
124 }; 124 };
125 125
126 WallpaperFunctionBase::WallpaperDecoder* 126 WallpaperFunctionBase::WallpaperDecoder*
127 WallpaperFunctionBase::wallpaper_decoder_; 127 WallpaperFunctionBase::wallpaper_decoder_;
128 128
129 WallpaperFunctionBase::WallpaperFunctionBase() { 129 WallpaperFunctionBase::WallpaperFunctionBase() {
130 } 130 }
131 131
132 WallpaperFunctionBase::~WallpaperFunctionBase() { 132 WallpaperFunctionBase::~WallpaperFunctionBase() {
133 } 133 }
134 134
135 void WallpaperFunctionBase::OnFailureOrCancel(const std::string& error) {
136 wallpaper_decoder_ = NULL;
137 SetResult(Value::CreateStringValue(error));
Mihai Parparita -not on Chrome 2012/10/18 00:30:54 The more idiomatic (with other APIs) way of doing
bshe 2012/10/18 17:34:59 I made the change and use SetError as you suggeste
138 SendResponse(false);
139 }
140
135 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { 141 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() {
136 } 142 }
137 143
138 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { 144 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() {
139 } 145 }
140 146
141 bool WallpaperSetWallpaperFunction::RunImpl() { 147 bool WallpaperSetWallpaperFunction::RunImpl() {
142 BinaryValue* input = NULL; 148 BinaryValue* input = NULL;
143 if (args_ == NULL || !args_->GetBinary(0, &input)) { 149 if (args_ == NULL || !args_->GetBinary(0, &input)) {
144 return false; 150 return false;
(...skipping 22 matching lines...) Expand all
167 const gfx::ImageSkia& wallpaper) { 173 const gfx::ImageSkia& wallpaper) {
168 wallpaper_ = wallpaper; 174 wallpaper_ = wallpaper;
169 // Set wallpaper_decoder_ to null since the decoding already finished. 175 // Set wallpaper_decoder_ to null since the decoding already finished.
170 wallpaper_decoder_ = NULL; 176 wallpaper_decoder_ = NULL;
171 BrowserThread::PostTask( 177 BrowserThread::PostTask(
172 BrowserThread::FILE, FROM_HERE, 178 BrowserThread::FILE, FROM_HERE,
173 base::Bind(&WallpaperSetWallpaperFunction::SaveToFile, 179 base::Bind(&WallpaperSetWallpaperFunction::SaveToFile,
174 this)); 180 this));
175 } 181 }
176 182
177 void WallpaperSetWallpaperFunction::OnFailureOrCancel() {
178 wallpaper_decoder_ = NULL;
179 SendResponse(false);
180 }
181
182 void WallpaperSetWallpaperFunction::SaveToFile() { 183 void WallpaperSetWallpaperFunction::SaveToFile() {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
184 FilePath wallpaper_dir; 185 FilePath wallpaper_dir;
185 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 186 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
186 if (!file_util::DirectoryExists(wallpaper_dir) && 187 if (!file_util::DirectoryExists(wallpaper_dir) &&
187 !file_util::CreateDirectory(wallpaper_dir)) { 188 !file_util::CreateDirectory(wallpaper_dir)) {
188 BrowserThread::PostTask( 189 BrowserThread::PostTask(
189 BrowserThread::UI, FROM_HERE, 190 BrowserThread::UI, FROM_HERE,
190 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, 191 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel,
191 this)); 192 this, ""));
193 LOG(ERROR) << "Failed to create wallpaper directory.";
192 return; 194 return;
193 } 195 }
194 std::string file_name = GURL(url_).ExtractFileName(); 196 std::string file_name = GURL(url_).ExtractFileName();
195 FilePath file_path = wallpaper_dir.Append(file_name); 197 FilePath file_path = wallpaper_dir.Append(file_name);
196 if (file_util::PathExists(file_path) || 198 if (file_util::PathExists(file_path) ||
197 file_util::WriteFile(file_path, image_data_.c_str(), 199 file_util::WriteFile(file_path, image_data_.c_str(),
198 image_data_.size()) != -1 ) { 200 image_data_.size()) != -1 ) {
199 BrowserThread::PostTask( 201 BrowserThread::PostTask(
200 BrowserThread::UI, FROM_HERE, 202 BrowserThread::UI, FROM_HERE,
201 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper, 203 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper,
202 this)); 204 this));
203 chromeos::UserImage wallpaper(wallpaper_); 205 chromeos::UserImage wallpaper(wallpaper_);
204 206
205 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to 207 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to
206 // maintain the aspect ratio after resize. 208 // maintain the aspect ratio after resize.
207 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( 209 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
208 wallpaper, 210 wallpaper,
209 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix), 211 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix),
210 ash::CENTER_CROPPED, 212 ash::CENTER_CROPPED,
211 ash::kSmallWallpaperMaxWidth, 213 ash::kSmallWallpaperMaxWidth,
212 ash::kSmallWallpaperMaxHeight); 214 ash::kSmallWallpaperMaxHeight);
213 } else { 215 } else {
214 BrowserThread::PostTask( 216 BrowserThread::PostTask(
215 BrowserThread::UI, FROM_HERE, 217 BrowserThread::UI, FROM_HERE,
216 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, 218 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel,
217 this)); 219 this, ""));
220 LOG(ERROR) << "Failed to save downloaded wallpaper.";
218 } 221 }
219 } 222 }
220 223
221 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() { 224 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() {
222 chromeos::WallpaperManager* wallpaper_manager = 225 chromeos::WallpaperManager* wallpaper_manager =
223 chromeos::WallpaperManager::Get(); 226 chromeos::WallpaperManager::Get();
224 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_); 227 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_);
225 bool is_persistent = 228 bool is_persistent =
226 !chromeos::UserManager::Get()->IsCurrentUserEphemeral(); 229 !chromeos::UserManager::Get()->IsCurrentUserEphemeral();
227 chromeos::WallpaperInfo info = { 230 chromeos::WallpaperInfo info = {
228 url_, 231 url_,
229 layout_, 232 layout_,
230 chromeos::User::ONLINE, 233 chromeos::User::ONLINE,
231 base::Time::Now().LocalMidnight() 234 base::Time::Now().LocalMidnight()
232 }; 235 };
233 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent); 236 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent);
237 SetResult(Value::CreateStringValue(""));
234 SendResponse(true); 238 SendResponse(true);
235 } 239 }
236 240
237 WallpaperSetCustomWallpaperFunction::WallpaperSetCustomWallpaperFunction() { 241 WallpaperSetCustomWallpaperFunction::WallpaperSetCustomWallpaperFunction() {
238 } 242 }
239 243
240 WallpaperSetCustomWallpaperFunction::~WallpaperSetCustomWallpaperFunction() { 244 WallpaperSetCustomWallpaperFunction::~WallpaperSetCustomWallpaperFunction() {
241 } 245 }
242 246
243 bool WallpaperSetCustomWallpaperFunction::RunImpl() { 247 bool WallpaperSetCustomWallpaperFunction::RunImpl() {
(...skipping 23 matching lines...) Expand all
267 const gfx::ImageSkia& wallpaper) { 271 const gfx::ImageSkia& wallpaper) {
268 chromeos::UserImage::RawImage raw_image(image_data_.begin(), 272 chromeos::UserImage::RawImage raw_image(image_data_.begin(),
269 image_data_.end()); 273 image_data_.end());
270 chromeos::UserImage image(wallpaper, raw_image); 274 chromeos::UserImage image(wallpaper, raw_image);
271 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate 275 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate
272 // to refresh thumbnail. Uses a null delegate here. 276 // to refresh thumbnail. Uses a null delegate here.
273 chromeos::WallpaperManager::Get()->SetCustomWallpaper( 277 chromeos::WallpaperManager::Get()->SetCustomWallpaper(
274 email_, layout_, chromeos::User::CUSTOMIZED, 278 email_, layout_, chromeos::User::CUSTOMIZED,
275 base::WeakPtr<chromeos::WallpaperDelegate>(), image); 279 base::WeakPtr<chromeos::WallpaperDelegate>(), image);
276 wallpaper_decoder_ = NULL; 280 wallpaper_decoder_ = NULL;
281 SetResult(Value::CreateStringValue(""));
277 SendResponse(true); 282 SendResponse(true);
278 } 283 }
279
280 void WallpaperSetCustomWallpaperFunction::OnFailureOrCancel() {
281 wallpaper_decoder_ = NULL;
282 SendResponse(false);
283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698