| 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 <memory> | 10 #include <memory> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, | 49 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, |
| 50 // extension_prefs, | 50 // extension_prefs, |
| 51 // pref_service, | 51 // pref_service, |
| 52 // profile, | 52 // profile, |
| 53 // update_frequency_secs, | 53 // update_frequency_secs, |
| 54 // downloader_factory); | 54 // downloader_factory); |
| 55 // updater->Start(); | 55 // updater->Start(); |
| 56 // .... | 56 // .... |
| 57 // updater->Stop(); | 57 // updater->Stop(); |
| 58 class ExtensionUpdater : public ExtensionDownloaderDelegate, | 58 class ExtensionUpdater : public ExtensionDownloaderDelegate, |
| 59 public ExtensionRegistryObserver, | |
| 60 public content::NotificationObserver { | 59 public content::NotificationObserver { |
| 61 public: | 60 public: |
| 62 typedef base::Closure FinishedCallback; | 61 typedef base::Closure FinishedCallback; |
| 63 | 62 |
| 64 struct CheckParams { | 63 struct CheckParams { |
| 65 // Creates a default CheckParams instance that checks for all extensions. | 64 // Creates a default CheckParams instance that checks for all extensions. |
| 66 CheckParams(); | 65 CheckParams(); |
| 67 ~CheckParams(); | 66 ~CheckParams(); |
| 68 | 67 |
| 69 // The set of extensions that should be checked for updates. If empty | 68 // The set of extensions that should be checked for updates. If empty |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 |
| 103 // Posts a task to do an update check. Does nothing if there is | 102 // Posts a task to do an update check. Does nothing if there is |
| 104 // already a pending task that has not yet run. | 103 // already a pending task that has not yet run. |
| 105 void CheckSoon(); | 104 void CheckSoon(); |
| 106 | 105 |
| 107 // Starts an update check for the specified extension soon. If a check | 106 // Starts an update check for the specified extension soon. |
| 108 // is already running, or finished too recently without an update being | 107 void CheckExtensionSoon(const std::string& extension_id, |
| 109 // installed, this method returns false and the check won't be scheduled. | |
| 110 bool CheckExtensionSoon(const std::string& extension_id, | |
| 111 const FinishedCallback& callback); | 108 const FinishedCallback& callback); |
| 112 | 109 |
| 113 // Starts an update check right now, instead of waiting for the next | 110 // Starts an update check right now, instead of waiting for the next |
| 114 // regularly scheduled check or a pending check from CheckSoon(). | 111 // regularly scheduled check or a pending check from CheckSoon(). |
| 115 void CheckNow(const CheckParams& params); | 112 void CheckNow(const CheckParams& params); |
| 116 | 113 |
| 117 // Returns true iff CheckSoon() has been called but the update check | 114 // Returns true iff CheckSoon() has been called but the update check |
| 118 // hasn't been performed yet. This is used mostly by tests; calling | 115 // hasn't been performed yet. This is used mostly by tests; calling |
| 119 // code should just call CheckSoon(). | 116 // code should just call CheckSoon(). |
| 120 bool WillCheckSoon() const; | 117 bool WillCheckSoon() const; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 151 InProgressCheck(); | 148 InProgressCheck(); |
| 152 InProgressCheck(const InProgressCheck& other); | 149 InProgressCheck(const InProgressCheck& other); |
| 153 ~InProgressCheck(); | 150 ~InProgressCheck(); |
| 154 | 151 |
| 155 bool install_immediately; | 152 bool install_immediately; |
| 156 FinishedCallback callback; | 153 FinishedCallback callback; |
| 157 // The ids of extensions that have in-progress update checks. | 154 // The ids of extensions that have in-progress update checks. |
| 158 std::list<std::string> in_progress_ids_; | 155 std::list<std::string> in_progress_ids_; |
| 159 }; | 156 }; |
| 160 | 157 |
| 161 struct ThrottleInfo; | |
| 162 | |
| 163 // Ensure that we have a valid ExtensionDownloader instance referenced by | 158 // Ensure that we have a valid ExtensionDownloader instance referenced by |
| 164 // |downloader|. | 159 // |downloader|. |
| 165 void EnsureDownloaderCreated(); | 160 void EnsureDownloaderCreated(); |
| 166 | 161 |
| 167 // Computes when to schedule the first update check. | 162 // Computes when to schedule the first update check. |
| 168 base::TimeDelta DetermineFirstCheckDelay(); | 163 base::TimeDelta DetermineFirstCheckDelay(); |
| 169 | 164 |
| 170 // Sets the timer to call TimerFired after roughly |target_delay| from now. | 165 // Sets the timer to call TimerFired after roughly |target_delay| from now. |
| 171 // To help spread load evenly on servers, this method adds some random | 166 // To help spread load evenly on servers, this method adds some random |
| 172 // jitter. It also saves the scheduled time so it can be reloaded on | 167 // jitter. It also saves the scheduled time so it can be reloaded on |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void UpdatePingData(const std::string& id, const PingResult& ping_result); | 202 void UpdatePingData(const std::string& id, const PingResult& ping_result); |
| 208 | 203 |
| 209 // Starts installing a crx file that has been fetched but not installed yet. | 204 // Starts installing a crx file that has been fetched but not installed yet. |
| 210 void MaybeInstallCRXFile(); | 205 void MaybeInstallCRXFile(); |
| 211 | 206 |
| 212 // content::NotificationObserver implementation. | 207 // content::NotificationObserver implementation. |
| 213 void Observe(int type, | 208 void Observe(int type, |
| 214 const content::NotificationSource& source, | 209 const content::NotificationSource& source, |
| 215 const content::NotificationDetails& details) override; | 210 const content::NotificationDetails& details) override; |
| 216 | 211 |
| 217 // Implementation of ExtensionRegistryObserver. | |
| 218 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | |
| 219 const Extension* extension, | |
| 220 bool is_update, | |
| 221 const std::string& old_name) override; | |
| 222 | |
| 223 // Send a notification that update checks are starting. | 212 // Send a notification that update checks are starting. |
| 224 void NotifyStarted(); | 213 void NotifyStarted(); |
| 225 | 214 |
| 226 // Send a notification if we're finished updating. | 215 // Send a notification if we're finished updating. |
| 227 void NotifyIfFinished(int request_id); | 216 void NotifyIfFinished(int request_id); |
| 228 | 217 |
| 229 void ExtensionCheckFinished(const std::string& extension_id, | 218 void ExtensionCheckFinished(const std::string& extension_id, |
| 230 const FinishedCallback& callback); | 219 const FinishedCallback& callback); |
| 231 | 220 |
| 232 // Whether Start() has been called but not Stop(). | 221 // Whether Start() has been called but not Stop(). |
| (...skipping 16 matching lines...) Expand all Loading... |
| 249 ExtensionPrefs* extension_prefs_; | 238 ExtensionPrefs* extension_prefs_; |
| 250 PrefService* prefs_; | 239 PrefService* prefs_; |
| 251 Profile* profile_; | 240 Profile* profile_; |
| 252 | 241 |
| 253 std::map<int, InProgressCheck> requests_in_progress_; | 242 std::map<int, InProgressCheck> requests_in_progress_; |
| 254 int next_request_id_; | 243 int next_request_id_; |
| 255 | 244 |
| 256 // Observes CRX installs we initiate. | 245 // Observes CRX installs we initiate. |
| 257 content::NotificationRegistrar registrar_; | 246 content::NotificationRegistrar registrar_; |
| 258 | 247 |
| 259 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | |
| 260 extension_registry_observer_; | |
| 261 | |
| 262 // True when a CrxInstaller is doing an install. Used in MaybeUpdateCrxFile() | 248 // True when a CrxInstaller is doing an install. Used in MaybeUpdateCrxFile() |
| 263 // to keep more than one install from running at once. | 249 // to keep more than one install from running at once. |
| 264 bool crx_install_is_running_; | 250 bool crx_install_is_running_; |
| 265 | 251 |
| 266 // Fetched CRX files waiting to be installed. | 252 // Fetched CRX files waiting to be installed. |
| 267 std::stack<FetchedCRXFile> fetched_crx_files_; | 253 std::stack<FetchedCRXFile> fetched_crx_files_; |
| 268 FetchedCRXFile current_crx_file_; | 254 FetchedCRXFile current_crx_file_; |
| 269 | 255 |
| 270 ExtensionCache* extension_cache_; | 256 ExtensionCache* extension_cache_; |
| 271 | 257 |
| 272 // Keeps track of when an extension tried to update itself, so we can throttle | |
| 273 // checks to prevent too many requests from being made. | |
| 274 std::map<std::string, ThrottleInfo> throttle_info_; | |
| 275 | |
| 276 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; | 258 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; |
| 277 | 259 |
| 278 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); | 260 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); |
| 279 }; | 261 }; |
| 280 | 262 |
| 281 } // namespace extensions | 263 } // namespace extensions |
| 282 | 264 |
| 283 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ | 265 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
| OLD | NEW |