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

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

Issue 16634016: Support png wallpapers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_cycle_controller.h" 10 #include "ash/wm/window_cycle_controller.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 229
230 class WallpaperFunctionBase::WallpaperDecoder : public ImageDecoder::Delegate { 230 class WallpaperFunctionBase::WallpaperDecoder : public ImageDecoder::Delegate {
231 public: 231 public:
232 explicit WallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function) 232 explicit WallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function)
233 : function_(function) { 233 : function_(function) {
234 } 234 }
235 235
236 void Start(const std::string& image_data) { 236 void Start(const std::string& image_data) {
237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
238 image_decoder_ = new ImageDecoder(this, image_data, 238
239 ImageDecoder::ROBUST_JPEG_CODEC); 239 // This function can only be called after user login. It is fine to use
Nikita (slow) 2013/06/13 13:03:33 Please place CHECK here that like CHECK(chromeos:
bshe 2013/06/14 18:12:18 Done.
240 // unsafe image deocder here. Before user login, a robust jpeg decoder will
241 // be used.
242 unsafe_image_decoder_ = new ImageDecoder(this, image_data,
243 ImageDecoder::DEFAULT_CODEC);
240 scoped_refptr<base::MessageLoopProxy> task_runner = 244 scoped_refptr<base::MessageLoopProxy> task_runner =
241 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); 245 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
242 image_decoder_->Start(task_runner); 246 unsafe_image_decoder_->Start(task_runner);
243 } 247 }
244 248
245 void Cancel() { 249 void Cancel() {
246 cancel_flag_.Set(); 250 cancel_flag_.Set();
247 } 251 }
248 252
249 virtual void OnImageDecoded(const ImageDecoder* decoder, 253 virtual void OnImageDecoded(const ImageDecoder* decoder,
250 const SkBitmap& decoded_image) OVERRIDE { 254 const SkBitmap& decoded_image) OVERRIDE {
251 // Make the SkBitmap immutable as we won't modify it. This is important 255 // Make the SkBitmap immutable as we won't modify it. This is important
252 // because otherwise it gets duplicated during painting, wasting memory. 256 // because otherwise it gets duplicated during painting, wasting memory.
(...skipping 12 matching lines...) Expand all
265 } 269 }
266 270
267 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE { 271 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE {
268 function_->OnFailureOrCancel( 272 function_->OnFailureOrCancel(
269 l10n_util::GetStringUTF8(IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER)); 273 l10n_util::GetStringUTF8(IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER));
270 delete this; 274 delete this;
271 } 275 }
272 276
273 private: 277 private:
274 scoped_refptr<WallpaperFunctionBase> function_; 278 scoped_refptr<WallpaperFunctionBase> function_;
275 scoped_refptr<ImageDecoder> image_decoder_; 279 scoped_refptr<ImageDecoder> unsafe_image_decoder_;
276 base::CancellationFlag cancel_flag_; 280 base::CancellationFlag cancel_flag_;
277 281
278 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder); 282 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder);
279 }; 283 };
280 284
281 WallpaperFunctionBase::WallpaperDecoder* 285 WallpaperFunctionBase::WallpaperDecoder*
282 WallpaperFunctionBase::wallpaper_decoder_; 286 WallpaperFunctionBase::wallpaper_decoder_;
283 287
284 WallpaperFunctionBase::WallpaperFunctionBase() { 288 WallpaperFunctionBase::WallpaperFunctionBase() {
285 } 289 }
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 this, email, source)); 878 this, email, source));
875 return true; 879 return true;
876 } 880 }
877 881
878 void WallpaperPrivateGetOfflineWallpaperListFunction::GetList( 882 void WallpaperPrivateGetOfflineWallpaperListFunction::GetList(
879 const std::string& email, 883 const std::string& email,
880 const std::string& source) { 884 const std::string& source) {
881 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( 885 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
882 sequence_token_)); 886 sequence_token_));
883 std::vector<std::string> file_list; 887 std::vector<std::string> file_list;
888 // TODO(bshe): This api function is only used for ONLINE wallpapers. Remove
889 // source.
884 if (source == kOnlineSource) { 890 if (source == kOnlineSource) {
885 base::FilePath wallpaper_dir; 891 base::FilePath wallpaper_dir;
886 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 892 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
887 if (file_util::DirectoryExists(wallpaper_dir)) { 893 if (file_util::DirectoryExists(wallpaper_dir)) {
888 file_util::FileEnumerator files(wallpaper_dir, false, 894 file_util::FileEnumerator files(wallpaper_dir, false,
889 file_util::FileEnumerator::FILES); 895 file_util::FileEnumerator::FILES);
890 for (base::FilePath current = files.Next(); !current.empty(); 896 for (base::FilePath current = files.Next(); !current.empty();
891 current = files.Next()) { 897 current = files.Next()) {
892 std::string file_name = current.BaseName().RemoveExtension().value(); 898 std::string file_name = current.BaseName().RemoveExtension().value();
893 // Do not add file name of small resolution wallpaper to the list. 899 // Do not add file name of small resolution wallpaper to the list.
894 if (!EndsWith(file_name, chromeos::kSmallWallpaperSuffix, true)) 900 if (!EndsWith(file_name, chromeos::kSmallWallpaperSuffix, true))
895 file_list.push_back(current.BaseName().value()); 901 file_list.push_back(current.BaseName().value());
896 } 902 }
897 } 903 }
898 } else {
899 base::FilePath custom_thumbnails_dir = chromeos::WallpaperManager::Get()->
900 GetCustomWallpaperPath(chromeos::kThumbnailWallpaperSubDir, email, "");
901 if (file_util::DirectoryExists(custom_thumbnails_dir)) {
902 file_util::FileEnumerator files(custom_thumbnails_dir, false,
903 file_util::FileEnumerator::FILES);
904 std::set<std::string> file_name_set;
905 for (base::FilePath current = files.Next(); !current.empty();
906 current = files.Next()) {
907 file_name_set.insert(current.BaseName().value());
908 }
909 for (std::set<std::string>::reverse_iterator rit = file_name_set.rbegin();
910 rit != file_name_set.rend(); ++rit) {
911 file_list.push_back(*rit);
912 }
913 }
914 } 904 }
915 BrowserThread::PostTask( 905 BrowserThread::PostTask(
916 BrowserThread::UI, FROM_HERE, 906 BrowserThread::UI, FROM_HERE,
917 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete, 907 base::Bind(&WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete,
918 this, file_list)); 908 this, file_list));
919 } 909 }
920 910
921 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( 911 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete(
922 const std::vector<std::string>& file_list) { 912 const std::vector<std::string>& file_list) {
923 ListValue* results = new ListValue(); 913 ListValue* results = new ListValue();
924 results->AppendStrings(file_list); 914 results->AppendStrings(file_list);
925 SetResult(results); 915 SetResult(results);
926 SendResponse(true); 916 SendResponse(true);
927 } 917 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698