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_
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h"
13 #include "chrome/common/extensions/api/wallpaper_private.h"
14 #include "net/url_request/url_fetcher_delegate.h"
18 } // namespace chromeos
20 // Wallpaper manager strings.
21 class WallpaperPrivateGetStringsFunction
: public SyncExtensionFunction
{
23 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings",
24 WALLPAPERPRIVATE_GETSTRINGS
)
27 ~WallpaperPrivateGetStringsFunction() override
{}
29 // SyncExtensionFunction overrides.
30 bool RunSync() override
;
33 // Check if sync themes setting is enabled.
34 class WallpaperPrivateGetSyncSettingFunction
: public SyncExtensionFunction
{
36 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getSyncSetting",
37 WALLPAPERPRIVATE_GETSYNCSETTING
)
40 ~WallpaperPrivateGetSyncSettingFunction() override
{}
42 // SyncExtensionFunction overrides.
43 bool RunSync() override
;
46 class WallpaperPrivateSetWallpaperIfExistsFunction
47 : public WallpaperFunctionBase
{
49 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExists",
50 WALLPAPERPRIVATE_SETWALLPAPERIFEXISTS
)
52 WallpaperPrivateSetWallpaperIfExistsFunction();
55 ~WallpaperPrivateSetWallpaperIfExistsFunction() override
;
57 // AsyncExtensionFunction overrides.
58 bool RunAsync() override
;
61 void OnWallpaperDecoded(const gfx::ImageSkia
& image
) override
;
63 // File doesn't exist. Sets javascript callback parameter to false.
64 void OnFileNotExists(const std::string
& error
);
66 // Reads file specified by |file_path|. If success, post a task to start
68 void ReadFileAndInitiateStartDecode(const base::FilePath
& file_path
,
69 const base::FilePath
& fallback_path
);
71 scoped_ptr
<extensions::api::wallpaper_private::SetWallpaperIfExists::Params
>
74 // User id of the active user when this api is been called.
77 // Sequence token associated with wallpaper operations. Shared with
79 base::SequencedWorkerPool::SequenceToken sequence_token_
;
82 class WallpaperPrivateSetWallpaperFunction
: public WallpaperFunctionBase
{
84 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper",
85 WALLPAPERPRIVATE_SETWALLPAPER
)
87 WallpaperPrivateSetWallpaperFunction();
90 ~WallpaperPrivateSetWallpaperFunction() override
;
92 // AsyncExtensionFunction overrides.
93 bool RunAsync() override
;
96 void OnWallpaperDecoded(const gfx::ImageSkia
& image
) override
;
98 // Saves the image data to a file.
101 // Sets wallpaper to the decoded image.
102 void SetDecodedWallpaper(scoped_ptr
<gfx::ImageSkia
> image
);
104 scoped_ptr
<extensions::api::wallpaper_private::SetWallpaper::Params
> params
;
106 // The decoded wallpaper. It may accessed from UI thread to set wallpaper or
107 // FILE thread to resize and save wallpaper to disk.
108 gfx::ImageSkia wallpaper_
;
110 // User id of the active user when this api is been called.
111 std::string user_id_
;
113 // Sequence token associated with wallpaper operations. Shared with
115 base::SequencedWorkerPool::SequenceToken sequence_token_
;
118 class WallpaperPrivateResetWallpaperFunction
119 : public AsyncExtensionFunction
{
121 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper",
122 WALLPAPERPRIVATE_RESETWALLPAPER
)
124 WallpaperPrivateResetWallpaperFunction();
127 ~WallpaperPrivateResetWallpaperFunction() override
;
129 // AsyncExtensionFunction overrides.
130 bool RunAsync() override
;
133 class WallpaperPrivateSetCustomWallpaperFunction
134 : public WallpaperFunctionBase
{
136 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper",
137 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER
)
139 WallpaperPrivateSetCustomWallpaperFunction();
142 ~WallpaperPrivateSetCustomWallpaperFunction() override
;
144 // AsyncExtensionFunction overrides.
145 bool RunAsync() override
;
148 void OnWallpaperDecoded(const gfx::ImageSkia
& wallpaper
) override
;
150 // Generates thumbnail of custom wallpaper. A simple STRETCH is used for
151 // generating thunbail.
152 void GenerateThumbnail(const base::FilePath
& thumbnail_path
,
153 scoped_ptr
<gfx::ImageSkia
> image
);
155 // Thumbnail is ready. Calls api function javascript callback.
156 void ThumbnailGenerated(base::RefCountedBytes
* data
);
158 scoped_ptr
<extensions::api::wallpaper_private::SetCustomWallpaper::Params
>
161 // User id of the active user when this api is been called.
162 std::string user_id_
;
164 // User id hash of the logged in user.
165 std::string user_id_hash_
;
167 // Sequence token associated with wallpaper operations. Shared with
169 base::SequencedWorkerPool::SequenceToken sequence_token_
;
172 class WallpaperPrivateSetCustomWallpaperLayoutFunction
173 : public AsyncExtensionFunction
{
175 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout",
176 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT
)
178 WallpaperPrivateSetCustomWallpaperLayoutFunction();
181 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() override
;
183 // AsyncExtensionFunction overrides.
184 bool RunAsync() override
;
187 class WallpaperPrivateMinimizeInactiveWindowsFunction
188 : public AsyncExtensionFunction
{
190 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows",
191 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS
)
193 WallpaperPrivateMinimizeInactiveWindowsFunction();
196 ~WallpaperPrivateMinimizeInactiveWindowsFunction() override
;
198 // AsyncExtensionFunction overrides.
199 bool RunAsync() override
;
202 class WallpaperPrivateRestoreMinimizedWindowsFunction
203 : public AsyncExtensionFunction
{
205 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows",
206 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS
)
208 WallpaperPrivateRestoreMinimizedWindowsFunction();
211 ~WallpaperPrivateRestoreMinimizedWindowsFunction() override
;
213 // AsyncExtensionFunction overrides.
214 bool RunAsync() override
;
217 class WallpaperPrivateGetThumbnailFunction
: public AsyncExtensionFunction
{
219 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail",
220 WALLPAPERPRIVATE_GETTHUMBNAIL
)
222 WallpaperPrivateGetThumbnailFunction();
225 ~WallpaperPrivateGetThumbnailFunction() override
;
227 // AsyncExtensionFunction overrides.
228 bool RunAsync() override
;
231 // Failed to get thumbnail for |file_name|.
232 void Failure(const std::string
& file_name
);
234 // Returns true to suppress javascript console error. Called when the
235 // requested thumbnail is not found or corrupted in thumbnail directory.
236 void FileNotLoaded();
238 // Sets data field to the loaded thumbnail binary data in the results. Called
239 // when requested wallpaper thumbnail loaded successfully.
240 void FileLoaded(const std::string
& data
);
242 // Gets thumbnail from |path|. If |path| does not exist, call FileNotLoaded().
243 void Get(const base::FilePath
& path
);
245 // Sequence token associated with wallpaper operations. Shared with
247 base::SequencedWorkerPool::SequenceToken sequence_token_
;
250 class WallpaperPrivateSaveThumbnailFunction
: public AsyncExtensionFunction
{
252 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail",
253 WALLPAPERPRIVATE_SAVETHUMBNAIL
)
255 WallpaperPrivateSaveThumbnailFunction();
258 ~WallpaperPrivateSaveThumbnailFunction() override
;
260 // AsyncExtensionFunction overrides.
261 bool RunAsync() override
;
264 // Failed to save thumbnail for |file_name|.
265 void Failure(const std::string
& file_name
);
267 // Saved thumbnail to thumbnail directory.
270 // Saves thumbnail to thumbnail directory as |file_name|.
271 void Save(const std::vector
<char>& data
, const std::string
& file_name
);
273 // Sequence token associated with wallpaper operations. Shared with
275 base::SequencedWorkerPool::SequenceToken sequence_token_
;
278 class WallpaperPrivateGetOfflineWallpaperListFunction
279 : public AsyncExtensionFunction
{
281 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList",
282 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST
)
283 WallpaperPrivateGetOfflineWallpaperListFunction();
286 ~WallpaperPrivateGetOfflineWallpaperListFunction() override
;
288 // AsyncExtensionFunction overrides.
289 bool RunAsync() override
;
292 // Enumerates the list of files in online wallpaper directory.
295 // Sends the list of files to extension api caller. If no files or no
296 // directory, sends empty list.
297 void OnComplete(const std::vector
<std::string
>& file_list
);
299 // Sequence token associated with wallpaper operations. Shared with
301 base::SequencedWorkerPool::SequenceToken sequence_token_
;
304 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_