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.
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_
8 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h"
10 #include "chrome/common/extensions/api/wallpaper_private.h"
11 #include "net/url_request/url_fetcher_delegate.h"
15 } // namespace chromeos
17 // Wallpaper manager strings.
18 class WallpaperPrivateGetStringsFunction : public SyncExtensionFunction {
20 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings",
21 WALLPAPERPRIVATE_GETSTRINGS)
24 virtual ~WallpaperPrivateGetStringsFunction() {}
26 // SyncExtensionFunction overrides.
27 virtual bool RunImpl() OVERRIDE;
30 class WallpaperPrivateSetWallpaperIfExistsFunction
31 : public WallpaperFunctionBase {
33 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExists",
34 WALLPAPERPRIVATE_SETWALLPAPERIFEXISTS)
36 WallpaperPrivateSetWallpaperIfExistsFunction();
39 virtual ~WallpaperPrivateSetWallpaperIfExistsFunction();
41 // AsyncExtensionFunction overrides.
42 virtual bool RunImpl() OVERRIDE;
45 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
47 // File doesn't exist. Sets javascript callback parameter to false.
48 void OnFileNotExists(const std::string& error);
50 // Reads file specified by |file_path|. If success, post a task to start
52 void ReadFileAndInitiateStartDecode(const base::FilePath& file_path,
53 const base::FilePath& fallback_path);
55 scoped_ptr<extensions::api::wallpaper_private::SetWallpaperIfExists::Params>
58 // User id of the active user when this api is been called.
61 // Sequence token associated with wallpaper operations. Shared with
63 base::SequencedWorkerPool::SequenceToken sequence_token_;
66 class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase {
68 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper",
69 WALLPAPERPRIVATE_SETWALLPAPER)
71 WallpaperPrivateSetWallpaperFunction();
74 virtual ~WallpaperPrivateSetWallpaperFunction();
76 // AsyncExtensionFunction overrides.
77 virtual bool RunImpl() OVERRIDE;
80 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
82 // Saves the image data to a file.
85 // Sets wallpaper to the decoded image.
86 void SetDecodedWallpaper(scoped_ptr<gfx::ImageSkia> wallpaper);
88 scoped_ptr<extensions::api::wallpaper_private::SetWallpaper::Params> params;
90 // The decoded wallpaper. It may accessed from UI thread to set wallpaper or
91 // FILE thread to resize and save wallpaper to disk.
92 gfx::ImageSkia wallpaper_;
94 // User id of the active user when this api is been called.
97 // Sequence token associated with wallpaper operations. Shared with
99 base::SequencedWorkerPool::SequenceToken sequence_token_;
102 class WallpaperPrivateResetWallpaperFunction
103 : public AsyncExtensionFunction {
105 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper",
106 WALLPAPERPRIVATE_RESETWALLPAPER)
108 WallpaperPrivateResetWallpaperFunction();
111 virtual ~WallpaperPrivateResetWallpaperFunction();
113 // AsyncExtensionFunction overrides.
114 virtual bool RunImpl() OVERRIDE;
117 class WallpaperPrivateSetCustomWallpaperFunction
118 : public WallpaperFunctionBase {
120 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper",
121 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER)
123 WallpaperPrivateSetCustomWallpaperFunction();
126 virtual ~WallpaperPrivateSetCustomWallpaperFunction();
128 // AsyncExtensionFunction overrides.
129 virtual bool RunImpl() OVERRIDE;
132 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
134 // Generates thumbnail of custom wallpaper. A simple STRETCH is used for
135 // generating thunbail.
136 void GenerateThumbnail(const base::FilePath& thumbnail_path,
137 scoped_ptr<gfx::ImageSkia> image);
139 // Thumbnail is ready. Calls api function javascript callback.
140 void ThumbnailGenerated(base::RefCountedBytes* data);
142 scoped_ptr<extensions::api::wallpaper_private::SetCustomWallpaper::Params>
145 // User id of the active user when this api is been called.
146 std::string user_id_;
148 // User id hash of the logged in user.
149 std::string user_id_hash_;
151 // Sequence token associated with wallpaper operations. Shared with
153 base::SequencedWorkerPool::SequenceToken sequence_token_;
156 class WallpaperPrivateSetCustomWallpaperLayoutFunction
157 : public AsyncExtensionFunction {
159 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout",
160 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT)
162 WallpaperPrivateSetCustomWallpaperLayoutFunction();
165 virtual ~WallpaperPrivateSetCustomWallpaperLayoutFunction();
167 // AsyncExtensionFunction overrides.
168 virtual bool RunImpl() OVERRIDE;
171 class WallpaperPrivateMinimizeInactiveWindowsFunction
172 : public AsyncExtensionFunction {
174 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows",
175 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS)
177 WallpaperPrivateMinimizeInactiveWindowsFunction();
180 virtual ~WallpaperPrivateMinimizeInactiveWindowsFunction();
182 // AsyncExtensionFunction overrides.
183 virtual bool RunImpl() OVERRIDE;
186 class WallpaperPrivateRestoreMinimizedWindowsFunction
187 : public AsyncExtensionFunction {
189 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows",
190 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS)
192 WallpaperPrivateRestoreMinimizedWindowsFunction();
195 virtual ~WallpaperPrivateRestoreMinimizedWindowsFunction();
197 // AsyncExtensionFunction overrides.
198 virtual bool RunImpl() OVERRIDE;
201 class WallpaperPrivateGetThumbnailFunction : public AsyncExtensionFunction {
203 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail",
204 WALLPAPERPRIVATE_GETTHUMBNAIL)
206 WallpaperPrivateGetThumbnailFunction();
209 virtual ~WallpaperPrivateGetThumbnailFunction();
211 // AsyncExtensionFunction overrides.
212 virtual bool RunImpl() OVERRIDE;
215 // Failed to get thumbnail for |file_name|.
216 void Failure(const std::string& file_name);
218 // Returns true to suppress javascript console error. Called when the
219 // requested thumbnail is not found or corrupted in thumbnail directory.
220 void FileNotLoaded();
222 // Sets data field to the loaded thumbnail binary data in the results. Called
223 // when requested wallpaper thumbnail loaded successfully.
224 void FileLoaded(const std::string& data);
226 // Gets thumbnail from |path|. If |path| does not exist, call FileNotLoaded().
227 void Get(const base::FilePath& path);
229 // Sequence token associated with wallpaper operations. Shared with
231 base::SequencedWorkerPool::SequenceToken sequence_token_;
234 class WallpaperPrivateSaveThumbnailFunction : public AsyncExtensionFunction {
236 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail",
237 WALLPAPERPRIVATE_SAVETHUMBNAIL)
239 WallpaperPrivateSaveThumbnailFunction();
242 virtual ~WallpaperPrivateSaveThumbnailFunction();
244 // AsyncExtensionFunction overrides.
245 virtual bool RunImpl() OVERRIDE;
248 // Failed to save thumbnail for |file_name|.
249 void Failure(const std::string& file_name);
251 // Saved thumbnail to thumbnail directory.
254 // Saves thumbnail to thumbnail directory as |file_name|.
255 void Save(const std::string& data, const std::string& file_name);
257 // Sequence token associated with wallpaper operations. Shared with
259 base::SequencedWorkerPool::SequenceToken sequence_token_;
262 class WallpaperPrivateGetOfflineWallpaperListFunction
263 : public AsyncExtensionFunction {
265 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList",
266 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST)
267 WallpaperPrivateGetOfflineWallpaperListFunction();
270 virtual ~WallpaperPrivateGetOfflineWallpaperListFunction();
272 // AsyncExtensionFunction overrides.
273 virtual bool RunImpl() OVERRIDE;
276 // Enumerates the list of files in online wallpaper directory.
279 // Sends the list of files to extension api caller. If no files or no
280 // directory, sends empty list.
281 void OnComplete(const std::vector<std::string>& file_list);
283 // Sequence token associated with wallpaper operations. Shared with
285 base::SequencedWorkerPool::SequenceToken sequence_token_;
288 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_