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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "chrome/browser/extensions/extension_function.h" | 14 #include "chrome/browser/extensions/extension_function.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
16 | 17 |
17 extern const char kWallpaperManagerDomain[]; | 18 extern const char kWallpaperManagerDomain[]; |
18 | 19 |
| 20 namespace { |
| 21 |
| 22 enum WallpaperErrorCode { |
| 23 HTTP_SUCCESS = 200, |
| 24 HTTP_CREATED = 201, |
| 25 HTTP_FOUND = 302, |
| 26 HTTP_NOT_MODIFIED = 304, |
| 27 HTTP_RESUME_INCOMPLETE = 308, |
| 28 HTTP_BAD_REQUEST = 400, |
| 29 HTTP_UNAUTHORIZED = 401, |
| 30 HTTP_FORBIDDEN = 403, |
| 31 HTTP_NOT_FOUND = 404, |
| 32 HTTP_CONFLICT = 409, |
| 33 HTTP_LENGTH_REQUIRED = 411, |
| 34 HTTP_PRECONDITION = 412, |
| 35 HTTP_INTERNAL_SERVER_ERROR = 500, |
| 36 HTTP_SERVICE_UNAVAILABLE = 503, |
| 37 WALLPAPER_NO_CONNECTION = -100, |
| 38 WALLPAPER_FILE_ERROR = -101, |
| 39 }; |
| 40 |
| 41 const int64 kBytesWallpaperDownloadProgressReportInterval = 10240; |
| 42 |
| 43 } // namespace |
| 44 |
19 namespace wallpaper_manager_util { | 45 namespace wallpaper_manager_util { |
20 | 46 |
21 // Opens wallpaper manager application. | 47 // Opens wallpaper manager application. |
22 void OpenWallpaperManager(); | 48 void OpenWallpaperManager(); |
23 | 49 |
24 } // namespace wallpaper_manager_util | 50 } // namespace wallpaper_manager_util |
25 | 51 |
| 52 // Wallpaper manager strings. |
| 53 class WallpaperManagerStringsFunction : public SyncExtensionFunction { |
| 54 public: |
| 55 DECLARE_EXTENSION_FUNCTION_NAME("experimental.wallpaperManager.getStrings"); |
26 | 56 |
27 // Wallpaper manager API functions. Followup CL will add implementations of | 57 protected: |
28 // some API functions. | 58 virtual ~WallpaperManagerStringsFunction() {} |
| 59 |
| 60 // SyncExtensionFunction overrides. |
| 61 virtual bool RunImpl() OVERRIDE; |
| 62 }; |
| 63 |
| 64 // Sets wallpaper to the image downloaded from URL. |
| 65 class WallpaperManagerSetWallpaperFunction : public AsyncExtensionFunction, |
| 66 public net::URLFetcherDelegate { |
| 67 public: |
| 68 DECLARE_EXTENSION_FUNCTION_NAME("experimental.wallpaperManager.setWallpaper"); |
| 69 |
| 70 protected: |
| 71 virtual ~WallpaperManagerSetWallpaperFunction(); |
| 72 |
| 73 // SyncExtensionFunction overrides. |
| 74 virtual bool RunImpl() OVERRIDE; |
| 75 |
| 76 private: |
| 77 |
| 78 // URLFetcherDelegate overrides: |
| 79 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 80 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 81 int64 current, |
| 82 int64 total) OVERRIDE; |
| 83 |
| 84 // Requests wallpaper from local file if cached. |
| 85 void RequestOnFileThread(const std::string& source_url); |
| 86 |
| 87 // Setups the url_fetcher on UI thread. |
| 88 void SetupFetcherOnUIThread(const GURL& wallpaper_url); |
| 89 |
| 90 // Returns wallpaper manager specific error code. |
| 91 WallpaperErrorCode GetErrorCode(const net::URLFetcher* source) const; |
| 92 |
| 93 // Dispatch DownloadErrorEvent to wallpaper manager extension. |
| 94 void DispatchErrorEvent(WallpaperErrorCode code); |
| 95 |
| 96 // Creates directory wallpaper will be downloaded to. |
| 97 bool CreateDirectory(const FilePath& path); |
| 98 |
| 99 FilePath wallpaper_dir_; |
| 100 scoped_ptr<net::URLFetcher> fetcher_; |
| 101 |
| 102 base::TimeTicks tick_wallpaper_download_start_; |
| 103 int64 bytes_wallpaper_download_progress_last_reported_; |
| 104 }; |
29 | 105 |
30 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ | 106 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |
OLD | NEW |