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 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 29 matching lines...) Expand all Loading... |
40 struct UpdateDetails { | 40 struct UpdateDetails { |
41 UpdateDetails(const std::string& id, const base::Version& version); | 41 UpdateDetails(const std::string& id, const base::Version& version); |
42 ~UpdateDetails(); | 42 ~UpdateDetails(); |
43 | 43 |
44 std::string id; | 44 std::string id; |
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 class WebstoreOAuth2TokenProvider; | |
51 | 50 |
52 // 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 |
53 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| | 52 // the crx file when updates are found. It uses a |ExtensionDownloaderDelegate| |
54 // 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 |
55 // the update check. | 54 // the update check. |
56 class ExtensionDownloader | 55 class ExtensionDownloader |
57 : public net::URLFetcherDelegate, | 56 : public net::URLFetcherDelegate, |
58 public OAuth2TokenService::Consumer { | 57 public OAuth2TokenService::Consumer { |
59 public: | 58 public: |
| 59 // A closure which constructs a new ExtensionDownloader to be owned by the |
| 60 // caller. |
| 61 typedef base::Callback< |
| 62 scoped_ptr<ExtensionDownloader>(ExtensionDownloaderDelegate* delegate)> |
| 63 Factory; |
| 64 |
60 // |delegate| is stored as a raw pointer and must outlive the | 65 // |delegate| is stored as a raw pointer and must outlive the |
61 // ExtensionDownloader. |webstore_identity_provider| may be NULL if this | 66 // ExtensionDownloader. |
62 // ExtensionDownloader does not need OAuth2 support; if not NULL, the | |
63 // given IdentityProvider must outlive this ExtensionDownloader. | |
64 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, | 67 ExtensionDownloader(ExtensionDownloaderDelegate* delegate, |
65 net::URLRequestContextGetter* request_context, | 68 net::URLRequestContextGetter* request_context); |
66 IdentityProvider* webstore_identity_provider); | |
67 virtual ~ExtensionDownloader(); | 69 virtual ~ExtensionDownloader(); |
68 | 70 |
69 // Adds |extension| to the list of extensions to check for updates. | 71 // Adds |extension| to the list of extensions to check for updates. |
70 // 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. |
71 // In that case, no callbacks will be performed on the |delegate_|. | 73 // In that case, no callbacks will be performed on the |delegate_|. |
72 // The |request_id| is passed on as is to the various |delegate_| callbacks. | 74 // The |request_id| is passed on as is to the various |delegate_| callbacks. |
73 // This is used for example by ExtensionUpdater to keep track of when | 75 // This is used for example by ExtensionUpdater to keep track of when |
74 // potentially concurrent update checks complete. | 76 // potentially concurrent update checks complete. |
75 bool AddExtension(const Extension& extension, int request_id); | 77 bool AddExtension(const Extension& extension, int request_id); |
76 | 78 |
77 // Adds extension |id| to the list of extensions to check for updates. | 79 // Adds extension |id| to the list of extensions to check for updates. |
78 // Returns false if the |id| can't be updated due to invalid details. | 80 // Returns false if the |id| can't be updated due to invalid details. |
79 // In that case, no callbacks will be performed on the |delegate_|. | 81 // In that case, no callbacks will be performed on the |delegate_|. |
80 // The |request_id| is passed on as is to the various |delegate_| callbacks. | 82 // The |request_id| is passed on as is to the various |delegate_| callbacks. |
81 // This is used for example by ExtensionUpdater to keep track of when | 83 // This is used for example by ExtensionUpdater to keep track of when |
82 // potentially concurrent update checks complete. | 84 // potentially concurrent update checks complete. |
83 bool AddPendingExtension(const std::string& id, | 85 bool AddPendingExtension(const std::string& id, |
84 const GURL& update_url, | 86 const GURL& update_url, |
85 int request_id); | 87 int request_id); |
86 | 88 |
87 // Schedules a fetch of the manifest of all the extensions added with | 89 // Schedules a fetch of the manifest of all the extensions added with |
88 // AddExtension() and AddPendingExtension(). | 90 // AddExtension() and AddPendingExtension(). |
89 void StartAllPending(ExtensionCache* cache); | 91 void StartAllPending(ExtensionCache* cache); |
90 | 92 |
91 // Schedules an update check of the blacklist. | 93 // Schedules an update check of the blacklist. |
92 void StartBlacklistUpdate(const std::string& version, | 94 void StartBlacklistUpdate(const std::string& version, |
93 const ManifestFetchData::PingData& ping_data, | 95 const ManifestFetchData::PingData& ping_data, |
94 int request_id); | 96 int request_id); |
95 | 97 |
| 98 // Sets an IdentityProvider to be used for OAuth2 authentication on protected |
| 99 // Webstore downloads. |
| 100 void SetWebstoreIdentityProvider( |
| 101 scoped_ptr<IdentityProvider> identity_provider); |
| 102 |
96 // These are needed for unit testing, to help identify the correct mock | 103 // These are needed for unit testing, to help identify the correct mock |
97 // URLFetcher objects. | 104 // URLFetcher objects. |
98 static const int kManifestFetcherId = 1; | 105 static const int kManifestFetcherId = 1; |
99 static const int kExtensionFetcherId = 2; | 106 static const int kExtensionFetcherId = 2; |
100 | 107 |
101 // Update AppID for extension blacklist. | 108 // Update AppID for extension blacklist. |
102 static const char kBlacklistAppID[]; | 109 static const char kBlacklistAppID[]; |
103 | 110 |
104 static const int kMaxRetries = 10; | 111 static const int kMaxRetries = 10; |
105 | 112 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 RequestQueue<ExtensionFetch> extensions_queue_; | 275 RequestQueue<ExtensionFetch> extensions_queue_; |
269 | 276 |
270 // Maps an extension-id to its PingResult data. | 277 // Maps an extension-id to its PingResult data. |
271 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; | 278 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; |
272 | 279 |
273 // Cache for .crx files. | 280 // Cache for .crx files. |
274 ExtensionCache* extension_cache_; | 281 ExtensionCache* extension_cache_; |
275 | 282 |
276 // An IdentityProvider which may be used for authentication on protected | 283 // An IdentityProvider which may be used for authentication on protected |
277 // download requests. May be NULL. | 284 // download requests. May be NULL. |
278 IdentityProvider* identity_provider_; | 285 scoped_ptr<IdentityProvider> identity_provider_; |
279 | 286 |
280 // A Webstore download-scoped access token for the |identity_provider_|'s | 287 // A Webstore download-scoped access token for the |identity_provider_|'s |
281 // active account, if any. | 288 // active account, if any. |
282 std::string access_token_; | 289 std::string access_token_; |
283 | 290 |
284 // A pending token fetch request. | 291 // A pending token fetch request. |
285 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 292 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
286 | 293 |
287 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 294 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
288 }; | 295 }; |
289 | 296 |
290 } // namespace extensions | 297 } // namespace extensions |
291 | 298 |
292 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 299 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
OLD | NEW |