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_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/version.h" | 20 #include "base/version.h" |
21 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" | 21 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" |
22 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 22 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" |
23 #include "chrome/browser/extensions/updater/request_queue.h" | 23 #include "chrome/browser/extensions/updater/request_queue.h" |
24 #include "chrome/common/extensions/update_manifest.h" | 24 #include "chrome/common/extensions/update_manifest.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "net/url_request/url_fetcher_delegate.h" | 26 #include "net/url_request/url_fetcher_delegate.h" |
27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
28 | 28 |
| 29 class IdentityProvider; |
| 30 |
29 namespace net { | 31 namespace net { |
30 class URLFetcher; | 32 class URLFetcher; |
31 class URLRequestContextGetter; | 33 class URLRequestContextGetter; |
32 class URLRequestStatus; | 34 class URLRequestStatus; |
33 } | 35 } |
34 | 36 |
35 namespace extensions { | 37 namespace extensions { |
36 | 38 |
37 struct UpdateDetails { | 39 struct UpdateDetails { |
38 UpdateDetails(const std::string& id, const base::Version& version); | 40 UpdateDetails(const std::string& id, const base::Version& version); |
39 ~UpdateDetails(); | 41 ~UpdateDetails(); |
40 | 42 |
41 std::string id; | 43 std::string id; |
42 base::Version version; | 44 base::Version version; |
43 }; | 45 }; |
44 | 46 |
45 class ExtensionCache; | 47 class ExtensionCache; |
46 class ExtensionUpdaterTest; | 48 class ExtensionUpdaterTest; |
| 49 class WebstoreOAuth2TokenProvider; |
47 | 50 |
48 // A class that checks for updates of a given list of extensions, and downloads | 51 // A class that checks for updates of a given list of extensions, and downloads |
49 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| | 52 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| |
50 // that takes ownership of the downloaded crx files, and handles events during | 53 // that takes ownership of the downloaded crx files, and handles events during |
51 // the update check. | 54 // the update check. |
52 class ExtensionDownloader : public net::URLFetcherDelegate { | 55 class ExtensionDownloader : public net::URLFetcherDelegate { |
53 public: | 56 public: |
54 // |delegate| is stored as a raw pointer and must outlive the | 57 // |delegate| is stored as a raw pointer and must outlive the |
55 // ExtensionDownloader. | 58 // ExtensionDownloader. |webstore_identity_provider| may be NULL if this |
| 59 // ExtensionDownloader does not need OAuth2 support; if not NULL, the |
| 60 // given IdentityProvider must outlive this ExtensionDownloader. |
56 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, | 61 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, |
57 net::URLRequestContextGetter* request_context); | 62 net::URLRequestContextGetter* request_context, |
| 63 IdentityProvider* webstore_identity_provider); |
58 virtual ~ExtensionDownloader(); | 64 virtual ~ExtensionDownloader(); |
59 | 65 |
60 // Adds |extension| to the list of extensions to check for updates. | 66 // Adds |extension| to the list of extensions to check for updates. |
61 // Returns false if the |extension| can't be updated due to invalid details. | 67 // Returns false if the |extension| can't be updated due to invalid details. |
62 // In that case, no callbacks will be performed on the |delegate_|. | 68 // In that case, no callbacks will be performed on the |delegate_|. |
63 // The |request_id| is passed on as is to the various |delegate_| callbacks. | 69 // The |request_id| is passed on as is to the various |delegate_| callbacks. |
64 // This is used for example by ExtensionUpdater to keep track of when | 70 // This is used for example by ExtensionUpdater to keep track of when |
65 // potentially concurrent update checks complete. | 71 // potentially concurrent update checks complete. |
66 bool AddExtension(const Extension& extension, int request_id); | 72 bool AddExtension(const Extension& extension, int request_id); |
67 | 73 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 123 |
118 // We need to keep track of some information associated with a url | 124 // We need to keep track of some information associated with a url |
119 // when doing a fetch. | 125 // when doing a fetch. |
120 struct ExtensionFetch { | 126 struct ExtensionFetch { |
121 ExtensionFetch(); | 127 ExtensionFetch(); |
122 ExtensionFetch(const std::string& id, const GURL& url, | 128 ExtensionFetch(const std::string& id, const GURL& url, |
123 const std::string& package_hash, const std::string& version, | 129 const std::string& package_hash, const std::string& version, |
124 const std::set<int>& request_ids); | 130 const std::set<int>& request_ids); |
125 ~ExtensionFetch(); | 131 ~ExtensionFetch(); |
126 | 132 |
| 133 // Potentially updates this fetch's authentication state and returns |true| |
| 134 // if the fetch should be retried. Returns |false| if the failure was not |
| 135 // related to authentication, leaving the ExtensionFetch data unmodified. |
| 136 bool IterateCredentialsAfterFailure(const net::URLRequestStatus& status, |
| 137 int response_code, |
| 138 bool support_oauth2); |
| 139 |
127 std::string id; | 140 std::string id; |
128 GURL url; | 141 GURL url; |
129 std::string package_hash; | 142 std::string package_hash; |
130 std::string version; | 143 std::string version; |
131 std::set<int> request_ids; | 144 std::set<int> request_ids; |
132 | 145 |
133 // Indicates whether or not the fetch is known to require credentials. | 146 enum CredentialsMode { |
134 bool is_protected; | 147 CREDENTIALS_NONE = 0, |
| 148 CREDENTIALS_OAUTH2_TOKEN, |
| 149 CREDENTIALS_COOKIES, |
| 150 }; |
| 151 |
| 152 // Indicates the type of credentials to include with this fetch. |
| 153 CredentialsMode credentials; |
135 }; | 154 }; |
136 | 155 |
137 // Helper for AddExtension() and AddPendingExtension(). | 156 // Helper for AddExtension() and AddPendingExtension(). |
138 bool AddExtensionData(const std::string& id, | 157 bool AddExtensionData(const std::string& id, |
139 const base::Version& version, | 158 const base::Version& version, |
140 Manifest::Type extension_type, | 159 Manifest::Type extension_type, |
141 const GURL& extension_update_url, | 160 const GURL& extension_update_url, |
142 const std::string& update_url_data, | 161 const std::string& update_url_data, |
143 int request_id); | 162 int request_id); |
144 | 163 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 216 |
198 // Do real work of StartAllPending. If .crx cache is used, this function | 217 // Do real work of StartAllPending. If .crx cache is used, this function |
199 // is called when cache is ready. | 218 // is called when cache is ready. |
200 void DoStartAllPending(); | 219 void DoStartAllPending(); |
201 | 220 |
202 // Notify delegate and remove ping results. | 221 // Notify delegate and remove ping results. |
203 void NotifyDelegateDownloadFinished(scoped_ptr<ExtensionFetch> fetch_data, | 222 void NotifyDelegateDownloadFinished(scoped_ptr<ExtensionFetch> fetch_data, |
204 const base::FilePath& crx_path, | 223 const base::FilePath& crx_path, |
205 bool file_ownership_passed); | 224 bool file_ownership_passed); |
206 | 225 |
| 226 // Receives an OAuth2 token to authenticate a Webstore CRX fetch. |
| 227 void OnWebstoreOAuth2TokenReceived(bool success, const std::string& token); |
| 228 |
207 // The delegate that receives the crx files downloaded by the | 229 // The delegate that receives the crx files downloaded by the |
208 // ExtensionDownloader, and that fills in optional ping and update url data. | 230 // ExtensionDownloader, and that fills in optional ping and update url data. |
209 ExtensionDownloaderDelegate* delegate_; | 231 ExtensionDownloaderDelegate* delegate_; |
210 | 232 |
211 // The request context to use for the URLFetchers. | 233 // The request context to use for the URLFetchers. |
212 scoped_refptr<net::URLRequestContextGetter> request_context_; | 234 scoped_refptr<net::URLRequestContextGetter> request_context_; |
213 | 235 |
214 // Used to create WeakPtrs to |this|. | 236 // Used to create WeakPtrs to |this|. |
215 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; | 237 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; |
216 | 238 |
(...skipping 16 matching lines...) Expand all Loading... |
233 // is available. | 255 // is available. |
234 RequestQueue<ManifestFetchData> manifests_queue_; | 256 RequestQueue<ManifestFetchData> manifests_queue_; |
235 RequestQueue<ExtensionFetch> extensions_queue_; | 257 RequestQueue<ExtensionFetch> extensions_queue_; |
236 | 258 |
237 // Maps an extension-id to its PingResult data. | 259 // Maps an extension-id to its PingResult data. |
238 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; | 260 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; |
239 | 261 |
240 // Cache for .crx files. | 262 // Cache for .crx files. |
241 ExtensionCache* extension_cache_; | 263 ExtensionCache* extension_cache_; |
242 | 264 |
| 265 // Acquires access tokens for webstore download URLs. |
| 266 scoped_ptr<WebstoreOAuth2TokenProvider> webstore_token_provider_; |
| 267 |
243 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 268 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
244 }; | 269 }; |
245 | 270 |
246 } // namespace extensions | 271 } // namespace extensions |
247 | 272 |
248 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 273 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
OLD | NEW |