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

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

Issue 456063002: ExtensionUpdater: Abstract ExtensionDownloader creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments and some cleanup Created 6 years, 4 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 | Annotate | Revision Log
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 <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,
53 // profile, 52 // profile,
54 // update_frequency_secs); 53 // update_frequency_secs,
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 ExtensionRegistryObserver,
60 public content::NotificationObserver { 60 public content::NotificationObserver {
61 public: 61 public:
62 typedef base::Closure FinishedCallback; 62 typedef base::Closure FinishedCallback;
63 63
64 struct CheckParams { 64 struct CheckParams {
(...skipping 17 matching lines...) Expand all
82 82
83 // Holds a pointer to the passed |service|, using it for querying installed 83 // Holds a pointer to the passed |service|, using it for querying installed
84 // extensions and installing updated ones. The |frequency_seconds| parameter 84 // extensions and installing updated ones. The |frequency_seconds| parameter
85 // controls how often update checks are scheduled. 85 // controls how often update checks are scheduled.
86 ExtensionUpdater(ExtensionServiceInterface* service, 86 ExtensionUpdater(ExtensionServiceInterface* service,
87 ExtensionPrefs* extension_prefs, 87 ExtensionPrefs* extension_prefs,
88 PrefService* prefs, 88 PrefService* prefs,
89 Profile* profile, 89 Profile* profile,
90 int frequency_seconds, 90 int frequency_seconds,
91 ExtensionCache* cache, 91 ExtensionCache* cache,
92 scoped_ptr<IdentityProvider> identity_provider); 92 const ExtensionDownloader::Factory& downloader_factory);
93 93
94 virtual ~ExtensionUpdater(); 94 virtual ~ExtensionUpdater();
95 95
96 // Starts the updater running. Should be called at most once. 96 // Starts the updater running. Should be called at most once.
97 void Start(); 97 void Start();
98 98
99 // Stops the updater running, cancelling any outstanding update manifest and 99 // Stops the updater running, cancelling any outstanding update manifest and
100 // crx downloads. Does not cancel any in-progress installs. 100 // crx downloads. Does not cancel any in-progress installs.
101 void Stop(); 101 void Stop();
102 102
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 ~InProgressCheck(); 150 ~InProgressCheck();
151 151
152 bool install_immediately; 152 bool install_immediately;
153 FinishedCallback callback; 153 FinishedCallback callback;
154 // The ids of extensions that have in-progress update checks. 154 // The ids of extensions that have in-progress update checks.
155 std::list<std::string> in_progress_ids_; 155 std::list<std::string> in_progress_ids_;
156 }; 156 };
157 157
158 struct ThrottleInfo; 158 struct ThrottleInfo;
159 159
160 // Ensure that we have a valid ExtensionDownloader instance referenced by
161 // |downloader|.
162 void EnsureDownloaderCreated();
163
160 // Computes when to schedule the first update check. 164 // Computes when to schedule the first update check.
161 base::TimeDelta DetermineFirstCheckDelay(); 165 base::TimeDelta DetermineFirstCheckDelay();
162 166
163 // Sets the timer to call TimerFired after roughly |target_delay| from now. 167 // 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 168 // 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 169 // jitter. It also saves the scheduled time so it can be reloaded on
166 // browser restart. 170 // browser restart.
167 void ScheduleNextCheck(const base::TimeDelta& target_delay); 171 void ScheduleNextCheck(const base::TimeDelta& target_delay);
168 172
169 // Add fetch records for extensions that are installed to the downloader, 173 // Add fetch records for extensions that are installed to the downloader,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 const FinishedCallback& callback); 237 const FinishedCallback& callback);
234 238
235 // Whether Start() has been called but not Stop(). 239 // Whether Start() has been called but not Stop().
236 bool alive_; 240 bool alive_;
237 241
238 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; 242 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_;
239 243
240 // Pointer back to the service that owns this ExtensionUpdater. 244 // Pointer back to the service that owns this ExtensionUpdater.
241 ExtensionServiceInterface* service_; 245 ExtensionServiceInterface* service_;
242 246
247 // A closure passed into the ExtensionUpdater to teach it how to construct
248 // new ExtensionDownloader instances.
249 const ExtensionDownloader::Factory downloader_factory_;
250
243 // Fetches the crx files for the extensions that have an available update. 251 // Fetches the crx files for the extensions that have an available update.
244 scoped_ptr<ExtensionDownloader> downloader_; 252 scoped_ptr<ExtensionDownloader> downloader_;
245 253
246 base::OneShotTimer<ExtensionUpdater> timer_; 254 base::OneShotTimer<ExtensionUpdater> timer_;
247 int frequency_seconds_; 255 int frequency_seconds_;
248 bool will_check_soon_; 256 bool will_check_soon_;
249 257
250 ExtensionPrefs* extension_prefs_; 258 ExtensionPrefs* extension_prefs_;
251 PrefService* prefs_; 259 PrefService* prefs_;
252 Profile* profile_; 260 Profile* profile_;
(...skipping 12 matching lines...) Expand all
265 bool crx_install_is_running_; 273 bool crx_install_is_running_;
266 274
267 // Fetched CRX files waiting to be installed. 275 // Fetched CRX files waiting to be installed.
268 std::stack<FetchedCRXFile> fetched_crx_files_; 276 std::stack<FetchedCRXFile> fetched_crx_files_;
269 FetchedCRXFile current_crx_file_; 277 FetchedCRXFile current_crx_file_;
270 278
271 CheckParams default_params_; 279 CheckParams default_params_;
272 280
273 ExtensionCache* extension_cache_; 281 ExtensionCache* extension_cache_;
274 282
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 283 // Keeps track of when an extension tried to update itself, so we can throttle
279 // checks to prevent too many requests from being made. 284 // checks to prevent too many requests from being made.
280 std::map<std::string, ThrottleInfo> throttle_info_; 285 std::map<std::string, ThrottleInfo> throttle_info_;
281 286
282 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); 287 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater);
283 }; 288 };
284 289
285 } // namespace extensions 290 } // namespace extensions
286 291
287 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ 292 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_downloader.cc ('k') | chrome/browser/extensions/updater/extension_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698