| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| 7 | 7 |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" | 9 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" |
| 10 #include "chrome/common/extensions/api/wallpaper_private.h" | 10 #include "chrome/common/extensions/api/wallpaper_private.h" |
| 11 #include "net/url_request/url_fetcher_delegate.h" | 11 #include "net/url_request/url_fetcher_delegate.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 class UserImage; | 14 class UserImage; |
| 15 } // namespace chromeos | 15 } // namespace chromeos |
| 16 | 16 |
| 17 // Wallpaper manager strings. | 17 // Wallpaper manager strings. |
| 18 class WallpaperPrivateGetStringsFunction : public SyncExtensionFunction { | 18 class WallpaperPrivateGetStringsFunction : public SyncExtensionFunction { |
| 19 public: | 19 public: |
| 20 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings", | 20 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings", |
| 21 WALLPAPERPRIVATE_GETSTRINGS) | 21 WALLPAPERPRIVATE_GETSTRINGS) |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 virtual ~WallpaperPrivateGetStringsFunction() {} | 24 virtual ~WallpaperPrivateGetStringsFunction() {} |
| 25 | 25 |
| 26 // SyncExtensionFunction overrides. | 26 // SyncExtensionFunction overrides. |
| 27 virtual bool RunImpl() OVERRIDE; | 27 virtual bool RunSync() OVERRIDE; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 class WallpaperPrivateSetWallpaperIfExistsFunction | 30 class WallpaperPrivateSetWallpaperIfExistsFunction |
| 31 : public WallpaperFunctionBase { | 31 : public WallpaperFunctionBase { |
| 32 public: | 32 public: |
| 33 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExists", | 33 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExists", |
| 34 WALLPAPERPRIVATE_SETWALLPAPERIFEXISTS) | 34 WALLPAPERPRIVATE_SETWALLPAPERIFEXISTS) |
| 35 | 35 |
| 36 WallpaperPrivateSetWallpaperIfExistsFunction(); | 36 WallpaperPrivateSetWallpaperIfExistsFunction(); |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 virtual ~WallpaperPrivateSetWallpaperIfExistsFunction(); | 39 virtual ~WallpaperPrivateSetWallpaperIfExistsFunction(); |
| 40 | 40 |
| 41 // AsyncExtensionFunction overrides. | 41 // AsyncExtensionFunction overrides. |
| 42 virtual bool RunImpl() OVERRIDE; | 42 virtual bool RunSync() OVERRIDE; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE; | 45 virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE; |
| 46 | 46 |
| 47 // File doesn't exist. Sets javascript callback parameter to false. | 47 // File doesn't exist. Sets javascript callback parameter to false. |
| 48 void OnFileNotExists(const std::string& error); | 48 void OnFileNotExists(const std::string& error); |
| 49 | 49 |
| 50 // Reads file specified by |file_path|. If success, post a task to start | 50 // Reads file specified by |file_path|. If success, post a task to start |
| 51 // decoding the file. | 51 // decoding the file. |
| 52 void ReadFileAndInitiateStartDecode(const base::FilePath& file_path, | 52 void ReadFileAndInitiateStartDecode(const base::FilePath& file_path, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 public: | 67 public: |
| 68 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper", | 68 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper", |
| 69 WALLPAPERPRIVATE_SETWALLPAPER) | 69 WALLPAPERPRIVATE_SETWALLPAPER) |
| 70 | 70 |
| 71 WallpaperPrivateSetWallpaperFunction(); | 71 WallpaperPrivateSetWallpaperFunction(); |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 virtual ~WallpaperPrivateSetWallpaperFunction(); | 74 virtual ~WallpaperPrivateSetWallpaperFunction(); |
| 75 | 75 |
| 76 // AsyncExtensionFunction overrides. | 76 // AsyncExtensionFunction overrides. |
| 77 virtual bool RunImpl() OVERRIDE; | 77 virtual bool RunSync() OVERRIDE; |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE; | 80 virtual void OnWallpaperDecoded(const gfx::ImageSkia& image) OVERRIDE; |
| 81 | 81 |
| 82 // Saves the image data to a file. | 82 // Saves the image data to a file. |
| 83 void SaveToFile(); | 83 void SaveToFile(); |
| 84 | 84 |
| 85 // Sets wallpaper to the decoded image. | 85 // Sets wallpaper to the decoded image. |
| 86 void SetDecodedWallpaper(scoped_ptr<gfx::ImageSkia> image); | 86 void SetDecodedWallpaper(scoped_ptr<gfx::ImageSkia> image); |
| 87 | 87 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 104 public: | 104 public: |
| 105 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper", | 105 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper", |
| 106 WALLPAPERPRIVATE_RESETWALLPAPER) | 106 WALLPAPERPRIVATE_RESETWALLPAPER) |
| 107 | 107 |
| 108 WallpaperPrivateResetWallpaperFunction(); | 108 WallpaperPrivateResetWallpaperFunction(); |
| 109 | 109 |
| 110 protected: | 110 protected: |
| 111 virtual ~WallpaperPrivateResetWallpaperFunction(); | 111 virtual ~WallpaperPrivateResetWallpaperFunction(); |
| 112 | 112 |
| 113 // AsyncExtensionFunction overrides. | 113 // AsyncExtensionFunction overrides. |
| 114 virtual bool RunImpl() OVERRIDE; | 114 virtual bool RunSync() OVERRIDE; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class WallpaperPrivateSetCustomWallpaperFunction | 117 class WallpaperPrivateSetCustomWallpaperFunction |
| 118 : public WallpaperFunctionBase { | 118 : public WallpaperFunctionBase { |
| 119 public: | 119 public: |
| 120 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper", | 120 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper", |
| 121 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER) | 121 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER) |
| 122 | 122 |
| 123 WallpaperPrivateSetCustomWallpaperFunction(); | 123 WallpaperPrivateSetCustomWallpaperFunction(); |
| 124 | 124 |
| 125 protected: | 125 protected: |
| 126 virtual ~WallpaperPrivateSetCustomWallpaperFunction(); | 126 virtual ~WallpaperPrivateSetCustomWallpaperFunction(); |
| 127 | 127 |
| 128 // AsyncExtensionFunction overrides. | 128 // AsyncExtensionFunction overrides. |
| 129 virtual bool RunImpl() OVERRIDE; | 129 virtual bool RunSync() OVERRIDE; |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; | 132 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; |
| 133 | 133 |
| 134 // Generates thumbnail of custom wallpaper. A simple STRETCH is used for | 134 // Generates thumbnail of custom wallpaper. A simple STRETCH is used for |
| 135 // generating thunbail. | 135 // generating thunbail. |
| 136 void GenerateThumbnail(const base::FilePath& thumbnail_path, | 136 void GenerateThumbnail(const base::FilePath& thumbnail_path, |
| 137 scoped_ptr<gfx::ImageSkia> image); | 137 scoped_ptr<gfx::ImageSkia> image); |
| 138 | 138 |
| 139 // Thumbnail is ready. Calls api function javascript callback. | 139 // Thumbnail is ready. Calls api function javascript callback. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 158 public: | 158 public: |
| 159 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout", | 159 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout", |
| 160 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT) | 160 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT) |
| 161 | 161 |
| 162 WallpaperPrivateSetCustomWallpaperLayoutFunction(); | 162 WallpaperPrivateSetCustomWallpaperLayoutFunction(); |
| 163 | 163 |
| 164 protected: | 164 protected: |
| 165 virtual ~WallpaperPrivateSetCustomWallpaperLayoutFunction(); | 165 virtual ~WallpaperPrivateSetCustomWallpaperLayoutFunction(); |
| 166 | 166 |
| 167 // AsyncExtensionFunction overrides. | 167 // AsyncExtensionFunction overrides. |
| 168 virtual bool RunImpl() OVERRIDE; | 168 virtual bool RunSync() OVERRIDE; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 class WallpaperPrivateMinimizeInactiveWindowsFunction | 171 class WallpaperPrivateMinimizeInactiveWindowsFunction |
| 172 : public AsyncExtensionFunction { | 172 : public AsyncExtensionFunction { |
| 173 public: | 173 public: |
| 174 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows", | 174 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows", |
| 175 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS) | 175 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS) |
| 176 | 176 |
| 177 WallpaperPrivateMinimizeInactiveWindowsFunction(); | 177 WallpaperPrivateMinimizeInactiveWindowsFunction(); |
| 178 | 178 |
| 179 protected: | 179 protected: |
| 180 virtual ~WallpaperPrivateMinimizeInactiveWindowsFunction(); | 180 virtual ~WallpaperPrivateMinimizeInactiveWindowsFunction(); |
| 181 | 181 |
| 182 // AsyncExtensionFunction overrides. | 182 // AsyncExtensionFunction overrides. |
| 183 virtual bool RunImpl() OVERRIDE; | 183 virtual bool RunSync() OVERRIDE; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 class WallpaperPrivateRestoreMinimizedWindowsFunction | 186 class WallpaperPrivateRestoreMinimizedWindowsFunction |
| 187 : public AsyncExtensionFunction { | 187 : public AsyncExtensionFunction { |
| 188 public: | 188 public: |
| 189 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows", | 189 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows", |
| 190 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS) | 190 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS) |
| 191 | 191 |
| 192 WallpaperPrivateRestoreMinimizedWindowsFunction(); | 192 WallpaperPrivateRestoreMinimizedWindowsFunction(); |
| 193 | 193 |
| 194 protected: | 194 protected: |
| 195 virtual ~WallpaperPrivateRestoreMinimizedWindowsFunction(); | 195 virtual ~WallpaperPrivateRestoreMinimizedWindowsFunction(); |
| 196 | 196 |
| 197 // AsyncExtensionFunction overrides. | 197 // AsyncExtensionFunction overrides. |
| 198 virtual bool RunImpl() OVERRIDE; | 198 virtual bool RunSync() OVERRIDE; |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 class WallpaperPrivateGetThumbnailFunction : public AsyncExtensionFunction { | 201 class WallpaperPrivateGetThumbnailFunction : public AsyncExtensionFunction { |
| 202 public: | 202 public: |
| 203 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail", | 203 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail", |
| 204 WALLPAPERPRIVATE_GETTHUMBNAIL) | 204 WALLPAPERPRIVATE_GETTHUMBNAIL) |
| 205 | 205 |
| 206 WallpaperPrivateGetThumbnailFunction(); | 206 WallpaperPrivateGetThumbnailFunction(); |
| 207 | 207 |
| 208 protected: | 208 protected: |
| 209 virtual ~WallpaperPrivateGetThumbnailFunction(); | 209 virtual ~WallpaperPrivateGetThumbnailFunction(); |
| 210 | 210 |
| 211 // AsyncExtensionFunction overrides. | 211 // AsyncExtensionFunction overrides. |
| 212 virtual bool RunImpl() OVERRIDE; | 212 virtual bool RunSync() OVERRIDE; |
| 213 | 213 |
| 214 private: | 214 private: |
| 215 // Failed to get thumbnail for |file_name|. | 215 // Failed to get thumbnail for |file_name|. |
| 216 void Failure(const std::string& file_name); | 216 void Failure(const std::string& file_name); |
| 217 | 217 |
| 218 // Returns true to suppress javascript console error. Called when the | 218 // Returns true to suppress javascript console error. Called when the |
| 219 // requested thumbnail is not found or corrupted in thumbnail directory. | 219 // requested thumbnail is not found or corrupted in thumbnail directory. |
| 220 void FileNotLoaded(); | 220 void FileNotLoaded(); |
| 221 | 221 |
| 222 // Sets data field to the loaded thumbnail binary data in the results. Called | 222 // Sets data field to the loaded thumbnail binary data in the results. Called |
| (...skipping 12 matching lines...) Expand all Loading... |
| 235 public: | 235 public: |
| 236 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail", | 236 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail", |
| 237 WALLPAPERPRIVATE_SAVETHUMBNAIL) | 237 WALLPAPERPRIVATE_SAVETHUMBNAIL) |
| 238 | 238 |
| 239 WallpaperPrivateSaveThumbnailFunction(); | 239 WallpaperPrivateSaveThumbnailFunction(); |
| 240 | 240 |
| 241 protected: | 241 protected: |
| 242 virtual ~WallpaperPrivateSaveThumbnailFunction(); | 242 virtual ~WallpaperPrivateSaveThumbnailFunction(); |
| 243 | 243 |
| 244 // AsyncExtensionFunction overrides. | 244 // AsyncExtensionFunction overrides. |
| 245 virtual bool RunImpl() OVERRIDE; | 245 virtual bool RunSync() OVERRIDE; |
| 246 | 246 |
| 247 private: | 247 private: |
| 248 // Failed to save thumbnail for |file_name|. | 248 // Failed to save thumbnail for |file_name|. |
| 249 void Failure(const std::string& file_name); | 249 void Failure(const std::string& file_name); |
| 250 | 250 |
| 251 // Saved thumbnail to thumbnail directory. | 251 // Saved thumbnail to thumbnail directory. |
| 252 void Success(); | 252 void Success(); |
| 253 | 253 |
| 254 // Saves thumbnail to thumbnail directory as |file_name|. | 254 // Saves thumbnail to thumbnail directory as |file_name|. |
| 255 void Save(const std::string& data, const std::string& file_name); | 255 void Save(const std::string& data, const std::string& file_name); |
| 256 | 256 |
| 257 // Sequence token associated with wallpaper operations. Shared with | 257 // Sequence token associated with wallpaper operations. Shared with |
| 258 // WallpaperManager. | 258 // WallpaperManager. |
| 259 base::SequencedWorkerPool::SequenceToken sequence_token_; | 259 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 class WallpaperPrivateGetOfflineWallpaperListFunction | 262 class WallpaperPrivateGetOfflineWallpaperListFunction |
| 263 : public AsyncExtensionFunction { | 263 : public AsyncExtensionFunction { |
| 264 public: | 264 public: |
| 265 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList", | 265 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList", |
| 266 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST) | 266 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST) |
| 267 WallpaperPrivateGetOfflineWallpaperListFunction(); | 267 WallpaperPrivateGetOfflineWallpaperListFunction(); |
| 268 | 268 |
| 269 protected: | 269 protected: |
| 270 virtual ~WallpaperPrivateGetOfflineWallpaperListFunction(); | 270 virtual ~WallpaperPrivateGetOfflineWallpaperListFunction(); |
| 271 | 271 |
| 272 // AsyncExtensionFunction overrides. | 272 // AsyncExtensionFunction overrides. |
| 273 virtual bool RunImpl() OVERRIDE; | 273 virtual bool RunSync() OVERRIDE; |
| 274 | 274 |
| 275 private: | 275 private: |
| 276 // Enumerates the list of files in online wallpaper directory. | 276 // Enumerates the list of files in online wallpaper directory. |
| 277 void GetList(); | 277 void GetList(); |
| 278 | 278 |
| 279 // Sends the list of files to extension api caller. If no files or no | 279 // Sends the list of files to extension api caller. If no files or no |
| 280 // directory, sends empty list. | 280 // directory, sends empty list. |
| 281 void OnComplete(const std::vector<std::string>& file_list); | 281 void OnComplete(const std::vector<std::string>& file_list); |
| 282 | 282 |
| 283 // Sequence token associated with wallpaper operations. Shared with | 283 // Sequence token associated with wallpaper operations. Shared with |
| 284 // WallpaperManager. | 284 // WallpaperManager. |
| 285 base::SequencedWorkerPool::SequenceToken sequence_token_; | 285 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 288 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| OLD | NEW |