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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
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/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" | 19 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" |
20 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 20 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" |
21 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/extensions/update_manifest.h" | 22 #include "chrome/common/extensions/update_manifest.h" |
23 #include "content/public/common/url_fetcher_delegate.h" | |
24 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 24 #include "net/url_request/url_fetcher_delegate.h" |
25 | 25 |
26 class Version; | 26 class Version; |
27 | 27 |
28 namespace net { | 28 namespace net { |
| 29 class URLFetcher; |
29 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
30 class URLRequestStatus; | 31 class URLRequestStatus; |
31 } | 32 } |
32 | 33 |
33 namespace extensions { | 34 namespace extensions { |
34 | 35 |
35 class ExtensionUpdaterTest; | 36 class ExtensionUpdaterTest; |
36 | 37 |
37 // A class that checks for updates of a given list of extensions, and downloads | 38 // A class that checks for updates of a given list of extensions, and downloads |
38 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| | 39 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| |
39 // that takes ownership of the downloaded crx files, and handles events during | 40 // that takes ownership of the downloaded crx files, and handles events during |
40 // the update check. | 41 // the update check. |
41 class ExtensionDownloader : public content::URLFetcherDelegate { | 42 class ExtensionDownloader : public net::URLFetcherDelegate { |
42 public: | 43 public: |
43 // |delegate| is stored as a raw pointer and must outlive the | 44 // |delegate| is stored as a raw pointer and must outlive the |
44 // ExtensionDownloader. | 45 // ExtensionDownloader. |
45 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, | 46 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, |
46 net::URLRequestContextGetter* request_context); | 47 net::URLRequestContextGetter* request_context); |
47 virtual ~ExtensionDownloader(); | 48 virtual ~ExtensionDownloader(); |
48 | 49 |
49 // Adds |extension| to the list of extensions to check for updates. | 50 // Adds |extension| to the list of extensions to check for updates. |
50 // Returns false if the |extension| can't be updated due to invalid details. | 51 // Returns false if the |extension| can't be updated due to invalid details. |
51 // In that case, no callbacks will be performed on the |delegate_|. | 52 // In that case, no callbacks will be performed on the |delegate_|. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 Extension::Type extension_type, | 112 Extension::Type extension_type, |
112 GURL update_url, | 113 GURL update_url, |
113 const std::string& update_url_data); | 114 const std::string& update_url_data); |
114 | 115 |
115 // Adds all recorded stats taken so far to histogram counts. | 116 // Adds all recorded stats taken so far to histogram counts. |
116 void ReportStats() const; | 117 void ReportStats() const; |
117 | 118 |
118 // Begins an update check. Takes ownership of |fetch_data|. | 119 // Begins an update check. Takes ownership of |fetch_data|. |
119 void StartUpdateCheck(ManifestFetchData* fetch_data); | 120 void StartUpdateCheck(ManifestFetchData* fetch_data); |
120 | 121 |
121 // content::URLFetcherDelegate implementation. | 122 // net::URLFetcherDelegate implementation. |
122 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 123 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
123 | 124 |
124 // Handles the result of a manifest fetch. | 125 // Handles the result of a manifest fetch. |
125 void OnManifestFetchComplete(const GURL& url, | 126 void OnManifestFetchComplete(const GURL& url, |
126 const net::URLRequestStatus& status, | 127 const net::URLRequestStatus& status, |
127 int response_code, | 128 int response_code, |
128 const std::string& data); | 129 const std::string& data); |
129 | 130 |
130 // Once a manifest is parsed, this starts fetches of any relevant crx files. | 131 // Once a manifest is parsed, this starts fetches of any relevant crx files. |
131 // If |results| is null, it means something went wrong when parsing it. | 132 // If |results| is null, it means something went wrong when parsing it. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 URLStats url_stats_; | 174 URLStats url_stats_; |
174 | 175 |
175 // List of data on fetches we're going to do. We limit the number of | 176 // List of data on fetches we're going to do. We limit the number of |
176 // extensions grouped together in one batch to avoid running into the limits | 177 // extensions grouped together in one batch to avoid running into the limits |
177 // on the length of http GET requests, so there might be multiple | 178 // on the length of http GET requests, so there might be multiple |
178 // ManifestFetchData* objects with the same base_url. | 179 // ManifestFetchData* objects with the same base_url. |
179 typedef std::map<GURL, std::vector<ManifestFetchData*> > FetchMap; | 180 typedef std::map<GURL, std::vector<ManifestFetchData*> > FetchMap; |
180 FetchMap fetches_preparing_; | 181 FetchMap fetches_preparing_; |
181 | 182 |
182 // Outstanding url fetch requests for manifests and updates. | 183 // Outstanding url fetch requests for manifests and updates. |
183 scoped_ptr<content::URLFetcher> manifest_fetcher_; | 184 scoped_ptr<net::URLFetcher> manifest_fetcher_; |
184 scoped_ptr<content::URLFetcher> extension_fetcher_; | 185 scoped_ptr<net::URLFetcher> extension_fetcher_; |
185 | 186 |
186 // Pending manifests and extensions to be fetched when the appropriate fetcher | 187 // Pending manifests and extensions to be fetched when the appropriate fetcher |
187 // is available. | 188 // is available. |
188 std::deque<ManifestFetchData*> manifests_pending_; | 189 std::deque<ManifestFetchData*> manifests_pending_; |
189 std::deque<ExtensionFetch> extensions_pending_; | 190 std::deque<ExtensionFetch> extensions_pending_; |
190 | 191 |
191 // The manifest currently being fetched (if any). | 192 // The manifest currently being fetched (if any). |
192 scoped_ptr<ManifestFetchData> current_manifest_fetch_; | 193 scoped_ptr<ManifestFetchData> current_manifest_fetch_; |
193 | 194 |
194 // The extension currently being fetched (if any). | 195 // The extension currently being fetched (if any). |
195 ExtensionFetch current_extension_fetch_; | 196 ExtensionFetch current_extension_fetch_; |
196 | 197 |
197 // Maps an extension-id to its PingResult data. | 198 // Maps an extension-id to its PingResult data. |
198 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; | 199 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; |
199 | 200 |
200 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 201 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
201 }; | 202 }; |
202 | 203 |
203 } // namespace extensions | 204 } // namespace extensions |
204 | 205 |
205 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 206 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
OLD | NEW |