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

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

Issue 6965018: Install CRX updates one at a time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polish Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_EXTENSION_UPDATER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <deque> 9 #include <deque>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <stack>
12 #include <string> 13 #include <string>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
19 #include "base/scoped_temp_dir.h" 20 #include "base/scoped_temp_dir.h"
20 #include "base/task.h" 21 #include "base/task.h"
21 #include "base/time.h" 22 #include "base/time.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 }; 158 };
158 159
159 // A class for doing auto-updates of installed Extensions. Used like this: 160 // A class for doing auto-updates of installed Extensions. Used like this:
160 // 161 //
161 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, 162 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service,
162 // pref_service, 163 // pref_service,
163 // update_frequency_secs); 164 // update_frequency_secs);
164 // updater->Start(); 165 // updater->Start();
165 // .... 166 // ....
166 // updater->Stop(); 167 // updater->Stop();
167 class ExtensionUpdater : public URLFetcher::Delegate { 168 class ExtensionUpdater : public URLFetcher::Delegate,
169 public NotificationObserver {
168 public: 170 public:
169 // Holds a pointer to the passed |service|, using it for querying installed 171 // Holds a pointer to the passed |service|, using it for querying installed
170 // extensions and installing updated ones. The |frequency_seconds| parameter 172 // extensions and installing updated ones. The |frequency_seconds| parameter
171 // controls how often update checks are scheduled. 173 // controls how often update checks are scheduled.
172 ExtensionUpdater(ExtensionServiceInterface* service, 174 ExtensionUpdater(ExtensionServiceInterface* service,
173 ExtensionPrefs* extension_prefs, 175 ExtensionPrefs* extension_prefs,
174 PrefService* prefs, 176 PrefService* prefs,
175 Profile* profile, 177 Profile* profile,
176 int frequency_seconds); 178 int frequency_seconds);
177 179
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 ExtensionFetch(const std::string& i, const GURL& u, 216 ExtensionFetch(const std::string& i, const GURL& u,
215 const std::string& h, const std::string& v); 217 const std::string& h, const std::string& v);
216 ~ExtensionFetch(); 218 ~ExtensionFetch();
217 219
218 std::string id; 220 std::string id;
219 GURL url; 221 GURL url;
220 std::string package_hash; 222 std::string package_hash;
221 std::string version; 223 std::string version;
222 }; 224 };
223 225
226 // FetchedCRXFile holds information about a CRX file we fetched to disk,
227 // but have not yet installed.
228 struct FetchedCRXFile {
229 FetchedCRXFile();
230 FetchedCRXFile(const std::string& id,
231 const FilePath& path,
232 const GURL& download_url);
233 ~FetchedCRXFile();
234
235 std::string id;
236 FilePath path;
237 GURL download_url;
238 };
239
224 // These are needed for unit testing, to help identify the correct mock 240 // These are needed for unit testing, to help identify the correct mock
225 // URLFetcher objects. 241 // URLFetcher objects.
226 static const int kManifestFetcherId = 1; 242 static const int kManifestFetcherId = 1;
227 static const int kExtensionFetcherId = 2; 243 static const int kExtensionFetcherId = 2;
228 244
229 static const char* kBlacklistAppID; 245 static const char* kBlacklistAppID;
230 246
231 // Does common work from constructors. 247 // Does common work from constructors.
232 void Init(); 248 void Init();
233 249
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 319
304 // Send a notification if we're finished updating. 320 // Send a notification if we're finished updating.
305 void NotifyIfFinished(); 321 void NotifyIfFinished();
306 322
307 // Adds a set of ids to in_progress_ids_. 323 // Adds a set of ids to in_progress_ids_.
308 void AddToInProgress(const std::set<std::string>& ids); 324 void AddToInProgress(const std::set<std::string>& ids);
309 325
310 // Removes a set of ids from in_progress_ids_. 326 // Removes a set of ids from in_progress_ids_.
311 void RemoveFromInProgress(const std::set<std::string>& ids); 327 void RemoveFromInProgress(const std::set<std::string>& ids);
312 328
329 // If a CRX file has been fetched but not installed, and no install is
330 // currently running, start installing. Returns true if an install was
331 // started.
332 bool MaybeInstallCRXFile();
333
334 // NotificationObserver implementation.
335 virtual void Observe(NotificationType type,
336 const NotificationSource& source,
337 const NotificationDetails& details);
338
313 // Whether Start() has been called but not Stop(). 339 // Whether Start() has been called but not Stop().
314 bool alive_; 340 bool alive_;
315 341
316 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; 342 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_;
317 343
318 // Outstanding url fetch requests for manifests and updates. 344 // Outstanding url fetch requests for manifests and updates.
319 scoped_ptr<URLFetcher> manifest_fetcher_; 345 scoped_ptr<URLFetcher> manifest_fetcher_;
320 scoped_ptr<URLFetcher> extension_fetcher_; 346 scoped_ptr<URLFetcher> extension_fetcher_;
321 347
322 // Pending manifests and extensions to be fetched when the appropriate fetcher 348 // Pending manifests and extensions to be fetched when the appropriate fetcher
(...skipping 18 matching lines...) Expand all
341 bool will_check_soon_; 367 bool will_check_soon_;
342 368
343 ExtensionPrefs* extension_prefs_; 369 ExtensionPrefs* extension_prefs_;
344 PrefService* prefs_; 370 PrefService* prefs_;
345 Profile* profile_; 371 Profile* profile_;
346 bool blacklist_checks_enabled_; 372 bool blacklist_checks_enabled_;
347 373
348 // The ids of extensions that have in-progress update checks. 374 // The ids of extensions that have in-progress update checks.
349 std::set<std::string> in_progress_ids_; 375 std::set<std::string> in_progress_ids_;
350 376
377 // Observes CRX installs we initiate.
378 NotificationRegistrar registrar_;
379
380 // True when a CrxInstaller is doing an install. Used in MaybeUpdateCrxFile()
381 // to keep more than one install from running at once.
382 bool crx_install_is_running_;
383
384 // Fetched CRX files waiting to be installed.
385 std::stack<FetchedCRXFile> fetched_crx_files_;
386
351 FRIEND_TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory); 387 FRIEND_TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory);
352 FRIEND_TEST(ExtensionUpdaterTest, TestAfterStopBehavior); 388 FRIEND_TEST(ExtensionUpdaterTest, TestAfterStopBehavior);
353 389
354 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); 390 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater);
355 }; 391 };
356 392
357 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ 393 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.cc ('k') | chrome/browser/extensions/extension_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698