Chromium Code Reviews| 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_MANAGER_API_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |
| 7 | 7 |
| 8 #include "ash/desktop_background/desktop_background_resources.h" | |
| 8 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "chrome/browser/extensions/extension_function.h" | 13 #include "chrome/browser/extensions/extension_function.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
| 15 | 16 |
| 16 extern const char kWallpaperManagerDomain[]; | 17 extern const char kWallpaperManagerDomain[]; |
| 17 | 18 |
| 18 // Wallpaper manager API functions. Followup CL will add implementations of | 19 namespace { |
| 19 // some API functions. | 20 |
| 21 enum WallpaperErrorCode { | |
| 22 HTTP_SUCCESS = 200, | |
| 23 HTTP_CREATED = 201, | |
| 24 HTTP_FOUND = 302, | |
| 25 HTTP_NOT_MODIFIED = 304, | |
| 26 HTTP_RESUME_INCOMPLETE = 308, | |
| 27 HTTP_BAD_REQUEST = 400, | |
| 28 HTTP_UNAUTHORIZED = 401, | |
| 29 HTTP_FORBIDDEN = 403, | |
| 30 HTTP_NOT_FOUND = 404, | |
| 31 HTTP_CONFLICT = 409, | |
| 32 HTTP_LENGTH_REQUIRED = 411, | |
| 33 HTTP_PRECONDITION = 412, | |
| 34 HTTP_INTERNAL_SERVER_ERROR = 500, | |
| 35 HTTP_SERVICE_UNAVAILABLE = 503, | |
| 36 WALLPAPER_NO_CONNECTION = -100, | |
| 37 WALLPAPER_FILE_ERROR = -101, | |
| 38 }; | |
| 39 | |
| 40 const int64 kBytesWallpaperDownloadProgressReportInterval = 10240; | |
|
Mihai Parparita -not on Chrome
2012/07/16 23:14:25
Seems like this can just be in the .cc file.
bshe
2012/07/18 18:28:56
removed.
On 2012/07/16 23:14:25, Mihai Parparita
| |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 20 namespace wallpaper_manager_util { | 44 namespace wallpaper_manager_util { |
| 21 | 45 |
| 22 // Opens wallpaper manager application. | 46 // Opens wallpaper manager application. |
| 23 void OpenWallpaperManager(); | 47 void OpenWallpaperManager(); |
| 24 | 48 |
| 25 } // namespace wallpaper_manager_util | 49 } // namespace wallpaper_manager_util |
| 26 | 50 |
| 51 // Wallpaper manager strings. | |
| 52 class WallpaperManagerStringsFunction : public SyncExtensionFunction { | |
| 53 public: | |
| 54 DECLARE_EXTENSION_FUNCTION_NAME("wallpaperManagerPrivate.getStrings"); | |
| 55 | |
| 56 protected: | |
| 57 virtual ~WallpaperManagerStringsFunction() {} | |
| 58 | |
| 59 // SyncExtensionFunction overrides. | |
| 60 virtual bool RunImpl() OVERRIDE; | |
| 61 }; | |
| 62 | |
| 63 // Sets wallpaper to the image downloaded from URL. | |
| 64 class WallpaperManagerSetWallpaperFunction : public AsyncExtensionFunction { | |
| 65 public: | |
| 66 DECLARE_EXTENSION_FUNCTION_NAME("wallpaperManagerPrivate.setWallpaper"); | |
|
Mihai Parparita -not on Chrome
2012/07/16 23:14:25
The file name generally matches the API namespace
bshe
2012/07/18 18:28:56
Done.
| |
| 67 | |
| 68 protected: | |
| 69 virtual ~WallpaperManagerSetWallpaperFunction(); | |
| 70 | |
| 71 // SyncExtensionFunction overrides. | |
| 72 virtual bool RunImpl() OVERRIDE; | |
| 73 | |
| 74 private: | |
| 75 // This class is a wrapper class for URLFetcher. It has a ref counted pointer | |
|
Mihai Parparita -not on Chrome
2012/07/16 23:14:25
To make the header file more readable/hide interna
bshe
2012/07/18 18:28:56
Removed the class in new patch.
On 2012/07/16 23:
| |
| 76 // to class WallpaperManagerSetWallpaperFunction. So the instance of that | |
| 77 // class did not delete itself before fetching complete. We need to delete | |
| 78 // this wrapper class to release the ref counted pointer when fetch completed | |
| 79 // or canceled. | |
| 80 class WallpaperFetcher : public net::URLFetcherDelegate { | |
| 81 public: | |
| 82 explicit WallpaperFetcher( | |
| 83 scoped_refptr<WallpaperManagerSetWallpaperFunction> function); | |
| 84 | |
| 85 void Cancel(); | |
| 86 | |
| 87 void Start(const GURL& wallpaper_url, | |
| 88 const FilePath& file_path); | |
| 89 | |
| 90 private: | |
| 91 // URLFetcherDelegate overrides: | |
| 92 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE ; | |
| 93 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | |
| 94 int64 current, | |
| 95 int64 total) OVERRIDE; | |
| 96 | |
| 97 scoped_refptr<WallpaperManagerSetWallpaperFunction> function_; | |
| 98 scoped_ptr<net::URLFetcher> fetcher_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(WallpaperFetcher); | |
| 101 }; | |
| 102 | |
| 103 void OnDownloadComplete(const net::URLFetcher* source); | |
| 104 void OnDownloadProgress(const net::URLFetcher* source, | |
| 105 int64 current, | |
| 106 int64 total); | |
| 107 | |
| 108 // Requests wallpaper from local file if cached. | |
| 109 void RequestOnFileThread(const std::string& source_url); | |
| 110 | |
| 111 // Changes wallpaper to image at |file_path|. | |
| 112 void SetWallpaperOnUIThread(const FilePath& file_path); | |
| 113 | |
| 114 // Sets up the url_fetcher on UI thread. | |
| 115 void SetupFetcherOnUIThread(const GURL& wallpaper_url); | |
| 116 | |
| 117 // Returns wallpaper manager specific error code. | |
| 118 WallpaperErrorCode GetErrorCode(const net::URLFetcher* source) const; | |
| 119 | |
| 120 // Dispatch DownloadErrorEvent to wallpaper manager extension. | |
| 121 void DispatchErrorEvent(WallpaperErrorCode code); | |
| 122 | |
| 123 // Directory to save downloaded wallpapers. | |
| 124 FilePath wallpaper_dir_; | |
| 125 | |
| 126 // Layout of the downloaded wallpaper. | |
| 127 ash::WallpaperLayout layout_; | |
| 128 | |
| 129 // Instance of WallpaperFetcher. | |
| 130 static WallpaperFetcher* fetcher_; | |
| 131 | |
| 132 // The email address of logged in user. | |
| 133 std::string email_; | |
| 134 | |
| 135 base::TimeTicks tick_wallpaper_download_start_; | |
| 136 int64 bytes_wallpaper_download_progress_last_reported_; | |
| 137 }; | |
| 138 | |
| 27 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ | 139 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |
| OLD | NEW |