Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / wallpaper_private_api.h
blob71cfcba168b62888cb2bef7626f0303fb2bea359
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 <string>
9 #include <vector>
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"
16 namespace chromeos {
17 class UserImage;
18 } // namespace chromeos
20 // Wallpaper manager strings.
21 class WallpaperPrivateGetStringsFunction : public SyncExtensionFunction {
22 public:
23 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings",
24 WALLPAPERPRIVATE_GETSTRINGS)
26 protected:
27 ~WallpaperPrivateGetStringsFunction() override {}
29 // SyncExtensionFunction overrides.
30 bool RunSync() override;
33 // Check if sync themes setting is enabled.
34 class WallpaperPrivateGetSyncSettingFunction : public SyncExtensionFunction {
35 public:
36 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getSyncSetting",
37 WALLPAPERPRIVATE_GETSYNCSETTING)
39 protected:
40 ~WallpaperPrivateGetSyncSettingFunction() override {}
42 // SyncExtensionFunction overrides.
43 bool RunSync() override;
46 class WallpaperPrivateSetWallpaperIfExistsFunction
47 : public WallpaperFunctionBase {
48 public:
49 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExists",
50 WALLPAPERPRIVATE_SETWALLPAPERIFEXISTS)
52 WallpaperPrivateSetWallpaperIfExistsFunction();
54 protected:
55 ~WallpaperPrivateSetWallpaperIfExistsFunction() override;
57 // AsyncExtensionFunction overrides.
58 bool RunAsync() override;
60 private:
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
67 // decoding the file.
68 void ReadFileAndInitiateStartDecode(const base::FilePath& file_path,
69 const base::FilePath& fallback_path);
71 scoped_ptr<extensions::api::wallpaper_private::SetWallpaperIfExists::Params>
72 params;
74 // User id of the active user when this api is been called.
75 std::string user_id_;
77 // Sequence token associated with wallpaper operations. Shared with
78 // WallpaperManager.
79 base::SequencedWorkerPool::SequenceToken sequence_token_;
82 class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase {
83 public:
84 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper",
85 WALLPAPERPRIVATE_SETWALLPAPER)
87 WallpaperPrivateSetWallpaperFunction();
89 protected:
90 ~WallpaperPrivateSetWallpaperFunction() override;
92 // AsyncExtensionFunction overrides.
93 bool RunAsync() override;
95 private:
96 void OnWallpaperDecoded(const gfx::ImageSkia& image) override;
98 // Saves the image data to a file.
99 void SaveToFile();
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
114 // WallpaperManager.
115 base::SequencedWorkerPool::SequenceToken sequence_token_;
118 class WallpaperPrivateResetWallpaperFunction
119 : public AsyncExtensionFunction {
120 public:
121 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper",
122 WALLPAPERPRIVATE_RESETWALLPAPER)
124 WallpaperPrivateResetWallpaperFunction();
126 protected:
127 ~WallpaperPrivateResetWallpaperFunction() override;
129 // AsyncExtensionFunction overrides.
130 bool RunAsync() override;
133 class WallpaperPrivateSetCustomWallpaperFunction
134 : public WallpaperFunctionBase {
135 public:
136 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper",
137 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER)
139 WallpaperPrivateSetCustomWallpaperFunction();
141 protected:
142 ~WallpaperPrivateSetCustomWallpaperFunction() override;
144 // AsyncExtensionFunction overrides.
145 bool RunAsync() override;
147 private:
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>
159 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
168 // WallpaperManager.
169 base::SequencedWorkerPool::SequenceToken sequence_token_;
172 class WallpaperPrivateSetCustomWallpaperLayoutFunction
173 : public AsyncExtensionFunction {
174 public:
175 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout",
176 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT)
178 WallpaperPrivateSetCustomWallpaperLayoutFunction();
180 protected:
181 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() override;
183 // AsyncExtensionFunction overrides.
184 bool RunAsync() override;
187 class WallpaperPrivateMinimizeInactiveWindowsFunction
188 : public AsyncExtensionFunction {
189 public:
190 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows",
191 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS)
193 WallpaperPrivateMinimizeInactiveWindowsFunction();
195 protected:
196 ~WallpaperPrivateMinimizeInactiveWindowsFunction() override;
198 // AsyncExtensionFunction overrides.
199 bool RunAsync() override;
202 class WallpaperPrivateRestoreMinimizedWindowsFunction
203 : public AsyncExtensionFunction {
204 public:
205 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows",
206 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS)
208 WallpaperPrivateRestoreMinimizedWindowsFunction();
210 protected:
211 ~WallpaperPrivateRestoreMinimizedWindowsFunction() override;
213 // AsyncExtensionFunction overrides.
214 bool RunAsync() override;
217 class WallpaperPrivateGetThumbnailFunction : public AsyncExtensionFunction {
218 public:
219 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail",
220 WALLPAPERPRIVATE_GETTHUMBNAIL)
222 WallpaperPrivateGetThumbnailFunction();
224 protected:
225 ~WallpaperPrivateGetThumbnailFunction() override;
227 // AsyncExtensionFunction overrides.
228 bool RunAsync() override;
230 private:
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
246 // WallpaperManager.
247 base::SequencedWorkerPool::SequenceToken sequence_token_;
250 class WallpaperPrivateSaveThumbnailFunction : public AsyncExtensionFunction {
251 public:
252 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail",
253 WALLPAPERPRIVATE_SAVETHUMBNAIL)
255 WallpaperPrivateSaveThumbnailFunction();
257 protected:
258 ~WallpaperPrivateSaveThumbnailFunction() override;
260 // AsyncExtensionFunction overrides.
261 bool RunAsync() override;
263 private:
264 // Failed to save thumbnail for |file_name|.
265 void Failure(const std::string& file_name);
267 // Saved thumbnail to thumbnail directory.
268 void Success();
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
274 // WallpaperManager.
275 base::SequencedWorkerPool::SequenceToken sequence_token_;
278 class WallpaperPrivateGetOfflineWallpaperListFunction
279 : public AsyncExtensionFunction {
280 public:
281 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList",
282 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST)
283 WallpaperPrivateGetOfflineWallpaperListFunction();
285 protected:
286 ~WallpaperPrivateGetOfflineWallpaperListFunction() override;
288 // AsyncExtensionFunction overrides.
289 bool RunAsync() override;
291 private:
292 // Enumerates the list of files in online wallpaper directory.
293 void GetList();
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
300 // WallpaperManager.
301 base::SequencedWorkerPool::SequenceToken sequence_token_;
304 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_