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_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <stack> | 11 #include <stack> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
18 #include "base/memory/scoped_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/scoped_observer.h" | 20 #include "base/scoped_observer.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 23 #include "chrome/browser/extensions/updater/extension_downloader.h" |
23 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" | 24 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" |
24 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 25 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" |
25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
27 #include "extensions/browser/extension_registry_observer.h" | 28 #include "extensions/browser/extension_registry_observer.h" |
28 #include "google_apis/gaia/identity_provider.h" | |
29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
30 | 30 |
31 class ExtensionServiceInterface; | 31 class ExtensionServiceInterface; |
32 class PrefService; | 32 class PrefService; |
33 class Profile; | 33 class Profile; |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 class BrowserContext; | 36 class BrowserContext; |
37 } | 37 } |
38 | 38 |
39 namespace extensions { | 39 namespace extensions { |
40 | 40 |
41 class ExtensionCache; | 41 class ExtensionCache; |
42 class ExtensionDownloader; | |
43 class ExtensionPrefs; | 42 class ExtensionPrefs; |
44 class ExtensionRegistry; | 43 class ExtensionRegistry; |
45 class ExtensionSet; | 44 class ExtensionSet; |
46 class ExtensionUpdaterTest; | 45 class ExtensionUpdaterTest; |
47 | 46 |
48 // A class for doing auto-updates of installed Extensions. Used like this: | 47 // A class for doing auto-updates of installed Extensions. Used like this: |
49 // | 48 // |
50 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, | 49 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, |
51 // extension_prefs, | 50 // extension_prefs, |
52 // pref_service, | 51 // pref_service, |
(...skipping 29 matching lines...) Expand all Loading... |
82 | 81 |
83 // Holds a pointer to the passed |service|, using it for querying installed | 82 // Holds a pointer to the passed |service|, using it for querying installed |
84 // extensions and installing updated ones. The |frequency_seconds| parameter | 83 // extensions and installing updated ones. The |frequency_seconds| parameter |
85 // controls how often update checks are scheduled. | 84 // controls how often update checks are scheduled. |
86 ExtensionUpdater(ExtensionServiceInterface* service, | 85 ExtensionUpdater(ExtensionServiceInterface* service, |
87 ExtensionPrefs* extension_prefs, | 86 ExtensionPrefs* extension_prefs, |
88 PrefService* prefs, | 87 PrefService* prefs, |
89 Profile* profile, | 88 Profile* profile, |
90 int frequency_seconds, | 89 int frequency_seconds, |
91 ExtensionCache* cache, | 90 ExtensionCache* cache, |
92 scoped_ptr<IdentityProvider> identity_provider); | 91 const ExtensionDownloader::Factory& downloader_factory); |
93 | 92 |
94 virtual ~ExtensionUpdater(); | 93 virtual ~ExtensionUpdater(); |
95 | 94 |
96 // Starts the updater running. Should be called at most once. | 95 // Starts the updater running. Should be called at most once. |
97 void Start(); | 96 void Start(); |
98 | 97 |
99 // Stops the updater running, cancelling any outstanding update manifest and | 98 // Stops the updater running, cancelling any outstanding update manifest and |
100 // crx downloads. Does not cancel any in-progress installs. | 99 // crx downloads. Does not cancel any in-progress installs. |
101 void Stop(); | 100 void Stop(); |
102 | 101 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ~InProgressCheck(); | 149 ~InProgressCheck(); |
151 | 150 |
152 bool install_immediately; | 151 bool install_immediately; |
153 FinishedCallback callback; | 152 FinishedCallback callback; |
154 // The ids of extensions that have in-progress update checks. | 153 // The ids of extensions that have in-progress update checks. |
155 std::list<std::string> in_progress_ids_; | 154 std::list<std::string> in_progress_ids_; |
156 }; | 155 }; |
157 | 156 |
158 struct ThrottleInfo; | 157 struct ThrottleInfo; |
159 | 158 |
| 159 // Ensure that we have a valid ExtensionDownloader instance referenced by |
| 160 // |downloader|. |
| 161 void EnsureDownloaderCreated(); |
| 162 |
160 // Computes when to schedule the first update check. | 163 // Computes when to schedule the first update check. |
161 base::TimeDelta DetermineFirstCheckDelay(); | 164 base::TimeDelta DetermineFirstCheckDelay(); |
162 | 165 |
163 // Sets the timer to call TimerFired after roughly |target_delay| from now. | 166 // Sets the timer to call TimerFired after roughly |target_delay| from now. |
164 // To help spread load evenly on servers, this method adds some random | 167 // To help spread load evenly on servers, this method adds some random |
165 // jitter. It also saves the scheduled time so it can be reloaded on | 168 // jitter. It also saves the scheduled time so it can be reloaded on |
166 // browser restart. | 169 // browser restart. |
167 void ScheduleNextCheck(const base::TimeDelta& target_delay); | 170 void ScheduleNextCheck(const base::TimeDelta& target_delay); |
168 | 171 |
169 // Add fetch records for extensions that are installed to the downloader, | 172 // Add fetch records for extensions that are installed to the downloader, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 const FinishedCallback& callback); | 236 const FinishedCallback& callback); |
234 | 237 |
235 // Whether Start() has been called but not Stop(). | 238 // Whether Start() has been called but not Stop(). |
236 bool alive_; | 239 bool alive_; |
237 | 240 |
238 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; | 241 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; |
239 | 242 |
240 // Pointer back to the service that owns this ExtensionUpdater. | 243 // Pointer back to the service that owns this ExtensionUpdater. |
241 ExtensionServiceInterface* service_; | 244 ExtensionServiceInterface* service_; |
242 | 245 |
| 246 // A closure passed into the ExtensionUpdater to teach it how to construct |
| 247 // new ExtensionDownloader instances. |
| 248 const ExtensionDownloader::Factory downloader_factory_; |
| 249 |
243 // Fetches the crx files for the extensions that have an available update. | 250 // Fetches the crx files for the extensions that have an available update. |
244 scoped_ptr<ExtensionDownloader> downloader_; | 251 scoped_ptr<ExtensionDownloader> downloader_; |
245 | 252 |
246 base::OneShotTimer<ExtensionUpdater> timer_; | 253 base::OneShotTimer<ExtensionUpdater> timer_; |
247 int frequency_seconds_; | 254 int frequency_seconds_; |
248 bool will_check_soon_; | 255 bool will_check_soon_; |
249 | 256 |
250 ExtensionPrefs* extension_prefs_; | 257 ExtensionPrefs* extension_prefs_; |
251 PrefService* prefs_; | 258 PrefService* prefs_; |
252 Profile* profile_; | 259 Profile* profile_; |
(...skipping 12 matching lines...) Expand all Loading... |
265 bool crx_install_is_running_; | 272 bool crx_install_is_running_; |
266 | 273 |
267 // Fetched CRX files waiting to be installed. | 274 // Fetched CRX files waiting to be installed. |
268 std::stack<FetchedCRXFile> fetched_crx_files_; | 275 std::stack<FetchedCRXFile> fetched_crx_files_; |
269 FetchedCRXFile current_crx_file_; | 276 FetchedCRXFile current_crx_file_; |
270 | 277 |
271 CheckParams default_params_; | 278 CheckParams default_params_; |
272 | 279 |
273 ExtensionCache* extension_cache_; | 280 ExtensionCache* extension_cache_; |
274 | 281 |
275 // Provided to the ExtensionDownloader to enable OAuth2 support. | |
276 scoped_ptr<IdentityProvider> webstore_identity_provider_; | |
277 | |
278 // Keeps track of when an extension tried to update itself, so we can throttle | 282 // Keeps track of when an extension tried to update itself, so we can throttle |
279 // checks to prevent too many requests from being made. | 283 // checks to prevent too many requests from being made. |
280 std::map<std::string, ThrottleInfo> throttle_info_; | 284 std::map<std::string, ThrottleInfo> throttle_info_; |
281 | 285 |
282 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); | 286 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); |
283 }; | 287 }; |
284 | 288 |
285 } // namespace extensions | 289 } // namespace extensions |
286 | 290 |
287 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ | 291 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
OLD | NEW |