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 "ash/desktop_background/desktop_background_resources.h" | |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | |
11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
12 #include "base/time.h" | 14 #include "base/time.h" |
13 #include "chrome/browser/extensions/extension_function.h" | 15 #include "chrome/browser/extensions/extension_function.h" |
14 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
15 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
16 | 18 |
17 extern const char kWallpaperManagerDomain[]; | 19 extern const char kWallpaperManagerDomain[]; |
18 | 20 |
21 namespace { | |
22 | |
23 enum WallpaperErrorCode { | |
24 HTTP_SUCCESS = 200, | |
25 HTTP_CREATED = 201, | |
26 HTTP_FOUND = 302, | |
27 HTTP_NOT_MODIFIED = 304, | |
28 HTTP_RESUME_INCOMPLETE = 308, | |
29 HTTP_BAD_REQUEST = 400, | |
30 HTTP_UNAUTHORIZED = 401, | |
31 HTTP_FORBIDDEN = 403, | |
32 HTTP_NOT_FOUND = 404, | |
33 HTTP_CONFLICT = 409, | |
34 HTTP_LENGTH_REQUIRED = 411, | |
35 HTTP_PRECONDITION = 412, | |
36 HTTP_INTERNAL_SERVER_ERROR = 500, | |
37 HTTP_SERVICE_UNAVAILABLE = 503, | |
38 WALLPAPER_NO_CONNECTION = -100, | |
39 WALLPAPER_FILE_ERROR = -101, | |
40 }; | |
41 | |
42 const int64 kBytesWallpaperDownloadProgressReportInterval = 10240; | |
43 | |
44 } // namespace | |
45 | |
19 namespace wallpaper_manager_util { | 46 namespace wallpaper_manager_util { |
20 | 47 |
21 // Opens wallpaper manager application. | 48 // Opens wallpaper manager application. |
22 void OpenWallpaperManager(); | 49 void OpenWallpaperManager(); |
23 | 50 |
24 } // namespace wallpaper_manager_util | 51 } // namespace wallpaper_manager_util |
25 | 52 |
53 // Wallpaper manager strings. | |
54 class WallpaperManagerStringsFunction : public SyncExtensionFunction { | |
55 public: | |
56 DECLARE_EXTENSION_FUNCTION_NAME("experimental.wallpaperManager.getStrings"); | |
26 | 57 |
27 // Wallpaper manager API functions. Followup CL will add implementations of | 58 protected: |
28 // some API functions. | 59 virtual ~WallpaperManagerStringsFunction() {} |
60 | |
61 // SyncExtensionFunction overrides. | |
62 virtual bool RunImpl() OVERRIDE; | |
63 }; | |
64 | |
65 // Sets wallpaper to the image downloaded from URL. | |
66 class WallpaperManagerSetWallpaperFunction : public AsyncExtensionFunction { | |
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 // This class is a wrapper class for URLFetcher. It has a ref counted pointer | |
78 // to class WallpaperManagerSetWallpaperFunction. So the instance of that | |
79 // class did not delete itself before fetching complete. | |
80 class WallpaperFetcher : public net::URLFetcherDelegate { | |
81 public: | |
82 explicit WallpaperFetcher( | |
83 scoped_refptr<WallpaperManagerSetWallpaperFunction> function); | |
84 | |
85 void Start(const GURL& wallpaper_url, | |
86 const FilePath& file_path); | |
87 | |
88 private: | |
89 // URLFetcherDelegate overrides: | |
90 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE ; | |
91 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | |
92 int64 current, | |
93 int64 total) OVERRIDE; | |
94 | |
95 scoped_refptr<WallpaperManagerSetWallpaperFunction> function_; | |
96 scoped_ptr<net::URLFetcher> fetcher_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(WallpaperFetcher); | |
99 }; | |
100 | |
101 void OnDownloadComplete(const net::URLFetcher* source); | |
102 void OnDownloadProgress(const net::URLFetcher* source, | |
103 int64 current, | |
104 int64 total); | |
105 | |
106 // Requests wallpaper from local file if cached. | |
107 void RequestOnFileThread(const std::string& source_url); | |
108 | |
109 // 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.
| |
110 void SetupFetcherOnUIThread(const GURL& wallpaper_url); | |
111 | |
112 // Returns wallpaper manager specific error code. | |
113 WallpaperErrorCode GetErrorCode(const net::URLFetcher* source) const; | |
114 | |
115 // Dispatch DownloadErrorEvent to wallpaper manager extension. | |
116 void DispatchErrorEvent(WallpaperErrorCode code); | |
117 | |
118 // Creates directory wallpaper will be downloaded to. | |
119 bool CreateDirectory(const FilePath& path); | |
120 | |
121 FilePath wallpaper_dir_; | |
122 ash::WallpaperLayout layout_; | |
123 scoped_ptr<WallpaperFetcher> fetcher_; | |
124 // The email address of logged in user. | |
125 std::string email_; | |
126 | |
127 base::TimeTicks tick_wallpaper_download_start_; | |
128 int64 bytes_wallpaper_download_progress_last_reported_; | |
129 }; | |
29 | 130 |
30 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ | 131 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_ |
OLD | NEW |