| 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 "google_apis/gaia/oauth2_token_service.h" |
| 26 #include "net/url_request/url_fetcher_delegate.h" | 27 #include "net/url_request/url_fetcher_delegate.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 28 | 29 |
| 30 class IdentityProvider; |
| 31 |
| 29 namespace net { | 32 namespace net { |
| 30 class URLFetcher; | 33 class URLFetcher; |
| 31 class URLRequestContextGetter; | 34 class URLRequestContextGetter; |
| 32 class URLRequestStatus; | 35 class URLRequestStatus; |
| 33 } | 36 } |
| 34 | 37 |
| 35 namespace extensions { | 38 namespace extensions { |
| 36 | 39 |
| 37 struct UpdateDetails { | 40 struct UpdateDetails { |
| 38 UpdateDetails(const std::string& id, const base::Version& version); | 41 UpdateDetails(const std::string& id, const base::Version& version); |
| 39 ~UpdateDetails(); | 42 ~UpdateDetails(); |
| 40 | 43 |
| 41 std::string id; | 44 std::string id; |
| 42 base::Version version; | 45 base::Version version; |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 class ExtensionCache; | 48 class ExtensionCache; |
| 46 class ExtensionUpdaterTest; | 49 class ExtensionUpdaterTest; |
| 50 class WebstoreOAuth2TokenProvider; |
| 47 | 51 |
| 48 // A class that checks for updates of a given list of extensions, and downloads | 52 // 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| | 53 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| |
| 50 // that takes ownership of the downloaded crx files, and handles events during | 54 // that takes ownership of the downloaded crx files, and handles events during |
| 51 // the update check. | 55 // the update check. |
| 52 class ExtensionDownloader : public net::URLFetcherDelegate { | 56 class ExtensionDownloader |
| 57 : public net::URLFetcherDelegate, |
| 58 public OAuth2TokenService::Consumer { |
| 53 public: | 59 public: |
| 54 // |delegate| is stored as a raw pointer and must outlive the | 60 // |delegate| is stored as a raw pointer and must outlive the |
| 55 // ExtensionDownloader. | 61 // ExtensionDownloader. |webstore_identity_provider| may be NULL if this |
| 62 // ExtensionDownloader does not need OAuth2 support; if not NULL, the |
| 63 // given IdentityProvider must outlive this ExtensionDownloader. |
| 56 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, | 64 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, |
| 57 net::URLRequestContextGetter* request_context); | 65 net::URLRequestContextGetter* request_context, |
| 66 IdentityProvider* webstore_identity_provider); |
| 58 virtual ~ExtensionDownloader(); | 67 virtual ~ExtensionDownloader(); |
| 59 | 68 |
| 60 // Adds |extension| to the list of extensions to check for updates. | 69 // 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. | 70 // 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_|. | 71 // 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. | 72 // 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 | 73 // This is used for example by ExtensionUpdater to keep track of when |
| 65 // potentially concurrent update checks complete. | 74 // potentially concurrent update checks complete. |
| 66 bool AddExtension(const Extension& extension, int request_id); | 75 bool AddExtension(const Extension& extension, int request_id); |
| 67 | 76 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 const std::string& package_hash, const std::string& version, | 132 const std::string& package_hash, const std::string& version, |
| 124 const std::set<int>& request_ids); | 133 const std::set<int>& request_ids); |
| 125 ~ExtensionFetch(); | 134 ~ExtensionFetch(); |
| 126 | 135 |
| 127 std::string id; | 136 std::string id; |
| 128 GURL url; | 137 GURL url; |
| 129 std::string package_hash; | 138 std::string package_hash; |
| 130 std::string version; | 139 std::string version; |
| 131 std::set<int> request_ids; | 140 std::set<int> request_ids; |
| 132 | 141 |
| 133 // Indicates whether or not the fetch is known to require credentials. | 142 enum CredentialsMode { |
| 134 bool is_protected; | 143 CREDENTIALS_NONE = 0, |
| 144 CREDENTIALS_OAUTH2_TOKEN, |
| 145 CREDENTIALS_COOKIES, |
| 146 }; |
| 147 |
| 148 // Indicates the type of credentials to include with this fetch. |
| 149 CredentialsMode credentials; |
| 135 }; | 150 }; |
| 136 | 151 |
| 137 // Helper for AddExtension() and AddPendingExtension(). | 152 // Helper for AddExtension() and AddPendingExtension(). |
| 138 bool AddExtensionData(const std::string& id, | 153 bool AddExtensionData(const std::string& id, |
| 139 const base::Version& version, | 154 const base::Version& version, |
| 140 Manifest::Type extension_type, | 155 Manifest::Type extension_type, |
| 141 const GURL& extension_update_url, | 156 const GURL& extension_update_url, |
| 142 const std::string& update_url_data, | 157 const std::string& update_url_data, |
| 143 int request_id); | 158 int request_id); |
| 144 | 159 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 212 |
| 198 // Do real work of StartAllPending. If .crx cache is used, this function | 213 // Do real work of StartAllPending. If .crx cache is used, this function |
| 199 // is called when cache is ready. | 214 // is called when cache is ready. |
| 200 void DoStartAllPending(); | 215 void DoStartAllPending(); |
| 201 | 216 |
| 202 // Notify delegate and remove ping results. | 217 // Notify delegate and remove ping results. |
| 203 void NotifyDelegateDownloadFinished(scoped_ptr<ExtensionFetch> fetch_data, | 218 void NotifyDelegateDownloadFinished(scoped_ptr<ExtensionFetch> fetch_data, |
| 204 const base::FilePath& crx_path, | 219 const base::FilePath& crx_path, |
| 205 bool file_ownership_passed); | 220 bool file_ownership_passed); |
| 206 | 221 |
| 222 // Potentially updates an ExtensionFetch's authentication state and returns |
| 223 // |true| if the fetch should be retried. Returns |false| if the failure was |
| 224 // not related to authentication, leaving the ExtensionFetch data unmodified. |
| 225 bool IterateFetchCredentialsAfterFailure(ExtensionFetch* fetch, |
| 226 const net::URLRequestStatus& status, |
| 227 int response_code); |
| 228 |
| 229 // OAuth2TokenService::Consumer implementation. |
| 230 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 231 const std::string& access_token, |
| 232 const base::Time& expiration_time) OVERRIDE; |
| 233 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 234 const GoogleServiceAuthError& error) OVERRIDE; |
| 235 |
| 207 // The delegate that receives the crx files downloaded by the | 236 // The delegate that receives the crx files downloaded by the |
| 208 // ExtensionDownloader, and that fills in optional ping and update url data. | 237 // ExtensionDownloader, and that fills in optional ping and update url data. |
| 209 ExtensionDownloaderDelegate* delegate_; | 238 ExtensionDownloaderDelegate* delegate_; |
| 210 | 239 |
| 211 // The request context to use for the URLFetchers. | 240 // The request context to use for the URLFetchers. |
| 212 scoped_refptr<net::URLRequestContextGetter> request_context_; | 241 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 213 | 242 |
| 214 // Used to create WeakPtrs to |this|. | 243 // Used to create WeakPtrs to |this|. |
| 215 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; | 244 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; |
| 216 | 245 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 233 // is available. | 262 // is available. |
| 234 RequestQueue<ManifestFetchData> manifests_queue_; | 263 RequestQueue<ManifestFetchData> manifests_queue_; |
| 235 RequestQueue<ExtensionFetch> extensions_queue_; | 264 RequestQueue<ExtensionFetch> extensions_queue_; |
| 236 | 265 |
| 237 // Maps an extension-id to its PingResult data. | 266 // Maps an extension-id to its PingResult data. |
| 238 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; | 267 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; |
| 239 | 268 |
| 240 // Cache for .crx files. | 269 // Cache for .crx files. |
| 241 ExtensionCache* extension_cache_; | 270 ExtensionCache* extension_cache_; |
| 242 | 271 |
| 272 // An IdentityProvider which may be used for authentication on protected |
| 273 // download requests. May be NULL. |
| 274 IdentityProvider* identity_provider_; |
| 275 |
| 276 // A Webstore download-scoped access token for the |
| 277 // |webstore_identity_provider_|'s active account, if any. |
| 278 std::string access_token_; |
| 279 |
| 280 // A pending token fetch request. |
| 281 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 282 |
| 243 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 283 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
| 244 }; | 284 }; |
| 245 | 285 |
| 246 } // namespace extensions | 286 } // namespace extensions |
| 247 | 287 |
| 248 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 288 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
| OLD | NEW |