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 EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 6 #define EXTENSIONS_BROWSER_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 "extensions/browser/updater/extension_downloader_delegate.h" |
22 #include "extensions/browser/updater/manifest_fetch_data.h" | 22 #include "extensions/browser/updater/manifest_fetch_data.h" |
23 #include "extensions/browser/updater/request_queue.h" | 23 #include "extensions/browser/updater/request_queue.h" |
24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
25 #include "extensions/common/update_manifest.h" | 25 #include "extensions/common/update_manifest.h" |
26 #include "google_apis/gaia/oauth2_token_service.h" | 26 #include "google_apis/gaia/oauth2_token_service.h" |
27 #include "net/url_request/url_fetcher_delegate.h" | 27 #include "net/url_request/url_fetcher_delegate.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 class IdentityProvider; | 30 class IdentityProvider; |
31 | 31 |
(...skipping 13 matching lines...) Expand all Loading... |
45 base::Version version; | 45 base::Version version; |
46 }; | 46 }; |
47 | 47 |
48 class ExtensionCache; | 48 class ExtensionCache; |
49 class ExtensionUpdaterTest; | 49 class ExtensionUpdaterTest; |
50 | 50 |
51 // 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 |
52 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| | 52 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| |
53 // 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 |
54 // the update check. | 54 // the update check. |
55 class ExtensionDownloader | 55 class ExtensionDownloader : public net::URLFetcherDelegate, |
56 : public net::URLFetcherDelegate, | 56 public OAuth2TokenService::Consumer { |
57 public OAuth2TokenService::Consumer { | |
58 public: | 57 public: |
59 // A closure which constructs a new ExtensionDownloader to be owned by the | 58 // A closure which constructs a new ExtensionDownloader to be owned by the |
60 // caller. | 59 // caller. |
61 typedef base::Callback< | 60 typedef base::Callback<scoped_ptr<ExtensionDownloader>( |
62 scoped_ptr<ExtensionDownloader>(ExtensionDownloaderDelegate* delegate)> | 61 ExtensionDownloaderDelegate* delegate)> Factory; |
63 Factory; | |
64 | 62 |
65 // |delegate| is stored as a raw pointer and must outlive the | 63 // |delegate| is stored as a raw pointer and must outlive the |
66 // ExtensionDownloader. | 64 // ExtensionDownloader. |
67 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, | 65 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, |
68 net::URLRequestContextGetter* request_context); | 66 net::URLRequestContextGetter* request_context); |
69 virtual ~ExtensionDownloader(); | 67 virtual ~ExtensionDownloader(); |
70 | 68 |
71 // Adds |extension| to the list of extensions to check for updates. | 69 // Adds |extension| to the list of extensions to check for updates. |
72 // 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. |
73 // In that case, no callbacks will be performed on the |delegate_|. | 71 // In that case, no callbacks will be performed on the |delegate_|. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 142 |
145 int no_url_count, google_url_count, other_url_count; | 143 int no_url_count, google_url_count, other_url_count; |
146 int extension_count, theme_count, app_count, platform_app_count, | 144 int extension_count, theme_count, app_count, platform_app_count, |
147 pending_count; | 145 pending_count; |
148 }; | 146 }; |
149 | 147 |
150 // We need to keep track of some information associated with a url | 148 // We need to keep track of some information associated with a url |
151 // when doing a fetch. | 149 // when doing a fetch. |
152 struct ExtensionFetch { | 150 struct ExtensionFetch { |
153 ExtensionFetch(); | 151 ExtensionFetch(); |
154 ExtensionFetch(const std::string& id, const GURL& url, | 152 ExtensionFetch(const std::string& id, |
155 const std::string& package_hash, const std::string& version, | 153 const GURL& url, |
| 154 const std::string& package_hash, |
| 155 const std::string& version, |
156 const std::set<int>& request_ids); | 156 const std::set<int>& request_ids); |
157 ~ExtensionFetch(); | 157 ~ExtensionFetch(); |
158 | 158 |
159 std::string id; | 159 std::string id; |
160 GURL url; | 160 GURL url; |
161 std::string package_hash; | 161 std::string package_hash; |
162 std::string version; | 162 std::string version; |
163 std::set<int> request_ids; | 163 std::set<int> request_ids; |
164 | 164 |
165 enum CredentialsMode { | 165 enum CredentialsMode { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 scoped_refptr<net::URLRequestContextGetter> request_context_; | 273 scoped_refptr<net::URLRequestContextGetter> request_context_; |
274 | 274 |
275 // Collects UMA samples that are reported when ReportStats() is called. | 275 // Collects UMA samples that are reported when ReportStats() is called. |
276 URLStats url_stats_; | 276 URLStats url_stats_; |
277 | 277 |
278 // List of data on fetches we're going to do. We limit the number of | 278 // List of data on fetches we're going to do. We limit the number of |
279 // extensions grouped together in one batch to avoid running into the limits | 279 // extensions grouped together in one batch to avoid running into the limits |
280 // on the length of http GET requests, so there might be multiple | 280 // on the length of http GET requests, so there might be multiple |
281 // ManifestFetchData* objects with the same base_url. | 281 // ManifestFetchData* objects with the same base_url. |
282 typedef std::map<std::pair<int, GURL>, | 282 typedef std::map<std::pair<int, GURL>, |
283 std::vector<linked_ptr<ManifestFetchData> > > FetchMap; | 283 std::vector<linked_ptr<ManifestFetchData>>> FetchMap; |
284 FetchMap fetches_preparing_; | 284 FetchMap fetches_preparing_; |
285 | 285 |
286 // Outstanding url fetch requests for manifests and updates. | 286 // Outstanding url fetch requests for manifests and updates. |
287 scoped_ptr<net::URLFetcher> manifest_fetcher_; | 287 scoped_ptr<net::URLFetcher> manifest_fetcher_; |
288 scoped_ptr<net::URLFetcher> extension_fetcher_; | 288 scoped_ptr<net::URLFetcher> extension_fetcher_; |
289 | 289 |
290 // Pending manifests and extensions to be fetched when the appropriate fetcher | 290 // Pending manifests and extensions to be fetched when the appropriate fetcher |
291 // is available. | 291 // is available. |
292 RequestQueue<ManifestFetchData> manifests_queue_; | 292 RequestQueue<ManifestFetchData> manifests_queue_; |
293 RequestQueue<ExtensionFetch> extensions_queue_; | 293 RequestQueue<ExtensionFetch> extensions_queue_; |
(...skipping 30 matching lines...) Expand all Loading... |
324 bool enable_extra_update_metrics_; | 324 bool enable_extra_update_metrics_; |
325 | 325 |
326 // Used to create WeakPtrs to |this|. | 326 // Used to create WeakPtrs to |this|. |
327 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; | 327 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; |
328 | 328 |
329 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 329 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
330 }; | 330 }; |
331 | 331 |
332 } // namespace extensions | 332 } // namespace extensions |
333 | 333 |
334 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 334 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ |
OLD | NEW |