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

Side by Side Diff: chrome/browser/extensions/updater/extension_updater.h

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

Powered by Google App Engine
This is Rietveld 408576698