| 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. |foreground_check| |
| 76 bool AddExtension(const Extension& extension, int request_id); | 76 // parameter notifies the downloader that this extension update is an on |
| 77 // demand update (if true). |
| 78 bool AddExtension(const Extension& extension, |
| 79 int request_id, |
| 80 bool foreground_check); |
| 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 // |foreground_check| parameter notifies the downloader that this extension |
| 91 // update is an on demand update (if true). |
| 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 bool foreground_check); |
| 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 bool foreground_check); |
| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(const GURL& update_url, |
| 286 int request_id); | 304 int request_id, |
| 305 bool foreground_check); |
| 287 | 306 |
| 288 // The delegate that receives the crx files downloaded by the | 307 // The delegate that receives the crx files downloaded by the |
| 289 // ExtensionDownloader, and that fills in optional ping and update url data. | 308 // ExtensionDownloader, and that fills in optional ping and update url data. |
| 290 ExtensionDownloaderDelegate* delegate_; | 309 ExtensionDownloaderDelegate* delegate_; |
| 291 | 310 |
| 292 // The request context to use for the URLFetchers. | 311 // The request context to use for the URLFetchers. |
| 293 scoped_refptr<net::URLRequestContextGetter> request_context_; | 312 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 294 | 313 |
| 295 // Collects UMA samples that are reported when ReportStats() is called. | 314 // Collects UMA samples that are reported when ReportStats() is called. |
| 296 URLStats url_stats_; | 315 URLStats url_stats_; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 360 |
| 342 // Used to create WeakPtrs to |this|. | 361 // Used to create WeakPtrs to |this|. |
| 343 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; | 362 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; |
| 344 | 363 |
| 345 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 364 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
| 346 }; | 365 }; |
| 347 | 366 |
| 348 } // namespace extensions | 367 } // namespace extensions |
| 349 | 368 |
| 350 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ | 369 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ |
| OLD | NEW |