Home | History | Annotate | Download | only in extensions
      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.
      4 
      5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
      6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
      7 
      8 #include <map>
      9 #include <set>
     10 #include <string>
     11 #include <vector>
     12 
     13 #include "base/compiler_specific.h"
     14 #include "base/files/file_path.h"
     15 #include "base/gtest_prod_util.h"
     16 #include "base/memory/ref_counted.h"
     17 #include "base/memory/weak_ptr.h"
     18 #include "base/strings/string16.h"
     19 #include "chrome/browser/extensions/blacklist.h"
     20 #include "chrome/browser/extensions/extension_management.h"
     21 #include "chrome/browser/extensions/pending_extension_manager.h"
     22 #include "content/public/browser/notification_observer.h"
     23 #include "content/public/browser/notification_registrar.h"
     24 #include "extensions/browser/external_provider_interface.h"
     25 #include "extensions/browser/install_flag.h"
     26 #include "extensions/browser/management_policy.h"
     27 #include "extensions/browser/process_manager.h"
     28 #include "extensions/browser/uninstall_reason.h"
     29 #include "extensions/common/extension.h"
     30 #include "extensions/common/extension_set.h"
     31 #include "extensions/common/manifest.h"
     32 #include "sync/api/string_ordinal.h"
     33 
     34 class ExtensionSyncService;
     35 class GURL;
     36 class HostContentSettingsMap;
     37 class Profile;
     38 
     39 namespace base {
     40 class CommandLine;
     41 class SequencedTaskRunner;
     42 class Version;
     43 }
     44 
     45 namespace content {
     46 class DevToolsAgentHost;
     47 }
     48 
     49 namespace extensions {
     50 class ComponentLoader;
     51 class CrxInstaller;
     52 class ExtensionActionStorageManager;
     53 class ExtensionDownloader;
     54 class ExtensionDownloaderDelegate;
     55 class ExtensionErrorController;
     56 class ExtensionRegistry;
     57 class ExtensionSystem;
     58 class ExtensionUpdater;
     59 class OneShotEvent;
     60 class ExternalInstallManager;
     61 class SharedModuleService;
     62 class UpdateObserver;
     63 }  // namespace extensions
     64 
     65 // This is an interface class to encapsulate the dependencies that
     66 // various classes have on ExtensionService. This allows easy mocking.
     67 class ExtensionServiceInterface
     68     : public base::SupportsWeakPtr<ExtensionServiceInterface> {
     69  public:
     70   virtual ~ExtensionServiceInterface() {}
     71 
     72   // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
     73   //
     74   // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
     75   virtual const extensions::ExtensionSet* extensions() const = 0;
     76 
     77   // Gets the object managing the set of pending extensions.
     78   virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
     79 
     80   // Installs an update with the contents from |extension_path|. Returns true if
     81   // the install can be started. Sets |out_crx_installer| to the installer if
     82   // one was started.
     83   // TODO(aa): This method can be removed. ExtensionUpdater could use
     84   // CrxInstaller directly instead.
     85   virtual bool UpdateExtension(
     86       const std::string& id,
     87       const base::FilePath& path,
     88       bool file_ownership_passed,
     89       extensions::CrxInstaller** out_crx_installer) = 0;
     90 
     91   // DEPRECATED. Use ExtensionRegistry instead.
     92   //
     93   // Looks up an extension by its ID.
     94   //
     95   // If |include_disabled| is false then this will only include enabled
     96   // extensions. Use instead:
     97   //
     98   //   ExtensionRegistry::enabled_extensions().GetByID(id).
     99   //
    100   // If |include_disabled| is true then this will also include disabled and
    101   // blacklisted extensions (not terminated extensions). Use instead:
    102   //
    103   //   ExtensionRegistry::GetExtensionById(
    104   //         id, ExtensionRegistry::ENABLED |
    105   //             ExtensionRegistry::DISABLED |
    106   //             ExtensionRegistry::BLACKLISTED)
    107   //
    108   // Or don't, because it's probably not something you ever need to know.
    109   virtual const extensions::Extension* GetExtensionById(
    110       const std::string& id,
    111       bool include_disabled) const = 0;
    112 
    113   // DEPRECATED: Use ExtensionRegistry instead.
    114   //
    115   // Looks up an extension by ID, regardless of whether it's enabled,
    116   // disabled, blacklisted, or terminated. Use instead:
    117   //
    118   //   ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING).
    119   virtual const extensions::Extension* GetInstalledExtension(
    120       const std::string& id) const = 0;
    121 
    122   // Returns an update for an extension with the specified id, if installation
    123   // of that update was previously delayed because the extension was in use. If
    124   // no updates are pending for the extension returns NULL.
    125   virtual const extensions::Extension* GetPendingExtensionUpdate(
    126       const std::string& extension_id) const = 0;
    127 
    128   // Finishes installation of an update for an extension with the specified id,
    129   // when installation of that extension was previously delayed because the
    130   // extension was in use.
    131   virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
    132 
    133   // Returns true if the extension with the given |extension_id| is enabled.
    134   // This will return a valid answer even if the extension is not loaded yet.
    135   virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
    136 
    137   // Go through each extension and unload those that are not allowed to run by
    138   // management policy providers (ie. network admin and Google-managed
    139   // blacklist).
    140   virtual void CheckManagementPolicy() = 0;
    141 
    142   // Safe to call multiple times in a row.
    143   //
    144   // TODO(akalin): Remove this method (and others) once we refactor
    145   // themes sync to not use it directly.
    146   virtual void CheckForUpdatesSoon() = 0;
    147 
    148   // Adds |extension| to this ExtensionService and notifies observers that the
    149   // extensions have been loaded.
    150   virtual void AddExtension(const extensions::Extension* extension) = 0;
    151 
    152   // Check if we have preferences for the component extension and, if not or if
    153   // the stored version differs, install the extension (without requirements
    154   // checking) before calling AddExtension.
    155   virtual void AddComponentExtension(
    156       const extensions::Extension* extension) = 0;
    157 
    158   // Unload the specified extension.
    159   virtual void UnloadExtension(
    160       const std::string& extension_id,
    161       extensions::UnloadedExtensionInfo::Reason reason) = 0;
    162 
    163   // Remove the specified component extension.
    164   virtual void RemoveComponentExtension(const std::string& extension_id) = 0;
    165 
    166   // Whether the extension service is ready.
    167   virtual bool is_ready() = 0;
    168 
    169   // Returns task runner for crx installation file I/O operations.
    170   virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
    171 };
    172 
    173 // Manages installed and running Chromium extensions. An instance is shared
    174 // between normal and incognito profiles.
    175 class ExtensionService
    176     : public ExtensionServiceInterface,
    177       public extensions::ExternalProviderInterface::VisitorInterface,
    178       public content::NotificationObserver,
    179       public extensions::Blacklist::Observer,
    180       public extensions::ExtensionManagement::Observer {
    181  public:
    182   // Attempts to uninstall an extension from a given ExtensionService. Returns
    183   // true iff the target extension exists.
    184   static bool UninstallExtensionHelper(ExtensionService* extensions_service,
    185                                        const std::string& extension_id,
    186                                        extensions::UninstallReason reason);
    187 
    188   // Constructor stores pointers to |profile| and |extension_prefs| but
    189   // ownership remains at caller.
    190   ExtensionService(Profile* profile,
    191                    const base::CommandLine* command_line,
    192                    const base::FilePath& install_directory,
    193                    extensions::ExtensionPrefs* extension_prefs,
    194                    extensions::Blacklist* blacklist,
    195                    bool autoupdate_enabled,
    196                    bool extensions_enabled,
    197                    extensions::OneShotEvent* ready);
    198 
    199   virtual ~ExtensionService();
    200 
    201   // ExtensionServiceInterface implementation.
    202   //
    203   // NOTE: Many of these methods are DEPRECATED. See the interface for details.
    204   virtual const extensions::ExtensionSet* extensions() const OVERRIDE;
    205   virtual extensions::PendingExtensionManager*
    206       pending_extension_manager() OVERRIDE;
    207   virtual const extensions::Extension* GetExtensionById(
    208       const std::string& id, bool include_disabled) const OVERRIDE;
    209   virtual const extensions::Extension* GetInstalledExtension(
    210       const std::string& id) const OVERRIDE;
    211   virtual bool UpdateExtension(
    212       const std::string& id,
    213       const base::FilePath& extension_path,
    214       bool file_ownership_passed,
    215       extensions::CrxInstaller** out_crx_installer) OVERRIDE;
    216   virtual bool IsExtensionEnabled(
    217       const std::string& extension_id) const OVERRIDE;
    218   virtual void UnloadExtension(
    219       const std::string& extension_id,
    220       extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
    221   virtual void RemoveComponentExtension(const std::string& extension_id)
    222       OVERRIDE;
    223   virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
    224   virtual void AddComponentExtension(const extensions::Extension* extension)
    225       OVERRIDE;
    226   virtual const extensions::Extension* GetPendingExtensionUpdate(
    227       const std::string& extension_id) const OVERRIDE;
    228   virtual void FinishDelayedInstallation(
    229      const std::string& extension_id) OVERRIDE;
    230   virtual void CheckManagementPolicy() OVERRIDE;
    231   virtual void CheckForUpdatesSoon() OVERRIDE;
    232   virtual bool is_ready() OVERRIDE;
    233   virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
    234 
    235   // ExternalProvider::Visitor implementation.
    236   // Exposed for testing.
    237   virtual bool OnExternalExtensionFileFound(
    238       const std::string& id,
    239       const base::Version* version,
    240       const base::FilePath& path,
    241       extensions::Manifest::Location location,
    242       int creation_flags,
    243       bool mark_acknowledged) OVERRIDE;
    244   virtual bool OnExternalExtensionUpdateUrlFound(
    245       const std::string& id,
    246       const std::string& install_parameter,
    247       const GURL& update_url,
    248       extensions::Manifest::Location location,
    249       int creation_flags,
    250       bool mark_acknowledged) OVERRIDE;
    251   virtual void OnExternalProviderReady(
    252       const extensions::ExternalProviderInterface* provider) OVERRIDE;
    253 
    254   // ExtensionManagement::Observer implementation:
    255   virtual void OnExtensionManagementSettingsChanged() OVERRIDE;
    256 
    257   // Initialize and start all installed extensions.
    258   void Init();
    259 
    260   // Called when the associated Profile is going to be destroyed.
    261   void Shutdown();
    262 
    263   // Reloads the specified extension, sending the onLaunched() event to it if it
    264   // currently has any window showing.
    265   // Allows noisy failures.
    266   // NOTE: Reloading an extension can invalidate |extension_id| and Extension
    267   // pointers for the given extension. Consider making a copy of |extension_id|
    268   // first and retrieving a new Extension pointer afterwards.
    269   void ReloadExtension(const std::string& extension_id);
    270 
    271   // Suppresses noisy failures.
    272   void ReloadExtensionWithQuietFailure(const std::string& extension_id);
    273 
    274   // Uninstalls the specified extension. Callers should only call this method
    275   // with extensions that exist. |reason| lets the caller specify why the
    276   // extension is uninstalled.
    277   //
    278   // If the return value is true, |deletion_done_callback| is invoked when data
    279   // deletion is done or at least is scheduled.
    280   virtual bool UninstallExtension(const std::string& extension_id,
    281                                   extensions::UninstallReason reason,
    282                                   const base::Closure& deletion_done_callback,
    283                                   base::string16* error);
    284 
    285   // Enables the extension.  If the extension is already enabled, does
    286   // nothing.
    287   virtual void EnableExtension(const std::string& extension_id);
    288 
    289   // Disables the extension.  If the extension is already disabled, or
    290   // cannot be disabled, does nothing.
    291   virtual void DisableExtension(
    292       const std::string& extension_id,
    293       extensions::Extension::DisableReason disable_reason);
    294 
    295   // Disable non-default and non-managed extensions with ids not in
    296   // |except_ids|. Default extensions are those from the Web Store with
    297   // |was_installed_by_default| flag.
    298   void DisableUserExtensions(const std::vector<std::string>& except_ids);
    299 
    300   // Updates the |extension|'s granted permissions lists to include all
    301   // permissions in the |extension|'s manifest and re-enables the
    302   // extension.
    303   void GrantPermissionsAndEnableExtension(
    304       const extensions::Extension* extension);
    305 
    306   // Updates the |extension|'s granted permissions lists to include all
    307   // permissions in the |extensions|'s manifest.
    308   void GrantPermissions(const extensions::Extension* extension);
    309 
    310   // Check for updates (or potentially new extensions from external providers)
    311   void CheckForExternalUpdates();
    312 
    313   // Called when the initial extensions load has completed.
    314   virtual void OnLoadedInstalledExtensions();
    315 
    316   // Informs the service that an extension's files are in place for loading.
    317   //
    318   // |extension|     the extension
    319   // |page_ordinal|  the location of the extension in the app launcher
    320   // |install_flags| a bitmask of extensions::InstallFlags
    321   void OnExtensionInstalled(const extensions::Extension* extension,
    322                             const syncer::StringOrdinal& page_ordinal,
    323                             int install_flags);
    324   void OnExtensionInstalled(const extensions::Extension* extension,
    325                             const syncer::StringOrdinal& page_ordinal) {
    326     OnExtensionInstalled(extension,
    327                          page_ordinal,
    328                          static_cast<int>(extensions::kInstallFlagNone));
    329   }
    330 
    331   // Checks for delayed installation for all pending installs.
    332   void MaybeFinishDelayedInstallations();
    333 
    334   // Promotes an ephemeral app to a regular installed app. Ephemeral apps
    335   // are already installed in extension system (albiet transiently) and only
    336   // need to be exposed in the UI. Set |is_from_sync| to true if the
    337   // install was initiated via sync.
    338   void PromoteEphemeralApp(
    339       const extensions::Extension* extension, bool is_from_sync);
    340 
    341   // ExtensionHost of background page calls this method right after its render
    342   // view has been created.
    343   void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
    344 
    345   // Changes sequenced task runner for crx installation tasks to |task_runner|.
    346   void SetFileTaskRunnerForTesting(
    347       const scoped_refptr<base::SequencedTaskRunner>& task_runner);
    348 
    349   // Postpone installations so that we don't have to worry about race
    350   // conditions.
    351   void OnGarbageCollectIsolatedStorageStart();
    352 
    353   // Restart any extension installs which were delayed for isolated storage
    354   // garbage collection.
    355   void OnGarbageCollectIsolatedStorageFinished();
    356 
    357   // Record a histogram using the PermissionMessage enum values for each
    358   // permission in |e|.
    359   // NOTE: If this is ever called with high frequency, the implementation may
    360   // need to be made more efficient.
    361   static void RecordPermissionMessagesHistogram(
    362       const extensions::Extension* extension, const char* histogram);
    363 
    364   // Unloads the given extension and mark the extension as terminated. This
    365   // doesn't notify the user that the extension was terminated, if such a
    366   // notification is desired the calling code is responsible for doing that.
    367   void TerminateExtension(const std::string& extension_id);
    368 
    369   // Register self and content settings API with the specified map.
    370   void RegisterContentSettings(
    371       HostContentSettingsMap* host_content_settings_map);
    372 
    373   // Adds/Removes update observers.
    374   void AddUpdateObserver(extensions::UpdateObserver* observer);
    375   void RemoveUpdateObserver(extensions::UpdateObserver* observer);
    376 
    377   //////////////////////////////////////////////////////////////////////////////
    378   // Simple Accessors
    379 
    380   // Returns a WeakPtr to the ExtensionService.
    381   base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
    382 
    383   // Returns profile_ as a BrowserContext.
    384   content::BrowserContext* GetBrowserContext() const;
    385 
    386   bool extensions_enabled() const { return extensions_enabled_; }
    387   void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
    388 
    389   const base::FilePath& install_directory() const { return install_directory_; }
    390 
    391   const extensions::ExtensionSet* delayed_installs() const {
    392     return &delayed_installs_;
    393   }
    394 
    395   bool show_extensions_prompts() const { return show_extensions_prompts_; }
    396   void set_show_extensions_prompts(bool show_extensions_prompts) {
    397     show_extensions_prompts_ = show_extensions_prompts;
    398   }
    399 
    400   Profile* profile() { return profile_; }
    401 
    402   void set_extension_sync_service(
    403       ExtensionSyncService* extension_sync_service) {
    404     extension_sync_service_ = extension_sync_service;
    405   }
    406 
    407   // Note that this may return NULL if autoupdate is not turned on.
    408   extensions::ExtensionUpdater* updater() { return updater_.get(); }
    409 
    410   extensions::ComponentLoader* component_loader() {
    411     return component_loader_.get();
    412   }
    413 
    414   bool browser_terminating() const { return browser_terminating_; }
    415 
    416   extensions::SharedModuleService* shared_module_service() {
    417     return shared_module_service_.get();
    418   }
    419 
    420   extensions::ExternalInstallManager* external_install_manager() {
    421     return external_install_manager_.get();
    422   }
    423 
    424   //////////////////////////////////////////////////////////////////////////////
    425   // For Testing
    426 
    427   // Unload all extensions. Does not send notifications.
    428   void UnloadAllExtensionsForTest();
    429 
    430   // Reloads all extensions. Does not notify that extensions are ready.
    431   void ReloadExtensionsForTest();
    432 
    433   // Clear all ExternalProviders.
    434   void ClearProvidersForTesting();
    435 
    436   // Adds an ExternalProviderInterface for the service to use during testing.
    437   // Takes ownership of |test_provider|.
    438   void AddProviderForTesting(
    439       extensions::ExternalProviderInterface* test_provider);
    440 
    441   // Simulate an extension being blacklisted for tests.
    442   void BlacklistExtensionForTest(const std::string& extension_id);
    443 
    444 #if defined(UNIT_TEST)
    445   void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
    446     TrackTerminatedExtension(extension);
    447   }
    448 
    449   void FinishInstallationForTest(const extensions::Extension* extension) {
    450     FinishInstallation(extension, false /* not ephemeral */);
    451   }
    452 #endif
    453 
    454   void set_browser_terminating_for_test(bool value) {
    455     browser_terminating_ = value;
    456   }
    457 
    458   // By default ExtensionService will wait with installing an updated extension
    459   // until the extension is idle. Tests might not like this behavior, so you can
    460   // disable it with this method.
    461   void set_install_updates_when_idle_for_test(bool value) {
    462     install_updates_when_idle_ = value;
    463   }
    464 
    465   // Set a callback to be called when all external providers are ready and their
    466   // extensions have been installed.
    467   void set_external_updates_finished_callback_for_test(
    468       const base::Closure& callback) {
    469     external_updates_finished_callback_ = callback;
    470   }
    471 
    472 
    473  private:
    474   // Creates an ExtensionDownloader for use by the updater.
    475   scoped_ptr<extensions::ExtensionDownloader> CreateExtensionDownloader(
    476       extensions::ExtensionDownloaderDelegate* delegate);
    477 
    478   // Reloads the specified extension, sending the onLaunched() event to it if it
    479   // currently has any window showing. |be_noisy| determines whether noisy
    480   // failures are allowed for unpacked extension installs.
    481   void ReloadExtensionImpl(const std::string& extension_id, bool be_noisy);
    482 
    483   // content::NotificationObserver implementation:
    484   virtual void Observe(int type,
    485                        const content::NotificationSource& source,
    486                        const content::NotificationDetails& details) OVERRIDE;
    487 
    488   // extensions::Blacklist::Observer implementation.
    489   virtual void OnBlacklistUpdated() OVERRIDE;
    490 
    491   // Similar to FinishInstallation, but first checks if there still is an update
    492   // pending for the extension, and makes sure the extension is still idle.
    493   void MaybeFinishDelayedInstallation(const std::string& extension_id);
    494 
    495   // For the extension in |version_path| with |id|, check to see if it's an
    496   // externally managed extension.  If so, uninstall it.
    497   void CheckExternalUninstall(const std::string& id);
    498 
    499   // Populates greylist_.
    500   void LoadGreylistFromPrefs();
    501 
    502   // Signals *ready_ and sends a notification to the listeners.
    503   void SetReadyAndNotifyListeners();
    504 
    505   // Returns true if all the external extension providers are ready.
    506   bool AreAllExternalProvidersReady() const;
    507 
    508   // Called once all external providers are ready. Checks for unclaimed
    509   // external extensions.
    510   void OnAllExternalProvidersReady();
    511 
    512   // Adds the given extension to the list of terminated extensions if
    513   // it is not already there and unloads it.
    514   void TrackTerminatedExtension(const extensions::Extension* extension);
    515 
    516   // Removes the extension with the given id from the list of
    517   // terminated extensions if it is there.
    518   void UntrackTerminatedExtension(const std::string& id);
    519 
    520   // Update preferences for a new or updated extension; notify observers that
    521   // the extension is installed, e.g., to update event handlers on background
    522   // pages; and perform other extension install tasks before calling
    523   // AddExtension.
    524   // |install_flags| is a bitmask of extensions::InstallFlags.
    525   void AddNewOrUpdatedExtension(const extensions::Extension* extension,
    526                                 extensions::Extension::State initial_state,
    527                                 int install_flags,
    528                                 const syncer::StringOrdinal& page_ordinal,
    529                                 const std::string& install_parameter);
    530 
    531   // Handles sending notification that |extension| was loaded.
    532   void NotifyExtensionLoaded(const extensions::Extension* extension);
    533 
    534   // Handles sending notification that |extension| was unloaded.
    535   void NotifyExtensionUnloaded(
    536       const extensions::Extension* extension,
    537       extensions::UnloadedExtensionInfo::Reason reason);
    538 
    539   // Common helper to finish installing the given extension. |was_ephemeral|
    540   // should be true if the extension was previously installed and ephemeral.
    541   void FinishInstallation(const extensions::Extension* extension,
    542                           bool was_ephemeral);
    543 
    544   // Disables the extension if the privilege level has increased
    545   // (e.g., due to an upgrade).
    546   void CheckPermissionsIncrease(const extensions::Extension* extension,
    547                                 bool is_extension_installed);
    548 
    549   // Helper that updates the active extension list used for crash reporting.
    550   void UpdateActiveExtensionsInCrashReporter();
    551 
    552   // Helper to determine whether we should initially enable an installed
    553   // (or upgraded) extension.
    554   bool ShouldEnableOnInstall(const extensions::Extension* extension);
    555 
    556   // Helper to determine if updating an extensions should proceed immediately,
    557   // or if we should delay the update until further notice.
    558   bool ShouldDelayExtensionUpdate(const std::string& extension_id,
    559                                   bool install_immediately) const;
    560 
    561   // Manages the blacklisted extensions, intended as callback from
    562   // Blacklist::GetBlacklistedIDs.
    563   void ManageBlacklist(
    564       const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
    565 
    566   // Add extensions in |blocked| to blacklisted_extensions, remove extensions
    567   // that are neither in |blocked|, nor in |unchanged|.
    568   void UpdateBlockedExtensions(const extensions::ExtensionIdSet& blocked,
    569                                const extensions::ExtensionIdSet& unchanged);
    570 
    571   void UpdateGreylistedExtensions(
    572       const extensions::ExtensionIdSet& greylist,
    573       const extensions::ExtensionIdSet& unchanged,
    574       const extensions::Blacklist::BlacklistStateMap& state_map);
    575 
    576   // Used only by test code.
    577   void UnloadAllExtensionsInternal();
    578 
    579   // Disable apps & extensions now to stop them from running after a profile
    580   // has been conceptually deleted. Don't wait for full browser shutdown and
    581   // the actual profile objects to be destroyed.
    582   void OnProfileDestructionStarted();
    583 
    584   // Called on file task runner thread to uninstall extension.
    585   static void UninstallExtensionOnFileThread(
    586       const std::string& id,
    587       Profile* profile,
    588       const base::FilePath& install_dir,
    589       const base::FilePath& extension_path);
    590 
    591   // The normal profile associated with this ExtensionService.
    592   Profile* profile_;
    593 
    594   // The ExtensionSystem for the profile above.
    595   extensions::ExtensionSystem* system_;
    596 
    597   // Preferences for the owning profile.
    598   extensions::ExtensionPrefs* extension_prefs_;
    599 
    600   // Blacklist for the owning profile.
    601   extensions::Blacklist* blacklist_;
    602 
    603   // The ExtensionSyncService that is used by this ExtensionService.
    604   ExtensionSyncService* extension_sync_service_;
    605 
    606   // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
    607   extensions::ExtensionRegistry* registry_;
    608 
    609   // Set of greylisted extensions. These extensions are disabled if they are
    610   // already installed in Chromium at the time when they are added to
    611   // the greylist. Unlike blacklisted extensions, greylisted ones are visible
    612   // to the user and if user re-enables such an extension, they remain enabled.
    613   //
    614   // These extensions should appear in registry_.
    615   extensions::ExtensionSet greylist_;
    616 
    617   // The list of extension installs delayed for various reasons.  The reason
    618   // for delayed install is stored in ExtensionPrefs. These are not part of
    619   // ExtensionRegistry because they are not yet installed.
    620   extensions::ExtensionSet delayed_installs_;
    621 
    622   // Hold the set of pending extensions.
    623   extensions::PendingExtensionManager pending_extension_manager_;
    624 
    625   // The full path to the directory where extensions are installed.
    626   base::FilePath install_directory_;
    627 
    628   // Whether or not extensions are enabled.
    629   bool extensions_enabled_;
    630 
    631   // Whether to notify users when they attempt to install an extension.
    632   bool show_extensions_prompts_;
    633 
    634   // Whether to delay installing of extension updates until the extension is
    635   // idle.
    636   bool install_updates_when_idle_;
    637 
    638   // Signaled when all extensions are loaded.
    639   extensions::OneShotEvent* const ready_;
    640 
    641   // Our extension updater, if updates are turned on.
    642   scoped_ptr<extensions::ExtensionUpdater> updater_;
    643 
    644   // Map unloaded extensions' ids to their paths. When a temporarily loaded
    645   // extension is unloaded, we lose the information about it and don't have
    646   // any in the extension preferences file.
    647   typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
    648   UnloadedExtensionPathMap unloaded_extension_paths_;
    649 
    650   // Map of DevToolsAgentHost instances that are detached,
    651   // waiting for an extension to be reloaded.
    652   typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
    653       OrphanedDevTools;
    654   OrphanedDevTools orphaned_dev_tools_;
    655 
    656   content::NotificationRegistrar registrar_;
    657 
    658   // Keeps track of loading and unloading component extensions.
    659   scoped_ptr<extensions::ComponentLoader> component_loader_;
    660 
    661   // A collection of external extension providers.  Each provider reads
    662   // a source of external extension information.  Examples include the
    663   // windows registry and external_extensions.json.
    664   extensions::ProviderCollection external_extension_providers_;
    665 
    666   // Set to true by OnExternalExtensionUpdateUrlFound() when an external
    667   // extension URL is found, and by CheckForUpdatesSoon() when an update check
    668   // has to wait for the external providers.  Used in
    669   // OnAllExternalProvidersReady() to determine if an update check is needed to
    670   // install pending extensions.
    671   bool update_once_all_providers_are_ready_;
    672 
    673   // A callback to be called when all external providers are ready and their
    674   // extensions have been installed. Normally this is a null callback, but
    675   // is used in external provider related tests.
    676   base::Closure external_updates_finished_callback_;
    677 
    678   // Set when the browser is terminating. Prevents us from installing or
    679   // updating additional extensions and allows in-progress installations to
    680   // decide to abort.
    681   bool browser_terminating_;
    682 
    683   // Set to true to delay all new extension installations. Acts as a lock to
    684   // allow background processing of garbage collection of on-disk state without
    685   // needing to worry about race conditions caused by extension installation and
    686   // reinstallation.
    687   bool installs_delayed_for_gc_;
    688 
    689   // Set to true if this is the first time this ExtensionService has run.
    690   // Used for specially handling external extensions that are installed the
    691   // first time.
    692   bool is_first_run_;
    693 
    694   // Store the ids of reloading extensions. We use this to re-enable extensions
    695   // which were disabled for a reload.
    696   std::set<std::string> reloading_extensions_;
    697 
    698   // A set of the extension ids currently being terminated. We use this to
    699   // avoid trying to unload the same extension twice.
    700   std::set<std::string> extensions_being_terminated_;
    701 
    702   // The controller for the UI that alerts the user about any blacklisted
    703   // extensions.
    704   scoped_ptr<extensions::ExtensionErrorController> error_controller_;
    705 
    706   // The manager for extensions that were externally installed that is
    707   // responsible for prompting the user about suspicious extensions.
    708   scoped_ptr<extensions::ExternalInstallManager> external_install_manager_;
    709 
    710   // Sequenced task runner for extension related file operations.
    711   scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
    712 
    713   scoped_ptr<extensions::ExtensionActionStorageManager>
    714       extension_action_storage_manager_;
    715   scoped_ptr<extensions::ManagementPolicy::Provider>
    716       shared_module_policy_provider_;
    717 
    718   // The SharedModuleService used to check for import dependencies.
    719   scoped_ptr<extensions::SharedModuleService> shared_module_service_;
    720 
    721   ObserverList<extensions::UpdateObserver, true> update_observers_;
    722 
    723   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    724                            DestroyingProfileClearsExtensions);
    725   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
    726   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    727                            BlacklistedExtensionWillNotInstall);
    728   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    729                            UnloadBlacklistedExtensionPolicy);
    730   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    731                            WillNotLoadBlacklistedExtensionsFromDirectory);
    732   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension);
    733   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup);
    734   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    735                            GreylistedExtensionDisabled);
    736   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    737                            GreylistDontEnableManuallyDisabled);
    738   FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
    739                            GreylistUnknownDontChange);
    740 
    741   DISALLOW_COPY_AND_ASSIGN(ExtensionService);
    742 };
    743 
    744 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
    745