| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/threading/sequenced_worker_pool.h" | |
| 12 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" | 11 #include "chrome/browser/chromeos/extensions/wallpaper_function_base.h" |
| 13 #include "chrome/common/extensions/api/wallpaper_private.h" | 12 #include "chrome/common/extensions/api/wallpaper_private.h" |
| 14 #include "components/signin/core/account_id/account_id.h" | 13 #include "components/signin/core/account_id/account_id.h" |
| 15 #include "components/wallpaper/wallpaper_files_id.h" | 14 #include "components/wallpaper/wallpaper_files_id.h" |
| 16 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
| 17 | 16 |
| 18 namespace base { | 17 namespace base { |
| 19 class RefCountedBytes; | 18 class RefCountedBytes; |
| 20 } | 19 } |
| 21 | 20 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // decoding the file. | 73 // decoding the file. |
| 75 void ReadFileAndInitiateStartDecode(const base::FilePath& file_path, | 74 void ReadFileAndInitiateStartDecode(const base::FilePath& file_path, |
| 76 const base::FilePath& fallback_path); | 75 const base::FilePath& fallback_path); |
| 77 | 76 |
| 78 std::unique_ptr< | 77 std::unique_ptr< |
| 79 extensions::api::wallpaper_private::SetWallpaperIfExists::Params> | 78 extensions::api::wallpaper_private::SetWallpaperIfExists::Params> |
| 80 params; | 79 params; |
| 81 | 80 |
| 82 // User id of the active user when this api is been called. | 81 // User id of the active user when this api is been called. |
| 83 AccountId account_id_ = EmptyAccountId(); | 82 AccountId account_id_ = EmptyAccountId(); |
| 84 | |
| 85 // Sequence token associated with wallpaper operations. Shared with | |
| 86 // WallpaperManager. | |
| 87 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
| 88 }; | 83 }; |
| 89 | 84 |
| 90 class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase { | 85 class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase { |
| 91 public: | 86 public: |
| 92 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper", | 87 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper", |
| 93 WALLPAPERPRIVATE_SETWALLPAPER) | 88 WALLPAPERPRIVATE_SETWALLPAPER) |
| 94 | 89 |
| 95 WallpaperPrivateSetWallpaperFunction(); | 90 WallpaperPrivateSetWallpaperFunction(); |
| 96 | 91 |
| 97 protected: | 92 protected: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 111 | 106 |
| 112 std::unique_ptr<extensions::api::wallpaper_private::SetWallpaper::Params> | 107 std::unique_ptr<extensions::api::wallpaper_private::SetWallpaper::Params> |
| 113 params; | 108 params; |
| 114 | 109 |
| 115 // The decoded wallpaper. It may accessed from UI thread to set wallpaper or | 110 // The decoded wallpaper. It may accessed from UI thread to set wallpaper or |
| 116 // FILE thread to resize and save wallpaper to disk. | 111 // FILE thread to resize and save wallpaper to disk. |
| 117 gfx::ImageSkia wallpaper_; | 112 gfx::ImageSkia wallpaper_; |
| 118 | 113 |
| 119 // User account id of the active user when this api is been called. | 114 // User account id of the active user when this api is been called. |
| 120 AccountId account_id_ = EmptyAccountId(); | 115 AccountId account_id_ = EmptyAccountId(); |
| 121 | |
| 122 // Sequence token associated with wallpaper operations. Shared with | |
| 123 // WallpaperManager. | |
| 124 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
| 125 }; | 116 }; |
| 126 | 117 |
| 127 class WallpaperPrivateResetWallpaperFunction | 118 class WallpaperPrivateResetWallpaperFunction |
| 128 : public AsyncExtensionFunction { | 119 : public AsyncExtensionFunction { |
| 129 public: | 120 public: |
| 130 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper", | 121 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.resetWallpaper", |
| 131 WALLPAPERPRIVATE_RESETWALLPAPER) | 122 WALLPAPERPRIVATE_RESETWALLPAPER) |
| 132 | 123 |
| 133 WallpaperPrivateResetWallpaperFunction(); | 124 WallpaperPrivateResetWallpaperFunction(); |
| 134 | 125 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 157 |
| 167 std::unique_ptr< | 158 std::unique_ptr< |
| 168 extensions::api::wallpaper_private::SetCustomWallpaper::Params> | 159 extensions::api::wallpaper_private::SetCustomWallpaper::Params> |
| 169 params; | 160 params; |
| 170 | 161 |
| 171 // User account id of the active user when this api is been called. | 162 // User account id of the active user when this api is been called. |
| 172 AccountId account_id_ = EmptyAccountId(); | 163 AccountId account_id_ = EmptyAccountId(); |
| 173 | 164 |
| 174 // User id hash of the logged in user. | 165 // User id hash of the logged in user. |
| 175 wallpaper::WallpaperFilesId wallpaper_files_id_; | 166 wallpaper::WallpaperFilesId wallpaper_files_id_; |
| 176 | |
| 177 // Sequence token associated with wallpaper operations. Shared with | |
| 178 // WallpaperManager. | |
| 179 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
| 180 }; | 167 }; |
| 181 | 168 |
| 182 class WallpaperPrivateSetCustomWallpaperLayoutFunction | 169 class WallpaperPrivateSetCustomWallpaperLayoutFunction |
| 183 : public AsyncExtensionFunction { | 170 : public AsyncExtensionFunction { |
| 184 public: | 171 public: |
| 185 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout", | 172 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaperLayout", |
| 186 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT) | 173 WALLPAPERPRIVATE_SETCUSTOMWALLPAPERLAYOUT) |
| 187 | 174 |
| 188 WallpaperPrivateSetCustomWallpaperLayoutFunction(); | 175 WallpaperPrivateSetCustomWallpaperLayoutFunction(); |
| 189 | 176 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Returns true to suppress javascript console error. Called when the | 227 // Returns true to suppress javascript console error. Called when the |
| 241 // requested thumbnail is not found or corrupted in thumbnail directory. | 228 // requested thumbnail is not found or corrupted in thumbnail directory. |
| 242 void FileNotLoaded(); | 229 void FileNotLoaded(); |
| 243 | 230 |
| 244 // Sets data field to the loaded thumbnail binary data in the results. Called | 231 // Sets data field to the loaded thumbnail binary data in the results. Called |
| 245 // when requested wallpaper thumbnail loaded successfully. | 232 // when requested wallpaper thumbnail loaded successfully. |
| 246 void FileLoaded(const std::string& data); | 233 void FileLoaded(const std::string& data); |
| 247 | 234 |
| 248 // Gets thumbnail from |path|. If |path| does not exist, call FileNotLoaded(). | 235 // Gets thumbnail from |path|. If |path| does not exist, call FileNotLoaded(). |
| 249 void Get(const base::FilePath& path); | 236 void Get(const base::FilePath& path); |
| 250 | |
| 251 // Sequence token associated with wallpaper operations. Shared with | |
| 252 // WallpaperManager. | |
| 253 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
| 254 }; | 237 }; |
| 255 | 238 |
| 256 class WallpaperPrivateSaveThumbnailFunction : public AsyncExtensionFunction { | 239 class WallpaperPrivateSaveThumbnailFunction : public AsyncExtensionFunction { |
| 257 public: | 240 public: |
| 258 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail", | 241 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail", |
| 259 WALLPAPERPRIVATE_SAVETHUMBNAIL) | 242 WALLPAPERPRIVATE_SAVETHUMBNAIL) |
| 260 | 243 |
| 261 WallpaperPrivateSaveThumbnailFunction(); | 244 WallpaperPrivateSaveThumbnailFunction(); |
| 262 | 245 |
| 263 protected: | 246 protected: |
| 264 ~WallpaperPrivateSaveThumbnailFunction() override; | 247 ~WallpaperPrivateSaveThumbnailFunction() override; |
| 265 | 248 |
| 266 // AsyncExtensionFunction overrides. | 249 // AsyncExtensionFunction overrides. |
| 267 bool RunAsync() override; | 250 bool RunAsync() override; |
| 268 | 251 |
| 269 private: | 252 private: |
| 270 // Failed to save thumbnail for |file_name|. | 253 // Failed to save thumbnail for |file_name|. |
| 271 void Failure(const std::string& file_name); | 254 void Failure(const std::string& file_name); |
| 272 | 255 |
| 273 // Saved thumbnail to thumbnail directory. | 256 // Saved thumbnail to thumbnail directory. |
| 274 void Success(); | 257 void Success(); |
| 275 | 258 |
| 276 // Saves thumbnail to thumbnail directory as |file_name|. | 259 // Saves thumbnail to thumbnail directory as |file_name|. |
| 277 void Save(const std::vector<char>& data, const std::string& file_name); | 260 void Save(const std::vector<char>& data, const std::string& file_name); |
| 278 | |
| 279 // Sequence token associated with wallpaper operations. Shared with | |
| 280 // WallpaperManager. | |
| 281 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
| 282 }; | 261 }; |
| 283 | 262 |
| 284 class WallpaperPrivateGetOfflineWallpaperListFunction | 263 class WallpaperPrivateGetOfflineWallpaperListFunction |
| 285 : public AsyncExtensionFunction { | 264 : public AsyncExtensionFunction { |
| 286 public: | 265 public: |
| 287 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList", | 266 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList", |
| 288 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST) | 267 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST) |
| 289 WallpaperPrivateGetOfflineWallpaperListFunction(); | 268 WallpaperPrivateGetOfflineWallpaperListFunction(); |
| 290 | 269 |
| 291 protected: | 270 protected: |
| 292 ~WallpaperPrivateGetOfflineWallpaperListFunction() override; | 271 ~WallpaperPrivateGetOfflineWallpaperListFunction() override; |
| 293 | 272 |
| 294 // AsyncExtensionFunction overrides. | 273 // AsyncExtensionFunction overrides. |
| 295 bool RunAsync() override; | 274 bool RunAsync() override; |
| 296 | 275 |
| 297 private: | 276 private: |
| 298 // Enumerates the list of files in online wallpaper directory. | 277 // Enumerates the list of files in online wallpaper directory. |
| 299 void GetList(); | 278 void GetList(); |
| 300 | 279 |
| 301 // Sends the list of files to extension api caller. If no files or no | 280 // Sends the list of files to extension api caller. If no files or no |
| 302 // directory, sends empty list. | 281 // directory, sends empty list. |
| 303 void OnComplete(const std::vector<std::string>& file_list); | 282 void OnComplete(const std::vector<std::string>& file_list); |
| 304 | |
| 305 // Sequence token associated with wallpaper operations. Shared with | |
| 306 // WallpaperManager. | |
| 307 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
| 308 }; | 283 }; |
| 309 | 284 |
| 310 // The wallpaper UMA is recorded when a new wallpaper is set, either by the | 285 // The wallpaper UMA is recorded when a new wallpaper is set, either by the |
| 311 // built-in Wallpaper Picker App, or by a third party App. | 286 // built-in Wallpaper Picker App, or by a third party App. |
| 312 class WallpaperPrivateRecordWallpaperUMAFunction | 287 class WallpaperPrivateRecordWallpaperUMAFunction |
| 313 : public UIThreadExtensionFunction { | 288 : public UIThreadExtensionFunction { |
| 314 public: | 289 public: |
| 315 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.recordWallpaperUMA", | 290 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.recordWallpaperUMA", |
| 316 WALLPAPERPRIVATE_RECORDWALLPAPERUMA) | 291 WALLPAPERPRIVATE_RECORDWALLPAPERUMA) |
| 317 | 292 |
| 318 protected: | 293 protected: |
| 319 ~WallpaperPrivateRecordWallpaperUMAFunction() override {} | 294 ~WallpaperPrivateRecordWallpaperUMAFunction() override {} |
| 320 | 295 |
| 321 // ExtensionFunction: | 296 // ExtensionFunction: |
| 322 ResponseAction Run() override; | 297 ResponseAction Run() override; |
| 323 }; | 298 }; |
| 324 | 299 |
| 325 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 300 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| OLD | NEW |