Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/wallpaper_manager_api.h |
| diff --git a/chrome/browser/chromeos/extensions/wallpaper_manager_api.h b/chrome/browser/chromeos/extensions/wallpaper_manager_api.h |
| index 8cda7af844fe20ffdd847d8999af84f43a771063..bb2541b3db4febadcfcfbeb7ad3d7c77802c89e2 100644 |
| --- a/chrome/browser/chromeos/extensions/wallpaper_manager_api.h |
| +++ b/chrome/browser/chromeos/extensions/wallpaper_manager_api.h |
| @@ -6,8 +6,10 @@ |
| #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |
| #pragma once |
| +#include "ash/desktop_background/desktop_background_resources.h" |
| #include "base/file_path.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/observer_list.h" |
| #include "base/time.h" |
| #include "chrome/browser/extensions/extension_function.h" |
| @@ -16,6 +18,31 @@ |
| extern const char kWallpaperManagerDomain[]; |
| +namespace { |
| + |
| +enum WallpaperErrorCode { |
| + HTTP_SUCCESS = 200, |
| + HTTP_CREATED = 201, |
| + HTTP_FOUND = 302, |
| + HTTP_NOT_MODIFIED = 304, |
| + HTTP_RESUME_INCOMPLETE = 308, |
| + HTTP_BAD_REQUEST = 400, |
| + HTTP_UNAUTHORIZED = 401, |
| + HTTP_FORBIDDEN = 403, |
| + HTTP_NOT_FOUND = 404, |
| + HTTP_CONFLICT = 409, |
| + HTTP_LENGTH_REQUIRED = 411, |
| + HTTP_PRECONDITION = 412, |
| + HTTP_INTERNAL_SERVER_ERROR = 500, |
| + HTTP_SERVICE_UNAVAILABLE = 503, |
| + WALLPAPER_NO_CONNECTION = -100, |
| + WALLPAPER_FILE_ERROR = -101, |
| +}; |
| + |
| +const int64 kBytesWallpaperDownloadProgressReportInterval = 10240; |
| + |
| +} // namespace |
| + |
| namespace wallpaper_manager_util { |
| // Opens wallpaper manager application. |
| @@ -23,8 +50,82 @@ void OpenWallpaperManager(); |
| } // namespace wallpaper_manager_util |
| +// Wallpaper manager strings. |
| +class WallpaperManagerStringsFunction : public SyncExtensionFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("experimental.wallpaperManager.getStrings"); |
| + |
| + protected: |
| + virtual ~WallpaperManagerStringsFunction() {} |
| + |
| + // SyncExtensionFunction overrides. |
| + virtual bool RunImpl() OVERRIDE; |
| +}; |
| + |
| +// Sets wallpaper to the image downloaded from URL. |
| +class WallpaperManagerSetWallpaperFunction : public AsyncExtensionFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("experimental.wallpaperManager.setWallpaper"); |
| + |
| + protected: |
| + virtual ~WallpaperManagerSetWallpaperFunction(); |
| + |
| + // SyncExtensionFunction overrides. |
| + virtual bool RunImpl() OVERRIDE; |
| + |
| + private: |
| + // This class is a wrapper class for URLFetcher. It has a ref counted pointer |
| + // to class WallpaperManagerSetWallpaperFunction. So the instance of that |
| + // class did not delete itself before fetching complete. |
| + class WallpaperFetcher : public net::URLFetcherDelegate { |
| + public: |
| + explicit WallpaperFetcher( |
| + scoped_refptr<WallpaperManagerSetWallpaperFunction> function); |
| + |
| + void Start(const GURL& wallpaper_url, |
| + const FilePath& file_path); |
| + |
| + private: |
| + // URLFetcherDelegate overrides: |
| + virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE ; |
| + virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| + int64 current, |
| + int64 total) OVERRIDE; |
| + |
| + scoped_refptr<WallpaperManagerSetWallpaperFunction> function_; |
| + scoped_ptr<net::URLFetcher> fetcher_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WallpaperFetcher); |
| + }; |
| + |
| + void OnDownloadComplete(const net::URLFetcher* source); |
| + void OnDownloadProgress(const net::URLFetcher* source, |
| + int64 current, |
| + int64 total); |
| + |
| + // Requests wallpaper from local file if cached. |
| + void RequestOnFileThread(const std::string& source_url); |
| + |
| + // Setups the url_fetcher on UI thread. |
|
flackr
2012/07/12 19:26:12
s/Setups/Sets up
bshe
2012/07/13 19:28:57
Done.
|
| + void SetupFetcherOnUIThread(const GURL& wallpaper_url); |
| + |
| + // Returns wallpaper manager specific error code. |
| + WallpaperErrorCode GetErrorCode(const net::URLFetcher* source) const; |
| + |
| + // Dispatch DownloadErrorEvent to wallpaper manager extension. |
| + void DispatchErrorEvent(WallpaperErrorCode code); |
| + |
| + // Creates directory wallpaper will be downloaded to. |
| + bool CreateDirectory(const FilePath& path); |
| + |
| + FilePath wallpaper_dir_; |
| + ash::WallpaperLayout layout_; |
| + scoped_ptr<WallpaperFetcher> fetcher_; |
| + // The email address of logged in user. |
| + std::string email_; |
| -// Wallpaper manager API functions. Followup CL will add implementations of |
| -// some API functions. |
| + base::TimeTicks tick_wallpaper_download_start_; |
| + int64 bytes_wallpaper_download_progress_last_reported_; |
| +}; |
| #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |