Index: chrome/browser/chromeos/login/wallpaper_loader.h |
diff --git a/chrome/browser/chromeos/login/wallpaper_loader.h b/chrome/browser/chromeos/login/wallpaper_loader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..532df1ed640523c7eee69ba2ae7d2e6a63b97040 |
--- /dev/null |
+++ b/chrome/browser/chromeos/login/wallpaper_loader.h |
@@ -0,0 +1,79 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_LOADER_H_ |
+#define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_LOADER_H_ |
+ |
+#include <map> |
+ |
+#include "base/callback.h" |
+#include "base/memory/ref_counted.h" |
+#include "chrome/browser/image_decoder.h" |
+ |
+class MessageLoop; |
+class SkBitmap; |
+ |
+namespace chromeos { |
+ |
+// Callback used to inidicate that wallpaper has been loaded. |
+typedef base::Callback<void(const SkBitmap& wallpaper)> LoadedCallback; |
+ |
+// A facility to read and decode a custom wallpaper asynchronously in the IO |
+// thread. Returns the image in the form of an SkBitmap. |
+class WallpaperLoader : public base::RefCountedThreadSafe<WallpaperLoader>, |
+ public ImageDecoder::Delegate { |
+ public: |
+ WallpaperLoader(); |
+ |
+ // Start reading the image from |filepath| on the file thread. Calls |
+ // |loaded_cb| when image has been successfully loaded. |
+ // If |save_raw_image| is true, save the loaded image to |save_to_path|. |
+ void Start(const std::string& filepath, |
+ bool save_raw_image, |
+ const std::string& save_to_path, |
+ const LoadedCallback& loaded_cb); |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<WallpaperLoader>; |
+ |
+ // Contains attributes we need to know about each wallpaper we decode. |
+ struct WallpaperInfo { |
+ WallpaperInfo(bool save_raw_image, |
+ const std::string& save_to_path, |
+ const LoadedCallback& loaded_cb); |
+ ~WallpaperInfo(); |
+ |
+ bool save_raw_image; |
+ std::string save_to_path; |
+ LoadedCallback loaded_cb; |
+ }; |
+ |
+ typedef std::map<const ImageDecoder*, WallpaperInfo> WallpaperInfoMap; |
+ |
+ virtual ~WallpaperLoader(); |
+ |
+ // Method that reads the file on the file thread and starts decoding it in |
+ // sandboxed process. |
+ void LoadImage(const std::string& filepath, |
+ const WallpaperInfo& wallpaper_info); |
+ |
+ // ImageDecoder::Delegate implementation. |
+ virtual void OnImageDecoded(const ImageDecoder* decoder, |
+ const SkBitmap& decoded_image) OVERRIDE; |
+ virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
+ |
+ // The message loop object of the thread in which we notify the delegate. |
+ MessageLoop* target_message_loop_; |
+ |
+ // Holds info structures about all wallpapers we're trying to decode. |
+ // Accessed only on FILE thread. |
+ WallpaperInfoMap wallpaper_info_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); |
+ |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_LOADER_H_ |