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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
14 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h"
16 #include "base/gtest_prod_util.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/prefs/pref_change_registrar.h"
20 #include "base/strings/string16.h"
21 #include "chrome/browser/extensions/blacklist.h"
22 #include "chrome/browser/extensions/extension_function_histogram_value.h"
23 #include "chrome/browser/extensions/extension_icon_manager.h"
24 #include "chrome/browser/extensions/extension_prefs.h"
25 #include "chrome/browser/extensions/extension_process_manager.h"
26 #include "chrome/browser/extensions/extension_sync_service.h"
27 #include "chrome/browser/extensions/extension_toolbar_model.h"
28 #include "chrome/browser/extensions/extensions_quota_service.h"
29 #include "chrome/browser/extensions/external_provider_interface.h"
30 #include "chrome/browser/extensions/management_policy.h"
31 #include "chrome/browser/extensions/menu_manager.h"
32 #include "chrome/browser/extensions/pending_enables.h"
33 #include "chrome/browser/extensions/pending_extension_manager.h"
34 #include "chrome/browser/extensions/process_map.h"
35 #include "chrome/browser/extensions/update_observer.h"
36 #include "chrome/common/extensions/extension.h"
37 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/extensions/extension_set.h"
39 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
40 #include "content/public/browser/devtools_agent_host.h"
41 #include "content/public/browser/notification_observer.h"
42 #include "content/public/browser/notification_registrar.h"
43 #include "extensions/common/manifest.h"
44 #include "extensions/common/one_shot_event.h"
47 class ExtensionErrorUI;
48 class ExtensionToolbarModel;
53 class SequencedTaskRunner;
57 namespace extensions {
58 class BrowserEventRouter;
59 class ComponentLoader;
60 class ContentSettingsStore;
62 class ExtensionActionStorageManager;
63 class ExtensionSystem;
64 class ExtensionUpdater;
65 class PendingExtensionManager;
66 class SettingsFrontend;
67 } // namespace extensions
70 class SyncErrorFactory;
73 // This is an interface class to encapsulate the dependencies that
74 // various classes have on ExtensionService. This allows easy mocking.
75 class ExtensionServiceInterface
76 : public base::SupportsWeakPtr<ExtensionServiceInterface> {
78 virtual ~ExtensionServiceInterface() {}
79 virtual const ExtensionSet* extensions() const = 0;
80 virtual const ExtensionSet* disabled_extensions() const = 0;
81 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
83 // Install an update. Return true if the install can be started.
84 // Set out_crx_installer to the installer if one was started.
85 virtual bool UpdateExtension(
86 const std::string& id,
87 const base::FilePath& path,
88 const GURL& download_url,
89 extensions::CrxInstaller** out_crx_installer) = 0;
90 virtual const extensions::Extension* GetExtensionById(
91 const std::string& id,
92 bool include_disabled) const = 0;
93 virtual const extensions::Extension* GetInstalledExtension(
94 const std::string& id) const = 0;
96 virtual const extensions::Extension* GetPendingExtensionUpdate(
97 const std::string& extension_id) const = 0;
98 virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
100 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
101 virtual bool IsExternalExtensionUninstalled(
102 const std::string& extension_id) const = 0;
104 virtual void CheckManagementPolicy() = 0;
106 // Safe to call multiple times in a row.
108 // TODO(akalin): Remove this method (and others) once we refactor
109 // themes sync to not use it directly.
110 virtual void CheckForUpdatesSoon() = 0;
112 virtual void AddExtension(const extensions::Extension* extension) = 0;
113 virtual void AddComponentExtension(
114 const extensions::Extension* extension) = 0;
116 virtual void UnloadExtension(
117 const std::string& extension_id,
118 extensions::UnloadedExtensionInfo::Reason reason) = 0;
119 virtual void RemoveComponentExtension(const std::string& extension_id) = 0;
121 virtual bool is_ready() = 0;
123 // Returns task runner for crx installation file I/O operations.
124 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
127 // Manages installed and running Chromium extensions.
128 class ExtensionService
129 : public ExtensionServiceInterface,
130 public extensions::ExternalProviderInterface::VisitorInterface,
131 public content::NotificationObserver,
132 public extensions::Blacklist::Observer {
134 // Returns the Extension of hosted or packaged apps, NULL otherwise.
135 const extensions::Extension* GetInstalledApp(const GURL& url) const;
137 // Returns whether the URL is from either a hosted or packaged app.
138 bool IsInstalledApp(const GURL& url) const;
140 // Attempts to uninstall an extension from a given ExtensionService. Returns
141 // true iff the target extension exists.
142 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
143 const std::string& extension_id);
145 // Constructor stores pointers to |profile| and |extension_prefs| but
146 // ownership remains at caller.
147 ExtensionService(Profile* profile,
148 const CommandLine* command_line,
149 const base::FilePath& install_directory,
150 extensions::ExtensionPrefs* extension_prefs,
151 extensions::Blacklist* blacklist,
152 bool autoupdate_enabled,
153 bool extensions_enabled,
154 extensions::OneShotEvent* ready);
156 virtual ~ExtensionService();
158 // Gets the list of currently installed extensions.
159 virtual const ExtensionSet* extensions() const OVERRIDE;
160 virtual const ExtensionSet* disabled_extensions() const OVERRIDE;
161 const ExtensionSet* terminated_extensions() const;
162 const ExtensionSet* blacklisted_extensions() const;
163 const ExtensionSet* delayed_installs() const;
165 // Returns a set of all installed, disabled, blacklisted, and terminated
167 scoped_ptr<const ExtensionSet> GenerateInstalledExtensionsSet() const;
169 // Gets the object managing the set of pending extensions.
170 virtual extensions::PendingExtensionManager*
171 pending_extension_manager() OVERRIDE;
173 const base::FilePath& install_directory() const { return install_directory_; }
175 extensions::ProcessMap* process_map() { return &process_map_; }
177 // Updates the app launcher value for the moved extension so that it is now
178 // located after the given predecessor and before the successor. This will
179 // trigger a sync if needed. Empty strings are used to indicate no successor
181 void OnExtensionMoved(const std::string& moved_extension_id,
182 const std::string& predecessor_extension_id,
183 const std::string& successor_extension_id);
185 // Whether the persistent background page, if any, is ready. We don't load
186 // other components until then. If there is no background page, or if it is
187 // non-persistent (lazy), we consider it to be ready.
188 bool IsBackgroundPageReady(const extensions::Extension* extension) const;
189 void SetBackgroundPageReady(const extensions::Extension* extension);
191 // Getter and setter for the flag that specifies whether the extension is
193 bool IsBeingUpgraded(const extensions::Extension* extension) const;
194 void SetBeingUpgraded(const extensions::Extension* extension, bool value);
196 // Getter and setter for the flag that specifies whether the extension is
198 bool IsBeingReloaded(const std::string& extension_id) const;
199 void SetBeingReloaded(const std::string& extension_id, bool value);
201 // Getter and setter for the flag that specifies if the extension has used
202 // the webrequest API.
203 // TODO(mpcomplete): remove. http://crbug.com/100411
204 bool HasUsedWebRequest(const extensions::Extension* extension) const;
205 void SetHasUsedWebRequest(const extensions::Extension* extension, bool value);
207 // Initialize and start all installed extensions.
210 // Called when the associated Profile is going to be destroyed.
213 // Look up an extension by ID. Does not include terminated
215 virtual const extensions::Extension* GetExtensionById(
216 const std::string& id, bool include_disabled) const OVERRIDE;
220 INCLUDE_ENABLED = 1 << 0,
221 INCLUDE_DISABLED = 1 << 1,
222 INCLUDE_TERMINATED = 1 << 2,
223 INCLUDE_BLACKLISTED = 1 << 3,
224 INCLUDE_EVERYTHING = (1 << 4) - 1,
227 // Look up an extension by ID, selecting which sets to look in:
228 // * extensions() --> INCLUDE_ENABLED
229 // * disabled_extensions() --> INCLUDE_DISABLED
230 // * terminated_extensions() --> INCLUDE_TERMINATED
231 // * blacklisted_extensions() --> INCLUDE_BLACKLISTED
232 const extensions::Extension* GetExtensionById(const std::string& id,
233 int include_mask) const;
235 // Returns the site of the given |extension_id|. Suitable for use with
236 // BrowserContext::GetStoragePartitionForSite().
237 GURL GetSiteForExtensionId(const std::string& extension_id);
239 // Looks up a terminated (crashed) extension by ID.
240 const extensions::Extension*
241 GetTerminatedExtension(const std::string& id) const;
243 // Looks up an extension by ID, regardless of whether it's enabled,
244 // disabled, blacklisted, or terminated.
245 virtual const extensions::Extension* GetInstalledExtension(
246 const std::string& id) const OVERRIDE;
248 // Updates a currently-installed extension with the contents from
250 // TODO(aa): This method can be removed. ExtensionUpdater could use
251 // CrxInstaller directly instead.
252 virtual bool UpdateExtension(
253 const std::string& id,
254 const base::FilePath& extension_path,
255 const GURL& download_url,
256 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
258 // Reloads the specified extension, sending the onLaunched() event to it if it
259 // currently has any window showing.
260 void ReloadExtension(const std::string extension_id);
262 // Uninstalls the specified extension. Callers should only call this method
263 // with extensions that exist. |external_uninstall| is a magical parameter
264 // that is only used to send information to ExtensionPrefs, which external
265 // callers should never set to true.
267 // We pass the |extension_id| by value to avoid having it deleted from under
268 // us incase someone calls it with Extension::id() or another string that we
269 // are going to delete in this function.
271 // TODO(aa): Remove |external_uninstall| -- this information should be passed
272 // to ExtensionPrefs some other way.
273 virtual bool UninstallExtension(std::string extension_id,
274 bool external_uninstall,
277 virtual bool IsExtensionEnabled(
278 const std::string& extension_id) const OVERRIDE;
279 virtual bool IsExternalExtensionUninstalled(
280 const std::string& extension_id) const OVERRIDE;
282 // Whether the extension should show as enabled state in launcher.
283 bool IsExtensionEnabledForLauncher(const std::string& extension_id) const;
285 // Enables the extension. If the extension is already enabled, does
287 virtual void EnableExtension(const std::string& extension_id);
289 // Disables the extension. If the extension is already disabled, or
290 // cannot be disabled, does nothing.
291 virtual void DisableExtension(const std::string& extension_id,
292 extensions::Extension::DisableReason disable_reason);
294 // Disable non-default and non-managed extensions with ids not in
295 // |except_ids|. Default extensions are those from the Web Store with
296 // |was_installed_by_default| flag.
297 void DisableUserExtensions(const std::vector<std::string>& except_ids);
299 // Updates the |extension|'s granted permissions lists to include all
300 // permissions in the |extension|'s manifest and re-enables the
302 void GrantPermissionsAndEnableExtension(
303 const extensions::Extension* extension);
305 // Updates the |extension|'s granted permissions lists to include all
306 // permissions in the |extensions|'s manifest.
307 void GrantPermissions(
308 const extensions::Extension* extension);
310 // Check for updates (or potentially new extensions from external providers)
311 void CheckForExternalUpdates();
313 // Unload the specified extension.
314 virtual void UnloadExtension(
315 const std::string& extension_id,
316 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
318 // Remove the specified component extension.
319 virtual void RemoveComponentExtension(const std::string& extension_id)
322 // Unload all extensions. This is currently only called on shutdown, and
323 // does not send notifications.
324 void UnloadAllExtensions();
326 // Called only by testing.
327 void ReloadExtensions();
329 // Scan the extension directory and clean up the cruft.
330 void GarbageCollectExtensions();
332 // Returns true if |url| should get extension api bindings and be permitted
333 // to make api calls. Note that this is independent of what extension
334 // permissions the given extension has been granted.
335 bool ExtensionBindingsAllowed(const GURL& url);
337 // Returns true if a normal browser window should avoid showing |url| in a
338 // tab. In this case, |url| is also rewritten to an error URL.
339 bool ShouldBlockUrlInBrowserTab(GURL* url);
341 // Called when the initial extensions load has completed.
342 virtual void OnLoadedInstalledExtensions();
344 // Adds |extension| to this ExtensionService and notifies observers that the
345 // extensions have been loaded.
346 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
348 // Check if we have preferences for the component extension and, if not or if
349 // the stored version differs, install the extension (without requirements
350 // checking) before calling AddExtension.
351 virtual void AddComponentExtension(const extensions::Extension* extension)
356 IMPORT_STATUS_UNSATISFIED,
357 IMPORT_STATUS_UNRECOVERABLE
360 // Checks an extension's imports. No installed and outdated imports will be
361 // stored in |missing_modules| and |outdated_modules|.
362 ImportStatus CheckImports(
363 const extensions::Extension* extension,
364 std::list<extensions::SharedModuleInfo::ImportInfo>* missing_modules,
365 std::list<extensions::SharedModuleInfo::ImportInfo>* outdated_modules);
367 // Checks an extension's shared module imports to see if they are satisfied.
368 // If they are not, this function adds the dependencies to the pending install
369 // list if |extension| came from the webstore.
370 ImportStatus SatisfyImports(const extensions::Extension* extension);
372 // Returns a set of extensions that import a given extension.
373 scoped_ptr<const ExtensionSet> GetDependentExtensions(
374 const extensions::Extension* extension);
376 // Uninstalls shared modules that were only referenced by |extension|.
377 void PruneSharedModulesOnUninstall(const extensions::Extension* extension);
379 // Informs the service that an extension's files are in place for loading.
381 // |page_ordinal| is the location of the extension in the app launcher.
382 // |has_requirement_errors| is true if requirements of the extension weren't
383 // met (for example graphics capabilities).
384 // |blacklist_state| will be BLACKLISTED if the extension is blacklisted.
385 // |wait_for_idle| may be false to install the extension immediately.
386 void OnExtensionInstalled(
387 const extensions::Extension* extension,
388 const syncer::StringOrdinal& page_ordinal,
389 bool has_requirement_errors,
390 extensions::Blacklist::BlacklistState blacklist_state,
393 // Checks for delayed installation for all pending installs.
394 void MaybeFinishDelayedInstallations();
396 // Similar to FinishInstallation, but first checks if there still is an update
397 // pending for the extension, and makes sure the extension is still idle.
398 void MaybeFinishDelayedInstallation(const std::string& extension_id);
400 // Finishes installation of an update for an extension with the specified id,
401 // when installation of that extension was previously delayed because the
402 // extension was in use.
403 virtual void FinishDelayedInstallation(
404 const std::string& extension_id) OVERRIDE;
406 // Returns an update for an extension with the specified id, if installation
407 // of that update was previously delayed because the extension was in use. If
408 // no updates are pending for the extension returns NULL.
409 virtual const extensions::Extension* GetPendingExtensionUpdate(
410 const std::string& extension_id) const OVERRIDE;
412 // Go through each extension and unload those that are not allowed to run by
413 // management policy providers (ie. network admin and Google-managed
415 virtual void CheckManagementPolicy() OVERRIDE;
417 virtual void CheckForUpdatesSoon() OVERRIDE;
419 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
420 bool extensions_enabled() { return extensions_enabled_; }
422 void set_show_extensions_prompts(bool enabled) {
423 show_extensions_prompts_ = enabled;
426 bool show_extensions_prompts() {
427 return show_extensions_prompts_;
432 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
433 // ExtensionPrefs* mutable_extension_prefs().
434 extensions::ExtensionPrefs* extension_prefs();
435 const extensions::ExtensionPrefs* extension_prefs() const;
437 extensions::SettingsFrontend* settings_frontend();
439 void set_extension_sync_service(
440 ExtensionSyncService* extension_sync_service) {
441 extension_sync_service_ = extension_sync_service;
444 extensions::ContentSettingsStore* GetContentSettingsStore();
446 // Whether the extension service is ready.
447 virtual bool is_ready() OVERRIDE;
449 virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
451 extensions::ComponentLoader* component_loader() {
452 return component_loader_.get();
455 // Note that this may return NULL if autoupdate is not turned on.
456 extensions::ExtensionUpdater* updater();
458 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; }
460 ExtensionsQuotaService* quota_service() { return "a_service_; }
462 extensions::MenuManager* menu_manager() { return &menu_manager_; }
464 // Notify the frontend that there was an error loading an extension.
465 // This method is public because UnpackedInstaller and InstalledLoader
467 // TODO(aa): Remove this. It doesn't do enough to be worth the dependency
468 // of these classes on ExtensionService.
469 void ReportExtensionLoadError(const base::FilePath& extension_path,
470 const std::string& error,
473 // ExtensionHost of background page calls this method right after its render
474 // view has been created.
475 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
477 // For the extension in |version_path| with |id|, check to see if it's an
478 // externally managed extension. If so, uninstall it.
479 void CheckExternalUninstall(const std::string& id);
481 // Changes sequenced task runner for crx installation tasks to |task_runner|.
482 void SetFileTaskRunnerForTesting(base::SequencedTaskRunner* task_runner);
484 // Clear all ExternalProviders.
485 void ClearProvidersForTesting();
487 // Adds an ExternalProviderInterface for the service to use during testing.
488 // Takes ownership of |test_provider|.
489 void AddProviderForTesting(
490 extensions::ExternalProviderInterface* test_provider);
492 // ExternalProvider::Visitor implementation.
493 virtual bool OnExternalExtensionFileFound(
494 const std::string& id,
495 const base::Version* version,
496 const base::FilePath& path,
497 extensions::Manifest::Location location,
499 bool mark_acknowledged) OVERRIDE;
501 virtual bool OnExternalExtensionUpdateUrlFound(
502 const std::string& id,
503 const GURL& update_url,
504 extensions::Manifest::Location location,
506 bool mark_acknowledged) OVERRIDE;
508 virtual void OnExternalProviderReady(
509 const extensions::ExternalProviderInterface* provider) OVERRIDE;
511 // Returns true when all the external extension providers are ready.
512 bool AreAllExternalProvidersReady() const;
514 void OnAllExternalProvidersReady();
516 // Once all external providers are done, generates any needed alerts about
518 void IdentifyAlertableExtensions();
520 // Given an ExtensionErrorUI alert, populates it with any extensions that
521 // need alerting. Returns true if the alert should be displayed at all.
523 // This method takes the extension_error_ui argument rather than using
524 // the member variable to make it easier to test the method in isolation.
525 bool PopulateExtensionErrorUI(ExtensionErrorUI* extension_error_ui);
527 // Checks if there are any new external extensions to notify the user about.
528 void UpdateExternalExtensionAlert();
530 // Given a (presumably just-installed) extension id, mark that extension as
532 void AcknowledgeExternalExtension(const std::string& id);
534 // Returns true if this extension is an external one that has yet to be
535 // marked as acknowledged.
536 bool IsUnacknowledgedExternalExtension(
537 const extensions::Extension* extension);
539 // Disable extensions that are known to be disabled yet are currently enabled.
540 void ReconcileKnownDisabled();
542 // Opens the Extensions page because the user wants to get more details
544 void HandleExtensionAlertDetails();
546 // Called when the extension alert is closed. Updates prefs and deletes
547 // the active |extension_error_ui_|.
548 void HandleExtensionAlertClosed();
550 // Marks alertable extensions as acknowledged, after the user presses the
552 void HandleExtensionAlertAccept();
554 // content::NotificationObserver
555 virtual void Observe(int type,
556 const content::NotificationSource& source,
557 const content::NotificationDetails& details) OVERRIDE;
559 // Whether there are any apps installed. Component apps are not included.
560 bool HasApps() const;
562 // Gets the set of loaded app ids. Component apps are not included.
563 extensions::ExtensionIdSet GetAppIds() const;
565 // Record a histogram using the PermissionMessage enum values for each
566 // permission in |e|.
567 // NOTE: If this is ever called with high frequency, the implementation may
568 // need to be made more efficient.
569 static void RecordPermissionMessagesHistogram(
570 const extensions::Extension* e, const char* histogram);
572 #if defined(UNIT_TEST)
573 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
574 TrackTerminatedExtension(extension);
577 void FinishInstallationForTest(const extensions::Extension* extension) {
578 FinishInstallation(extension);
582 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
584 bool browser_terminating() const { return browser_terminating_; }
587 void set_browser_terminating_for_test(bool value) {
588 browser_terminating_ = value;
591 // By default ExtensionService will wait with installing an updated extension
592 // until the extension is idle. Tests might not like this behavior, so you can
593 // disable it with this method.
594 void set_install_updates_when_idle_for_test(bool value) {
595 install_updates_when_idle_ = value;
598 // Adds/Removes update observers.
599 void AddUpdateObserver(extensions::UpdateObserver* observer);
600 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
602 #if defined(OS_CHROMEOS)
603 void disable_garbage_collection() {
604 disable_garbage_collection_ = true;
606 void enable_garbage_collection() {
607 disable_garbage_collection_ = false;
612 // Contains Extension data that can change during the life of the process,
613 // but does not persist across restarts.
614 struct ExtensionRuntimeData {
615 // True if the background page is ready.
616 bool background_page_ready;
618 // True while the extension is being upgraded.
621 // True if the extension has used the webRequest API.
622 bool has_used_webrequest;
624 ExtensionRuntimeData();
625 ~ExtensionRuntimeData();
627 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
629 // Signals *ready_ and sends a notification to the listeners.
630 void SetReadyAndNotifyListeners();
632 // Return true if the sync type of |extension| matches |type|.
633 void OnExtensionInstallPrefChanged();
635 // Adds the given extension to the list of terminated extensions if
636 // it is not already there and unloads it.
637 void TrackTerminatedExtension(const extensions::Extension* extension);
639 // Removes the extension with the given id from the list of
640 // terminated extensions if it is there.
641 void UntrackTerminatedExtension(const std::string& id);
643 // Update preferences for a new or updated extension; notify observers that
644 // the extension is installed, e.g., to update event handlers on background
645 // pages; and perform other extension install tasks before calling
647 void AddNewOrUpdatedExtension(
648 const extensions::Extension* extension,
649 extensions::Extension::State initial_state,
650 extensions::Blacklist::BlacklistState blacklist_state,
651 const syncer::StringOrdinal& page_ordinal);
653 // Handles sending notification that |extension| was loaded.
654 void NotifyExtensionLoaded(const extensions::Extension* extension);
656 // Handles sending notification that |extension| was unloaded.
657 void NotifyExtensionUnloaded(
658 const extensions::Extension* extension,
659 extensions::UnloadedExtensionInfo::Reason reason);
661 // Common helper to finish installing the given extension.
662 void FinishInstallation(const extensions::Extension* extension);
664 // Updates the |extension|'s active permission set to include only permissions
665 // currently requested by the extension and all the permissions required by
667 void UpdateActivePermissions(const extensions::Extension* extension);
669 // Disables the extension if the privilege level has increased
670 // (e.g., due to an upgrade).
671 void CheckPermissionsIncrease(const extensions::Extension* extension,
672 bool is_extension_installed);
674 // Helper that updates the active extension list used for crash reporting.
675 void UpdateActiveExtensionsInCrashReporter();
677 // Helper to determine whether we should initially enable an installed
678 // (or upgraded) extension.
679 bool ShouldEnableOnInstall(const extensions::Extension* extension);
681 // Helper to determine if an extension is idle, and it should be safe
682 // to update the extension.
683 bool IsExtensionIdle(const std::string& extension_id) const;
685 // Helper to determine if updating an extensions should proceed immediately,
686 // or if we should delay the update until further notice.
687 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
688 bool wait_for_idle) const;
690 // Helper to search storage directories for extensions with isolated storage
691 // that have been orphaned by an uninstall.
692 void GarbageCollectIsolatedStorage();
693 void OnGarbageCollectIsolatedStorageFinished();
694 void OnNeedsToGarbageCollectIsolatedStorage();
696 // extensions::Blacklist::Observer implementation.
697 virtual void OnBlacklistUpdated() OVERRIDE;
699 // Manages the blacklisted extensions, intended as callback from
700 // Blacklist::GetBlacklistedIDs.
701 void ManageBlacklist(const std::set<std::string>& blacklisted_ids);
703 // Controls if installs are delayed. See comment for
704 // |installs_delayed_for_gc_|.
705 void set_installs_delayed_for_gc(bool value) {
706 installs_delayed_for_gc_ = value;
708 bool installs_delayed_for_gc() const { return installs_delayed_for_gc_; }
710 // The normal profile associated with this ExtensionService.
713 // The ExtensionSystem for the profile above.
714 extensions::ExtensionSystem* system_;
716 // Preferences for the owning profile.
717 extensions::ExtensionPrefs* extension_prefs_;
719 // Blacklist for the owning profile.
720 extensions::Blacklist* blacklist_;
722 // Settings for the owning profile.
723 scoped_ptr<extensions::SettingsFrontend> settings_frontend_;
725 // The ExtensionSyncService that is used by this ExtensionService.
726 ExtensionSyncService* extension_sync_service_;
728 // The current list of installed extensions.
729 ExtensionSet extensions_;
731 // The list of installed extensions that have been disabled.
732 ExtensionSet disabled_extensions_;
734 // The list of installed extensions that have been terminated.
735 ExtensionSet terminated_extensions_;
737 // The list of installed extensions that have been blacklisted. Generally
738 // these shouldn't be considered as installed by the extension platform: we
739 // only keep them around so that if extensions are blacklisted by mistake
740 // they can easily be un-blacklisted.
741 ExtensionSet blacklisted_extensions_;
743 // The list of extension installs delayed for various reasons. The reason
744 // for delayed install is stored in ExtensionPrefs.
745 ExtensionSet delayed_installs_;
747 // Hold the set of pending extensions.
748 extensions::PendingExtensionManager pending_extension_manager_;
750 // The map of extension IDs to their runtime data.
751 ExtensionRuntimeDataMap extension_runtime_data_;
753 // The full path to the directory where extensions are installed.
754 base::FilePath install_directory_;
756 // Whether or not extensions are enabled.
757 bool extensions_enabled_;
759 // Whether to notify users when they attempt to install an extension.
760 bool show_extensions_prompts_;
762 // Whether to delay installing of extension updates until the extension is
764 bool install_updates_when_idle_;
766 // Used by dispatchers to limit API quota for individual extensions.
767 ExtensionsQuotaService quota_service_;
769 // Signaled when all extensions are loaded.
770 extensions::OneShotEvent* const ready_;
772 // Our extension updater, if updates are turned on.
773 scoped_ptr<extensions::ExtensionUpdater> updater_;
775 // The model that tracks extensions with BrowserAction buttons.
776 ExtensionToolbarModel toolbar_model_;
778 // Map unloaded extensions' ids to their paths. When a temporarily loaded
779 // extension is unloaded, we lose the information about it and don't have
780 // any in the extension preferences file.
781 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
782 UnloadedExtensionPathMap unloaded_extension_paths_;
784 // Store the ids of reloading extensions.
785 std::set<std::string> reloading_extensions_;
787 // Map of DevToolsAgentHost instances that are detached,
788 // waiting for an extension to be reloaded.
789 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
791 OrphanedDevTools orphaned_dev_tools_;
793 content::NotificationRegistrar registrar_;
794 PrefChangeRegistrar pref_change_registrar_;
796 // Keeps track of loading and unloading component extensions.
797 scoped_ptr<extensions::ComponentLoader> component_loader_;
799 // Keeps track of menu items added by extensions.
800 extensions::MenuManager menu_manager_;
802 // A collection of external extension providers. Each provider reads
803 // a source of external extension information. Examples include the
804 // windows registry and external_extensions.json.
805 extensions::ProviderCollection external_extension_providers_;
807 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
808 // extension URL is found, and by CheckForUpdatesSoon() when an update check
809 // has to wait for the external providers. Used in
810 // OnAllExternalProvidersReady() to determine if an update check is needed to
811 // install pending extensions.
812 bool update_once_all_providers_are_ready_;
814 // Set when the browser is terminating. Prevents us from installing or
815 // updating additional extensions and allows in-progress installations to
817 bool browser_terminating_;
819 // Set to true to delay all new extension installations. Acts as a lock to
820 // allow background processing of garbage collection of on-disk state without
821 // needing to worry about race conditions caused by extension installation and
823 bool installs_delayed_for_gc_;
825 // Set to true if this is the first time this ExtensionService has run.
826 // Used for specially handling external extensions that are installed the
830 extensions::ProcessMap process_map_;
832 // A set of the extension ids currently being reloaded. We use this to
833 // avoid showing a "new install" notice for an extension reinstall.
834 std::set<std::string> extensions_being_reloaded_;
836 scoped_ptr<ExtensionErrorUI> extension_error_ui_;
837 // Sequenced task runner for extension related file operations.
838 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
840 #if defined(ENABLE_EXTENSIONS)
841 scoped_ptr<extensions::ExtensionActionStorageManager>
842 extension_action_storage_manager_;
844 scoped_ptr<extensions::ManagementPolicy::Provider>
845 shared_module_policy_provider_;
847 ObserverList<extensions::UpdateObserver, true> update_observers_;
849 #if defined(OS_CHROMEOS)
850 // TODO(rkc): HACK alert - this is only in place to allow the
851 // kiosk_mode_screensaver to prevent its extension from getting garbage
852 // collected. Remove this once KioskModeScreensaver is removed.
853 // See crbug.com/280363
854 bool disable_garbage_collection_;
857 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
858 InstallAppsWithUnlimtedStorage);
859 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
860 InstallAppsAndCheckStorageProtection);
861 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
864 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_