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"
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 // Sequence token associated with wallpaper operations. Shared with
60 base::SequencedWorkerPool::SequenceToken sequence_token_;
63 class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase {
65 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper",
66 WALLPAPERPRIVATE_SETWALLPAPER)
68 WallpaperPrivateSetWallpaperFunction();
71 virtual ~WallpaperPrivateSetWallpaperFunction();
73 // AsyncExtensionFunction overrides.
74 virtual bool RunImpl() OVERRIDE;
77 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
79 // Saves the image data to a file.
82 // Sets wallpaper to the decoded image.
83 void SetDecodedWallpaper(scoped_ptr<gfx::ImageSkia> wallpaper);
85 scoped_ptr<extensions::api::wallpaper_private::SetWallpaper::Params> params;
87 // The decoded wallpaper. It may accessed from UI thread to set wallpaper or
88 // FILE thread to resize and save wallpaper to disk.
89 gfx::ImageSkia wallpaper_;
91 // Email address of logged in user.
94 // Sequence token associated with wallpaper operations. Shared with
96 base::SequencedWorkerPool::SequenceToken sequence_token_;
99 class WallpaperPrivateResetWallpaperFunction
100 : public AsyncExtensionFunction {
102 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper",
103 WALLPAPERPRIVATE_RESETWALLPAPER)
105 WallpaperPrivateResetWallpaperFunction();
108 virtual ~WallpaperPrivateResetWallpaperFunction();
110 // AsyncExtensionFunction overrides.
111 virtual bool RunImpl() OVERRIDE;
114 class WallpaperPrivateSetCustomWallpaperFunction
115 : public WallpaperFunctionBase {
117 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper",
118 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER)
120 WallpaperPrivateSetCustomWallpaperFunction();
123 virtual ~WallpaperPrivateSetCustomWallpaperFunction();
125 // AsyncExtensionFunction overrides.
126 virtual bool RunImpl() OVERRIDE;
129 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE;
131 // Generates thumbnail of custom wallpaper. A simple STRETCH is used for
132 // generating thunbail.
133 void GenerateThumbnail(const base::FilePath& thumbnail_path,
134 scoped_ptr<gfx::ImageSkia> image);
136 // Thumbnail is ready. Calls api function javascript callback.
137 void ThumbnailGenerated(base::RefCountedBytes* data);
139 scoped_ptr<extensions::api::wallpaper_private::SetCustomWallpaper::Params>
142 // Email address of logged in user.
145 // User id hash of the logged in user.
146 std::string user_id_hash_;
148 // Sequence token associated with wallpaper operations. Shared with
150 base::SequencedWorkerPool::SequenceToken sequence_token_;
153 class WallpaperPrivateSetCustomWallpaperLayoutFunction
154 : public AsyncExtensionFunction {
156 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout",
157 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT)
159 WallpaperPrivateSetCustomWallpaperLayoutFunction();
162 virtual ~WallpaperPrivateSetCustomWallpaperLayoutFunction();
164 // AsyncExtensionFunction overrides.
165 virtual bool RunImpl() OVERRIDE;
168 class WallpaperPrivateMinimizeInactiveWindowsFunction
169 : public AsyncExtensionFunction {
171 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows",
172 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS)
174 WallpaperPrivateMinimizeInactiveWindowsFunction();
177 virtual ~WallpaperPrivateMinimizeInactiveWindowsFunction();
179 // AsyncExtensionFunction overrides.
180 virtual bool RunImpl() OVERRIDE;
183 class WallpaperPrivateRestoreMinimizedWindowsFunction
184 : public AsyncExtensionFunction {
186 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows",
187 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS)
189 WallpaperPrivateRestoreMinimizedWindowsFunction();
192 virtual ~WallpaperPrivateRestoreMinimizedWindowsFunction();
194 // AsyncExtensionFunction overrides.
195 virtual bool RunImpl() OVERRIDE;
198 class WallpaperPrivateGetThumbnailFunction : public AsyncExtensionFunction {
200 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail",
201 WALLPAPERPRIVATE_GETTHUMBNAIL)
203 WallpaperPrivateGetThumbnailFunction();
206 virtual ~WallpaperPrivateGetThumbnailFunction();
208 // AsyncExtensionFunction overrides.
209 virtual bool RunImpl() OVERRIDE;
212 // Failed to get thumbnail for |file_name|.
213 void Failure(const std::string& file_name);
215 // Returns true to suppress javascript console error. Called when the
216 // requested thumbnail is not found or corrupted in thumbnail directory.
217 void FileNotLoaded();
219 // Sets data field to the loaded thumbnail binary data in the results. Called
220 // when requested wallpaper thumbnail loaded successfully.
221 void FileLoaded(const std::string& data);
223 // Gets thumbnail from |path|. If |path| does not exist, call FileNotLoaded().
224 void Get(const base::FilePath& path);
226 // Sequence token associated with wallpaper operations. Shared with
228 base::SequencedWorkerPool::SequenceToken sequence_token_;
231 class WallpaperPrivateSaveThumbnailFunction : public AsyncExtensionFunction {
233 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail",
234 WALLPAPERPRIVATE_SAVETHUMBNAIL)
236 WallpaperPrivateSaveThumbnailFunction();
239 virtual ~WallpaperPrivateSaveThumbnailFunction();
241 // AsyncExtensionFunction overrides.
242 virtual bool RunImpl() OVERRIDE;
245 // Failed to save thumbnail for |file_name|.
246 void Failure(const std::string& file_name);
248 // Saved thumbnail to thumbnail directory.
251 // Saves thumbnail to thumbnail directory as |file_name|.
252 void Save(const std::string& data, const std::string& file_name);
254 // Sequence token associated with wallpaper operations. Shared with
256 base::SequencedWorkerPool::SequenceToken sequence_token_;
259 class WallpaperPrivateGetOfflineWallpaperListFunction
260 : public AsyncExtensionFunction {
262 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList",
263 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST)
264 WallpaperPrivateGetOfflineWallpaperListFunction();
267 virtual ~WallpaperPrivateGetOfflineWallpaperListFunction();
269 // AsyncExtensionFunction overrides.
270 virtual bool RunImpl() OVERRIDE;
273 // Enumerates the list of files in online wallpaper directory.
276 // Sends the list of files to extension api caller. If no files or no
277 // directory, sends empty list.
278 void OnComplete(const std::vector<std::string>& file_list);
280 // Sequence token associated with wallpaper operations. Shared with
282 base::SequencedWorkerPool::SequenceToken sequence_token_;
285 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_