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 EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ | 5 #ifndef EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ |
6 #define EXTENSIONS_BROWSER_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 <memory> | 10 #include <memory> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // ExtensionDownloader. | 65 // ExtensionDownloader. |
66 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, | 66 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, |
67 net::URLRequestContextGetter* request_context); | 67 net::URLRequestContextGetter* request_context); |
68 ~ExtensionDownloader() override; | 68 ~ExtensionDownloader() override; |
69 | 69 |
70 // Adds |extension| to the list of extensions to check for updates. | 70 // Adds |extension| to the list of extensions to check for updates. |
71 // Returns false if the |extension| can't be updated due to invalid details. | 71 // Returns false if the |extension| can't be updated due to invalid details. |
72 // In that case, no callbacks will be performed on the |delegate_|. | 72 // In that case, no callbacks will be performed on the |delegate_|. |
73 // The |request_id| is passed on as is to the various |delegate_| callbacks. | 73 // The |request_id| is passed on as is to the various |delegate_| callbacks. |
74 // This is used for example by ExtensionUpdater to keep track of when | 74 // This is used for example by ExtensionUpdater to keep track of when |
75 // potentially concurrent update checks complete. | 75 // potentially concurrent update checks complete. |fetch_priority| |
76 bool AddExtension(const Extension& extension, int request_id); | 76 // parameter notifies the downloader the priority of this extension update |
| 77 // (either foreground or background). |
| 78 bool AddExtension(const Extension& extension, |
| 79 int request_id, |
| 80 ManifestFetchData::FetchPriority fetch_priority); |
77 | 81 |
78 // Adds extension |id| to the list of extensions to check for updates. | 82 // Adds extension |id| to the list of extensions to check for updates. |
79 // Returns false if the |id| can't be updated due to invalid details. | 83 // Returns false if the |id| can't be updated due to invalid details. |
80 // In that case, no callbacks will be performed on the |delegate_|. | 84 // In that case, no callbacks will be performed on the |delegate_|. |
81 // The |request_id| is passed on as is to the various |delegate_| callbacks. | 85 // The |request_id| is passed on as is to the various |delegate_| callbacks. |
82 // This is used for example by ExtensionUpdater to keep track of when | 86 // This is used for example by ExtensionUpdater to keep track of when |
83 // potentially concurrent update checks complete. The |is_corrupt_reinstall| | 87 // potentially concurrent update checks complete. The |is_corrupt_reinstall| |
84 // parameter is used to indicate in the request that we detected corruption in | 88 // parameter is used to indicate in the request that we detected corruption in |
85 // the local copy of the extension and we want to perform a reinstall of it. | 89 // the local copy of the extension and we want to perform a reinstall of it. |
| 90 // |fetch_priority| parameter notifies the downloader the priority of this |
| 91 // extension update (either foreground or background). |
86 bool AddPendingExtension(const std::string& id, | 92 bool AddPendingExtension(const std::string& id, |
87 const GURL& update_url, | 93 const GURL& update_url, |
88 bool is_corrupt_reinstall, | 94 bool is_corrupt_reinstall, |
89 int request_id); | 95 int request_id, |
| 96 ManifestFetchData::FetchPriority fetch_priority); |
90 | 97 |
91 // Schedules a fetch of the manifest of all the extensions added with | 98 // Schedules a fetch of the manifest of all the extensions added with |
92 // AddExtension() and AddPendingExtension(). | 99 // AddExtension() and AddPendingExtension(). |
93 void StartAllPending(ExtensionCache* cache); | 100 void StartAllPending(ExtensionCache* cache); |
94 | 101 |
95 // Schedules an update check of the blacklist. | 102 // Schedules an update check of the blacklist. |
96 void StartBlacklistUpdate(const std::string& version, | 103 void StartBlacklistUpdate(const std::string& version, |
97 const ManifestFetchData::PingData& ping_data, | 104 const ManifestFetchData::PingData& ping_data, |
98 int request_id); | 105 int request_id); |
99 | 106 |
(...skipping 21 matching lines...) Expand all Loading... |
121 // These are needed for unit testing, to help identify the correct mock | 128 // These are needed for unit testing, to help identify the correct mock |
122 // URLFetcher objects. | 129 // URLFetcher objects. |
123 static const int kManifestFetcherId = 1; | 130 static const int kManifestFetcherId = 1; |
124 static const int kExtensionFetcherId = 2; | 131 static const int kExtensionFetcherId = 2; |
125 | 132 |
126 // Update AppID for extension blacklist. | 133 // Update AppID for extension blacklist. |
127 static const char kBlacklistAppID[]; | 134 static const char kBlacklistAppID[]; |
128 | 135 |
129 static const int kMaxRetries = 10; | 136 static const int kMaxRetries = 10; |
130 | 137 |
| 138 // Names of the header fields used for traffic management for extension |
| 139 // updater. |
| 140 static const char kUpdateInteractivityHeader[]; |
| 141 static const char kUpdateAppIdHeader[]; |
| 142 static const char kUpdateUpdaterHeader[]; |
| 143 |
| 144 // Header values for foreground/background update requests. |
| 145 static const char kUpdateInteractivityForeground[]; |
| 146 static const char kUpdateInteractivityBackground[]; |
| 147 |
131 private: | 148 private: |
132 friend class ExtensionUpdaterTest; | 149 friend class ExtensionUpdaterTest; |
133 | 150 |
134 // These counters are bumped as extensions are added to be fetched. They | 151 // These counters are bumped as extensions are added to be fetched. They |
135 // are then recorded as UMA metrics when all the extensions have been added. | 152 // are then recorded as UMA metrics when all the extensions have been added. |
136 struct URLStats { | 153 struct URLStats { |
137 URLStats() | 154 URLStats() |
138 : no_url_count(0), | 155 : no_url_count(0), |
139 google_url_count(0), | 156 google_url_count(0), |
140 other_url_count(0), | 157 other_url_count(0), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 207 |
191 ExtraParams(); | 208 ExtraParams(); |
192 }; | 209 }; |
193 | 210 |
194 // Helper for AddExtension() and AddPendingExtension(). | 211 // Helper for AddExtension() and AddPendingExtension(). |
195 bool AddExtensionData(const std::string& id, | 212 bool AddExtensionData(const std::string& id, |
196 const base::Version& version, | 213 const base::Version& version, |
197 Manifest::Type extension_type, | 214 Manifest::Type extension_type, |
198 const GURL& extension_update_url, | 215 const GURL& extension_update_url, |
199 const ExtraParams& extra, | 216 const ExtraParams& extra, |
200 int request_id); | 217 int request_id, |
| 218 ManifestFetchData::FetchPriority fetch_priority); |
201 | 219 |
202 // Adds all recorded stats taken so far to histogram counts. | 220 // Adds all recorded stats taken so far to histogram counts. |
203 void ReportStats() const; | 221 void ReportStats() const; |
204 | 222 |
205 // Begins an update check. | 223 // Begins an update check. |
206 void StartUpdateCheck(std::unique_ptr<ManifestFetchData> fetch_data); | 224 void StartUpdateCheck(std::unique_ptr<ManifestFetchData> fetch_data); |
207 | 225 |
208 // Called by RequestQueue when a new manifest fetch request is started. | 226 // Called by RequestQueue when a new manifest fetch request is started. |
209 void CreateManifestFetcher(); | 227 void CreateManifestFetcher(); |
210 | 228 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 const net::URLRequestStatus& status, | 293 const net::URLRequestStatus& status, |
276 int response_code); | 294 int response_code); |
277 | 295 |
278 // OAuth2TokenService::Consumer implementation. | 296 // OAuth2TokenService::Consumer implementation. |
279 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 297 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
280 const std::string& access_token, | 298 const std::string& access_token, |
281 const base::Time& expiration_time) override; | 299 const base::Time& expiration_time) override; |
282 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 300 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
283 const GoogleServiceAuthError& error) override; | 301 const GoogleServiceAuthError& error) override; |
284 | 302 |
285 ManifestFetchData* CreateManifestFetchData(const GURL& update_url, | 303 ManifestFetchData* CreateManifestFetchData( |
286 int request_id); | 304 const GURL& update_url, |
| 305 int request_id, |
| 306 ManifestFetchData::FetchPriority fetch_priority); |
287 | 307 |
288 // The delegate that receives the crx files downloaded by the | 308 // The delegate that receives the crx files downloaded by the |
289 // ExtensionDownloader, and that fills in optional ping and update url data. | 309 // ExtensionDownloader, and that fills in optional ping and update url data. |
290 ExtensionDownloaderDelegate* delegate_; | 310 ExtensionDownloaderDelegate* delegate_; |
291 | 311 |
292 // The request context to use for the URLFetchers. | 312 // The request context to use for the URLFetchers. |
293 scoped_refptr<net::URLRequestContextGetter> request_context_; | 313 scoped_refptr<net::URLRequestContextGetter> request_context_; |
294 | 314 |
295 // Collects UMA samples that are reported when ReportStats() is called. | 315 // Collects UMA samples that are reported when ReportStats() is called. |
296 URLStats url_stats_; | 316 URLStats url_stats_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 361 |
342 // Used to create WeakPtrs to |this|. | 362 // Used to create WeakPtrs to |this|. |
343 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; | 363 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; |
344 | 364 |
345 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 365 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
346 }; | 366 }; |
347 | 367 |
348 } // namespace extensions | 368 } // namespace extensions |
349 | 369 |
350 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ | 370 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ |
OLD | NEW |