Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: extensions/browser/updater/extension_downloader.h

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 11 #include <set>
11 #include <string> 12 #include <string>
12 #include <utility> 13 #include <utility>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/linked_ptr.h" 18 #include "base/memory/linked_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 "extensions/browser/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"
(...skipping 22 matching lines...) Expand all
51 51
52 // 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
53 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| 53 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate|
54 // 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
55 // the update check. 55 // the update check.
56 class ExtensionDownloader : public net::URLFetcherDelegate, 56 class ExtensionDownloader : public net::URLFetcherDelegate,
57 public OAuth2TokenService::Consumer { 57 public OAuth2TokenService::Consumer {
58 public: 58 public:
59 // A closure which constructs a new ExtensionDownloader to be owned by the 59 // A closure which constructs a new ExtensionDownloader to be owned by the
60 // caller. 60 // caller.
61 typedef base::Callback<scoped_ptr<ExtensionDownloader>( 61 typedef base::Callback<std::unique_ptr<ExtensionDownloader>(
62 ExtensionDownloaderDelegate* delegate)> Factory; 62 ExtensionDownloaderDelegate* delegate)>
63 Factory;
63 64
64 // |delegate| is stored as a raw pointer and must outlive the 65 // |delegate| is stored as a raw pointer and must outlive the
65 // ExtensionDownloader. 66 // ExtensionDownloader.
66 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, 67 ExtensionDownloader(ExtensionDownloaderDelegate* delegate,
67 net::URLRequestContextGetter* request_context); 68 net::URLRequestContextGetter* request_context);
68 ~ExtensionDownloader() override; 69 ~ExtensionDownloader() override;
69 70
70 // Adds |extension| to the list of extensions to check for updates. 71 // 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. 72 // 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_|. 73 // In that case, no callbacks will be performed on the |delegate_|.
(...skipping 17 matching lines...) Expand all
90 void StartAllPending(ExtensionCache* cache); 91 void StartAllPending(ExtensionCache* cache);
91 92
92 // Schedules an update check of the blacklist. 93 // Schedules an update check of the blacklist.
93 void StartBlacklistUpdate(const std::string& version, 94 void StartBlacklistUpdate(const std::string& version,
94 const ManifestFetchData::PingData& ping_data, 95 const ManifestFetchData::PingData& ping_data,
95 int request_id); 96 int request_id);
96 97
97 // Sets an IdentityProvider to be used for OAuth2 authentication on protected 98 // Sets an IdentityProvider to be used for OAuth2 authentication on protected
98 // Webstore downloads. 99 // Webstore downloads.
99 void SetWebstoreIdentityProvider( 100 void SetWebstoreIdentityProvider(
100 scoped_ptr<IdentityProvider> identity_provider); 101 std::unique_ptr<IdentityProvider> identity_provider);
101 102
102 void set_brand_code(const std::string& brand_code) { 103 void set_brand_code(const std::string& brand_code) {
103 brand_code_ = brand_code; 104 brand_code_ = brand_code;
104 } 105 }
105 106
106 void set_manifest_query_params(const std::string& params) { 107 void set_manifest_query_params(const std::string& params) {
107 manifest_query_params_ = params; 108 manifest_query_params_ = params;
108 } 109 }
109 110
110 void set_ping_enabled_domain(const std::string& domain) { 111 void set_ping_enabled_domain(const std::string& domain) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 const base::Version& version, 187 const base::Version& version,
187 Manifest::Type extension_type, 188 Manifest::Type extension_type,
188 const GURL& extension_update_url, 189 const GURL& extension_update_url,
189 const std::string& update_url_data, 190 const std::string& update_url_data,
190 int request_id); 191 int request_id);
191 192
192 // Adds all recorded stats taken so far to histogram counts. 193 // Adds all recorded stats taken so far to histogram counts.
193 void ReportStats() const; 194 void ReportStats() const;
194 195
195 // Begins an update check. 196 // Begins an update check.
196 void StartUpdateCheck(scoped_ptr<ManifestFetchData> fetch_data); 197 void StartUpdateCheck(std::unique_ptr<ManifestFetchData> fetch_data);
197 198
198 // Called by RequestQueue when a new manifest fetch request is started. 199 // Called by RequestQueue when a new manifest fetch request is started.
199 void CreateManifestFetcher(); 200 void CreateManifestFetcher();
200 201
201 // net::URLFetcherDelegate implementation. 202 // net::URLFetcherDelegate implementation.
202 void OnURLFetchComplete(const net::URLFetcher* source) override; 203 void OnURLFetchComplete(const net::URLFetcher* source) override;
203 204
204 // Handles the result of a manifest fetch. 205 // Handles the result of a manifest fetch.
205 void OnManifestFetchComplete(const GURL& url, 206 void OnManifestFetchComplete(const GURL& url,
206 const net::URLRequestStatus& status, 207 const net::URLRequestStatus& status,
207 int response_code, 208 int response_code,
208 const base::TimeDelta& backoff_delay, 209 const base::TimeDelta& backoff_delay,
209 const std::string& data); 210 const std::string& data);
210 211
211 // Once a manifest is parsed, this starts fetches of any relevant crx files. 212 // Once a manifest is parsed, this starts fetches of any relevant crx files.
212 // If |results| is null, it means something went wrong when parsing it. 213 // If |results| is null, it means something went wrong when parsing it.
213 void HandleManifestResults(const ManifestFetchData* fetch_data, 214 void HandleManifestResults(const ManifestFetchData* fetch_data,
214 const UpdateManifest::Results* results); 215 const UpdateManifest::Results* results);
215 216
216 // Given a list of potential updates, returns the indices of the ones that are 217 // Given a list of potential updates, returns the indices of the ones that are
217 // applicable (are actually a new version, etc.) in |result|. 218 // applicable (are actually a new version, etc.) in |result|.
218 void DetermineUpdates(const ManifestFetchData& fetch_data, 219 void DetermineUpdates(const ManifestFetchData& fetch_data,
219 const UpdateManifest::Results& possible_updates, 220 const UpdateManifest::Results& possible_updates,
220 std::vector<int>* result); 221 std::vector<int>* result);
221 222
222 // Begins (or queues up) download of an updated extension. 223 // Begins (or queues up) download of an updated extension.
223 void FetchUpdatedExtension(scoped_ptr<ExtensionFetch> fetch_data); 224 void FetchUpdatedExtension(std::unique_ptr<ExtensionFetch> fetch_data);
224 225
225 // Called by RequestQueue when a new extension fetch request is started. 226 // Called by RequestQueue when a new extension fetch request is started.
226 void CreateExtensionFetcher(); 227 void CreateExtensionFetcher();
227 228
228 // Handles the result of a crx fetch. 229 // Handles the result of a crx fetch.
229 void OnCRXFetchComplete(const net::URLFetcher* source, 230 void OnCRXFetchComplete(const net::URLFetcher* source,
230 const GURL& url, 231 const GURL& url,
231 const net::URLRequestStatus& status, 232 const net::URLRequestStatus& status,
232 int response_code, 233 int response_code,
233 const base::TimeDelta& backoff_delay); 234 const base::TimeDelta& backoff_delay);
234 235
235 // Invokes OnExtensionDownloadFailed() on the |delegate_| for each extension 236 // Invokes OnExtensionDownloadFailed() on the |delegate_| for each extension
236 // in the set, with |error| as the reason for failure. 237 // in the set, with |error| as the reason for failure.
237 void NotifyExtensionsDownloadFailed(const std::set<std::string>& id_set, 238 void NotifyExtensionsDownloadFailed(const std::set<std::string>& id_set,
238 const std::set<int>& request_ids, 239 const std::set<int>& request_ids,
239 ExtensionDownloaderDelegate::Error error); 240 ExtensionDownloaderDelegate::Error error);
240 241
241 // Send a notification that an update was found for |id| that we'll 242 // Send a notification that an update was found for |id| that we'll
242 // attempt to download. 243 // attempt to download.
243 void NotifyUpdateFound(const std::string& id, const std::string& version); 244 void NotifyUpdateFound(const std::string& id, const std::string& version);
244 245
245 // Do real work of StartAllPending. If .crx cache is used, this function 246 // Do real work of StartAllPending. If .crx cache is used, this function
246 // is called when cache is ready. 247 // is called when cache is ready.
247 void DoStartAllPending(); 248 void DoStartAllPending();
248 249
249 // Notify delegate and remove ping results. 250 // Notify delegate and remove ping results.
250 void NotifyDelegateDownloadFinished(scoped_ptr<ExtensionFetch> fetch_data, 251 void NotifyDelegateDownloadFinished(
251 bool from_cache, 252 std::unique_ptr<ExtensionFetch> fetch_data,
252 const base::FilePath& crx_path, 253 bool from_cache,
253 bool file_ownership_passed); 254 const base::FilePath& crx_path,
255 bool file_ownership_passed);
254 256
255 // Cached extension installation completed. If it was not successful, we will 257 // Cached extension installation completed. If it was not successful, we will
256 // try to download it from the web store using already fetched manifest. 258 // try to download it from the web store using already fetched manifest.
257 void CacheInstallDone(scoped_ptr<ExtensionFetch> fetch_data, bool installed); 259 void CacheInstallDone(std::unique_ptr<ExtensionFetch> fetch_data,
260 bool installed);
258 261
259 // Potentially updates an ExtensionFetch's authentication state and returns 262 // Potentially updates an ExtensionFetch's authentication state and returns
260 // |true| if the fetch should be retried. Returns |false| if the failure was 263 // |true| if the fetch should be retried. Returns |false| if the failure was
261 // not related to authentication, leaving the ExtensionFetch data unmodified. 264 // not related to authentication, leaving the ExtensionFetch data unmodified.
262 bool IterateFetchCredentialsAfterFailure(ExtensionFetch* fetch, 265 bool IterateFetchCredentialsAfterFailure(ExtensionFetch* fetch,
263 const net::URLRequestStatus& status, 266 const net::URLRequestStatus& status,
264 int response_code); 267 int response_code);
265 268
266 // OAuth2TokenService::Consumer implementation. 269 // OAuth2TokenService::Consumer implementation.
267 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 270 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
(...skipping 17 matching lines...) Expand all
285 288
286 // List of data on fetches we're going to do. We limit the number of 289 // List of data on fetches we're going to do. We limit the number of
287 // extensions grouped together in one batch to avoid running into the limits 290 // extensions grouped together in one batch to avoid running into the limits
288 // on the length of http GET requests, so there might be multiple 291 // on the length of http GET requests, so there might be multiple
289 // ManifestFetchData* objects with the same base_url. 292 // ManifestFetchData* objects with the same base_url.
290 typedef std::map<std::pair<int, GURL>, 293 typedef std::map<std::pair<int, GURL>,
291 std::vector<linked_ptr<ManifestFetchData>>> FetchMap; 294 std::vector<linked_ptr<ManifestFetchData>>> FetchMap;
292 FetchMap fetches_preparing_; 295 FetchMap fetches_preparing_;
293 296
294 // Outstanding url fetch requests for manifests and updates. 297 // Outstanding url fetch requests for manifests and updates.
295 scoped_ptr<net::URLFetcher> manifest_fetcher_; 298 std::unique_ptr<net::URLFetcher> manifest_fetcher_;
296 scoped_ptr<net::URLFetcher> extension_fetcher_; 299 std::unique_ptr<net::URLFetcher> extension_fetcher_;
297 300
298 // Pending manifests and extensions to be fetched when the appropriate fetcher 301 // Pending manifests and extensions to be fetched when the appropriate fetcher
299 // is available. 302 // is available.
300 RequestQueue<ManifestFetchData> manifests_queue_; 303 RequestQueue<ManifestFetchData> manifests_queue_;
301 RequestQueue<ExtensionFetch> extensions_queue_; 304 RequestQueue<ExtensionFetch> extensions_queue_;
302 305
303 // Maps an extension-id to its PingResult data. 306 // Maps an extension-id to its PingResult data.
304 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; 307 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_;
305 308
306 // Cache for .crx files. 309 // Cache for .crx files.
307 ExtensionCache* extension_cache_; 310 ExtensionCache* extension_cache_;
308 311
309 // An IdentityProvider which may be used for authentication on protected 312 // An IdentityProvider which may be used for authentication on protected
310 // download requests. May be NULL. 313 // download requests. May be NULL.
311 scoped_ptr<IdentityProvider> identity_provider_; 314 std::unique_ptr<IdentityProvider> identity_provider_;
312 315
313 // A Webstore download-scoped access token for the |identity_provider_|'s 316 // A Webstore download-scoped access token for the |identity_provider_|'s
314 // active account, if any. 317 // active account, if any.
315 std::string access_token_; 318 std::string access_token_;
316 319
317 // A pending token fetch request. 320 // A pending token fetch request.
318 scoped_ptr<OAuth2TokenService::Request> access_token_request_; 321 std::unique_ptr<OAuth2TokenService::Request> access_token_request_;
319 322
320 // Brand code to include with manifest fetch queries if sending ping data. 323 // Brand code to include with manifest fetch queries if sending ping data.
321 std::string brand_code_; 324 std::string brand_code_;
322 325
323 // Baseline parameters to include with manifest fetch queries. 326 // Baseline parameters to include with manifest fetch queries.
324 std::string manifest_query_params_; 327 std::string manifest_query_params_;
325 328
326 // Domain to enable ping data. Ping data will be sent with manifest fetches 329 // Domain to enable ping data. Ping data will be sent with manifest fetches
327 // to update URLs which match this domain. Defaults to empty (no domain). 330 // to update URLs which match this domain. Defaults to empty (no domain).
328 std::string ping_enabled_domain_; 331 std::string ping_enabled_domain_;
329 332
330 // Indicates whether or not extra metrics should be included with ping data. 333 // Indicates whether or not extra metrics should be included with ping data.
331 // Defaults to |false|. 334 // Defaults to |false|.
332 bool enable_extra_update_metrics_; 335 bool enable_extra_update_metrics_;
333 336
334 // Used to create WeakPtrs to |this|. 337 // Used to create WeakPtrs to |this|.
335 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_; 338 base::WeakPtrFactory<ExtensionDownloader> weak_ptr_factory_;
336 339
337 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); 340 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader);
338 }; 341 };
339 342
340 } // namespace extensions 343 } // namespace extensions
341 344
342 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_ 345 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_H_
OLDNEW
« no previous file with comments | « extensions/browser/test_extensions_browser_client.cc ('k') | extensions/browser/updater/extension_downloader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698