OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_LOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_LOADER_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/browser/image_decoder.h" |
| 13 |
| 14 class MessageLoop; |
| 15 class SkBitmap; |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 // Callback used to inidicate that wallpaper has been loaded. |
| 20 typedef base::Callback<void(const SkBitmap& wallpaper)> LoadedCallback; |
| 21 |
| 22 // A facility to read and decode a custom wallpaper asynchronously in the IO |
| 23 // thread. Returns the image in the form of an SkBitmap. |
| 24 class WallpaperLoader : public base::RefCountedThreadSafe<WallpaperLoader>, |
| 25 public ImageDecoder::Delegate { |
| 26 public: |
| 27 WallpaperLoader(); |
| 28 |
| 29 // Start reading the image from |filepath| on the file thread. Calls |
| 30 // |loaded_cb| when image has been successfully loaded. |
| 31 // If |save_raw_image| is true, save the loaded image to |save_to_path|. |
| 32 void Start(const std::string& filepath, |
| 33 bool save_raw_image, |
| 34 const std::string& save_to_path, |
| 35 const LoadedCallback& loaded_cb); |
| 36 |
| 37 private: |
| 38 friend class base::RefCountedThreadSafe<WallpaperLoader>; |
| 39 |
| 40 // Contains attributes we need to know about each wallpaper we decode. |
| 41 struct WallpaperInfo { |
| 42 WallpaperInfo(bool save_raw_image, |
| 43 const std::string& save_to_path, |
| 44 const LoadedCallback& loaded_cb); |
| 45 ~WallpaperInfo(); |
| 46 |
| 47 bool save_raw_image; |
| 48 std::string save_to_path; |
| 49 LoadedCallback loaded_cb; |
| 50 }; |
| 51 |
| 52 typedef std::map<const ImageDecoder*, WallpaperInfo> WallpaperInfoMap; |
| 53 |
| 54 virtual ~WallpaperLoader(); |
| 55 |
| 56 // Method that reads the file on the file thread and starts decoding it in |
| 57 // sandboxed process. |
| 58 void LoadImage(const std::string& filepath, |
| 59 const WallpaperInfo& wallpaper_info); |
| 60 |
| 61 // ImageDecoder::Delegate implementation. |
| 62 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 63 const SkBitmap& decoded_image) OVERRIDE; |
| 64 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 65 |
| 66 // The message loop object of the thread in which we notify the delegate. |
| 67 MessageLoop* target_message_loop_; |
| 68 |
| 69 // Holds info structures about all wallpapers we're trying to decode. |
| 70 // Accessed only on FILE thread. |
| 71 WallpaperInfoMap wallpaper_info_map_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); |
| 74 |
| 75 }; |
| 76 |
| 77 } // namespace chromeos |
| 78 |
| 79 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_LOADER_H_ |
OLD | NEW |