Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 { | |
|
Matt Perry
2011/05/31 21:34:25
I think the implementation of this can be moved to
Matt Perry
2011/05/31 21:34:25
Put CRX in caps for consistency. Same with other m
Sam Kerner (Chrome)
2011/05/31 23:16:15
Done.
Sam Kerner (Chrome)
2011/05/31 23:16:15
Done.
| |
| 229 FetchedCrxFile(); | |
| 230 FetchedCrxFile(const std::string& id, | |
| 231 const FilePath& path, | |
| 232 const GURL& download_url); | |
| 233 ~FetchedCrxFile(); | |
| 234 std::string id; | |
| 235 FilePath path; | |
| 236 GURL download_url; | |
| 237 }; | |
| 238 | |
| 224 // These are needed for unit testing, to help identify the correct mock | 239 // These are needed for unit testing, to help identify the correct mock |
| 225 // URLFetcher objects. | 240 // URLFetcher objects. |
| 226 static const int kManifestFetcherId = 1; | 241 static const int kManifestFetcherId = 1; |
| 227 static const int kExtensionFetcherId = 2; | 242 static const int kExtensionFetcherId = 2; |
| 228 | 243 |
| 229 static const char* kBlacklistAppID; | 244 static const char* kBlacklistAppID; |
| 230 | 245 |
| 231 // Does common work from constructors. | 246 // Does common work from constructors. |
| 232 void Init(); | 247 void Init(); |
| 233 | 248 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 318 |
| 304 // Send a notification if we're finished updating. | 319 // Send a notification if we're finished updating. |
| 305 void NotifyIfFinished(); | 320 void NotifyIfFinished(); |
| 306 | 321 |
| 307 // Adds a set of ids to in_progress_ids_. | 322 // Adds a set of ids to in_progress_ids_. |
| 308 void AddToInProgress(const std::set<std::string>& ids); | 323 void AddToInProgress(const std::set<std::string>& ids); |
| 309 | 324 |
| 310 // Removes a set of ids from in_progress_ids_. | 325 // Removes a set of ids from in_progress_ids_. |
| 311 void RemoveFromInProgress(const std::set<std::string>& ids); | 326 void RemoveFromInProgress(const std::set<std::string>& ids); |
| 312 | 327 |
| 328 // If a CRX file has been fetched but not installed, and no install is | |
| 329 // currently running, start installing. Returns true if an install was | |
| 330 // started. | |
| 331 bool MaybeUpdateCrxFile(); | |
|
Matt Perry
2011/05/31 21:34:25
I think MaybeInstallCRXFile would mke more sense.
Sam Kerner (Chrome)
2011/05/31 23:16:15
Done.
| |
| 332 | |
| 333 // NotificationObserver implementation. | |
| 334 virtual void Observe(NotificationType type, | |
| 335 const NotificationSource& source, | |
| 336 const NotificationDetails& details); | |
| 337 | |
| 313 // Whether Start() has been called but not Stop(). | 338 // Whether Start() has been called but not Stop(). |
| 314 bool alive_; | 339 bool alive_; |
| 315 | 340 |
| 316 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; | 341 base::WeakPtrFactory<ExtensionUpdater> weak_ptr_factory_; |
| 317 | 342 |
| 318 // Outstanding url fetch requests for manifests and updates. | 343 // Outstanding url fetch requests for manifests and updates. |
| 319 scoped_ptr<URLFetcher> manifest_fetcher_; | 344 scoped_ptr<URLFetcher> manifest_fetcher_; |
| 320 scoped_ptr<URLFetcher> extension_fetcher_; | 345 scoped_ptr<URLFetcher> extension_fetcher_; |
| 321 | 346 |
| 322 // Pending manifests and extensions to be fetched when the appropriate fetcher | 347 // Pending manifests and extensions to be fetched when the appropriate fetcher |
| 323 // is available. | 348 // is available. |
| 324 std::deque<ManifestFetchData*> manifests_pending_; | 349 std::deque<ManifestFetchData*> manifests_pending_; |
| 325 std::deque<ExtensionFetch> extensions_pending_; | 350 std::deque<ExtensionFetch> extensions_pending_; |
| 326 | 351 |
|
Matt Perry
2011/05/31 21:34:25
nit: remove extra newline
Sam Kerner (Chrome)
2011/05/31 23:16:15
Done.
| |
| 352 | |
| 327 // The manifest currently being fetched (if any). | 353 // The manifest currently being fetched (if any). |
| 328 scoped_ptr<ManifestFetchData> current_manifest_fetch_; | 354 scoped_ptr<ManifestFetchData> current_manifest_fetch_; |
| 329 | 355 |
| 330 // The extension currently being fetched (if any). | 356 // The extension currently being fetched (if any). |
| 331 ExtensionFetch current_extension_fetch_; | 357 ExtensionFetch current_extension_fetch_; |
| 332 | 358 |
| 333 // Pointer back to the service that owns this ExtensionUpdater. | 359 // Pointer back to the service that owns this ExtensionUpdater. |
| 334 ExtensionServiceInterface* service_; | 360 ExtensionServiceInterface* service_; |
| 335 | 361 |
| 336 base::OneShotTimer<ExtensionUpdater> timer_; | 362 base::OneShotTimer<ExtensionUpdater> timer_; |
| 337 int frequency_seconds_; | 363 int frequency_seconds_; |
| 338 | 364 |
| 339 ScopedRunnableMethodFactory<ExtensionUpdater> method_factory_; | 365 ScopedRunnableMethodFactory<ExtensionUpdater> method_factory_; |
| 340 | 366 |
| 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_ |
| OLD | NEW |