Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_service.h
blob04d0f4ed8b40b12a2a453cfebc1f5a26fafbb82f
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
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/crx_file_info.h"
25 #include "extensions/browser/external_provider_interface.h"
26 #include "extensions/browser/install_flag.h"
27 #include "extensions/browser/management_policy.h"
28 #include "extensions/browser/process_manager.h"
29 #include "extensions/browser/uninstall_reason.h"
30 #include "extensions/common/extension.h"
31 #include "extensions/common/extension_set.h"
32 #include "extensions/common/manifest.h"
33 #include "sync/api/string_ordinal.h"
35 #if !defined(ENABLE_EXTENSIONS)
36 #error "Extensions must be enabled"
37 #endif
39 class ExtensionSyncService;
40 class GURL;
41 class HostContentSettingsMap;
42 class Profile;
44 namespace base {
45 class CommandLine;
46 class SequencedTaskRunner;
47 class Version;
50 namespace content {
51 class DevToolsAgentHost;
54 namespace extensions {
55 class AppDataMigrator;
56 class ComponentLoader;
57 class CrxInstaller;
58 class ExtensionActionStorageManager;
59 class ExtensionDownloader;
60 class ExtensionDownloaderDelegate;
61 class ExtensionErrorController;
62 class ExtensionRegistry;
63 class ExtensionSystem;
64 class ExtensionUpdater;
65 class OneShotEvent;
66 class ExternalInstallManager;
67 class SharedModuleService;
68 class UpdateObserver;
69 } // namespace extensions
71 // This is an interface class to encapsulate the dependencies that
72 // various classes have on ExtensionService. This allows easy mocking.
73 class ExtensionServiceInterface
74 : public base::SupportsWeakPtr<ExtensionServiceInterface> {
75 public:
76 virtual ~ExtensionServiceInterface() {}
78 // Gets the object managing the set of pending extensions.
79 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
81 // Installs an update with the contents from |extension_path|. Returns true if
82 // the install can be started. Sets |out_crx_installer| to the installer if
83 // one was started.
84 // TODO(aa): This method can be removed. ExtensionUpdater could use
85 // CrxInstaller directly instead.
86 virtual bool UpdateExtension(
87 const extensions::CRXFileInfo& file,
88 bool file_ownership_passed,
89 extensions::CrxInstaller** out_crx_installer) = 0;
91 // DEPRECATED. Use ExtensionRegistry instead.
93 // Looks up an extension by its ID.
95 // If |include_disabled| is false then this will only include enabled
96 // extensions. Use instead:
98 // ExtensionRegistry::enabled_extensions().GetByID(id).
100 // If |include_disabled| is true then this will also include disabled and
101 // blacklisted extensions (not terminated extensions). Use instead:
103 // ExtensionRegistry::GetExtensionById(
104 // id, ExtensionRegistry::ENABLED |
105 // ExtensionRegistry::DISABLED |
106 // ExtensionRegistry::BLACKLISTED)
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;
113 // DEPRECATED: Use ExtensionRegistry instead.
115 // Looks up an extension by ID, regardless of whether it's enabled,
116 // disabled, blacklisted, or terminated. Use instead:
118 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING).
119 virtual const extensions::Extension* GetInstalledExtension(
120 const std::string& id) const = 0;
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;
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;
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;
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;
142 // Safe to call multiple times in a row.
144 // TODO(akalin): Remove this method (and others) once we refactor
145 // themes sync to not use it directly.
146 virtual void CheckForUpdatesSoon() = 0;
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;
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;
158 // Unload the specified extension.
159 virtual void UnloadExtension(
160 const std::string& extension_id,
161 extensions::UnloadedExtensionInfo::Reason reason) = 0;
163 // Remove the specified component extension.
164 virtual void RemoveComponentExtension(const std::string& extension_id) = 0;
166 // Whether the extension service is ready.
167 virtual bool is_ready() = 0;
169 // Returns task runner for crx installation file I/O operations.
170 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
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);
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);
199 ~ExtensionService() override;
201 // ExtensionServiceInterface implementation.
203 // NOTE: Many of these methods are DEPRECATED. See the interface for details.
204 extensions::PendingExtensionManager* pending_extension_manager() override;
205 const extensions::Extension* GetExtensionById(
206 const std::string& id,
207 bool include_disabled) const override;
208 const extensions::Extension* GetInstalledExtension(
209 const std::string& id) const override;
210 bool UpdateExtension(const extensions::CRXFileInfo& file,
211 bool file_ownership_passed,
212 extensions::CrxInstaller** out_crx_installer) override;
213 bool IsExtensionEnabled(const std::string& extension_id) const override;
214 void UnloadExtension(
215 const std::string& extension_id,
216 extensions::UnloadedExtensionInfo::Reason reason) override;
217 void RemoveComponentExtension(const std::string& extension_id) override;
218 void AddExtension(const extensions::Extension* extension) override;
219 void AddComponentExtension(const extensions::Extension* extension) override;
220 const extensions::Extension* GetPendingExtensionUpdate(
221 const std::string& extension_id) const override;
222 void FinishDelayedInstallation(const std::string& extension_id) override;
223 void CheckManagementPolicy() override;
224 void CheckForUpdatesSoon() override;
225 bool is_ready() override;
226 base::SequencedTaskRunner* GetFileTaskRunner() override;
228 // ExternalProvider::Visitor implementation.
229 // Exposed for testing.
230 bool OnExternalExtensionFileFound(const std::string& id,
231 const base::Version* version,
232 const base::FilePath& path,
233 extensions::Manifest::Location location,
234 int creation_flags,
235 bool mark_acknowledged,
236 bool install_immediately) override;
237 bool OnExternalExtensionUpdateUrlFound(
238 const std::string& id,
239 const std::string& install_parameter,
240 const GURL& update_url,
241 extensions::Manifest::Location location,
242 int creation_flags,
243 bool mark_acknowledged) override;
244 void OnExternalProviderReady(
245 const extensions::ExternalProviderInterface* provider) override;
247 // ExtensionManagement::Observer implementation:
248 void OnExtensionManagementSettingsChanged() override;
250 // Initialize and start all installed extensions.
251 void Init();
253 // Called when the associated Profile is going to be destroyed.
254 void Shutdown();
256 // Reloads the specified extension, sending the onLaunched() event to it if it
257 // currently has any window showing.
258 // Allows noisy failures.
259 // NOTE: Reloading an extension can invalidate |extension_id| and Extension
260 // pointers for the given extension. Consider making a copy of |extension_id|
261 // first and retrieving a new Extension pointer afterwards.
262 void ReloadExtension(const std::string& extension_id);
264 // Suppresses noisy failures.
265 void ReloadExtensionWithQuietFailure(const std::string& extension_id);
267 // Uninstalls the specified extension. Callers should only call this method
268 // with extensions that exist. |reason| lets the caller specify why the
269 // extension is uninstalled.
271 // If the return value is true, |deletion_done_callback| is invoked when data
272 // deletion is done or at least is scheduled.
273 virtual bool UninstallExtension(const std::string& extension_id,
274 extensions::UninstallReason reason,
275 const base::Closure& deletion_done_callback,
276 base::string16* error);
278 // Enables the extension. If the extension is already enabled, does
279 // nothing.
280 virtual void EnableExtension(const std::string& extension_id);
282 // Disables the extension. If the extension is already disabled, or
283 // cannot be disabled, does nothing.
284 virtual void DisableExtension(
285 const std::string& extension_id,
286 extensions::Extension::DisableReason disable_reason);
288 // Disable non-default and non-managed extensions with ids not in
289 // |except_ids|. Default extensions are those from the Web Store with
290 // |was_installed_by_default| flag.
291 void DisableUserExtensions(const std::vector<std::string>& except_ids);
293 // Puts all extensions in a blocked state: Unloading every extension, and
294 // preventing them from ever loading until UnblockAllExtensions is called.
295 // This state is stored in preferences, so persists until Chrome restarts.
297 // Component, external component and whitelisted policy installed extensions
298 // are exempt from being Blocked (see CanBlockExtension).
299 void BlockAllExtensions();
301 // All blocked extensions are reverted to their previous state, and are
302 // reloaded. Newly added extensions are no longer automatically blocked.
303 void UnblockAllExtensions();
305 // Updates the |extension|'s granted permissions lists to include all
306 // permissions in the |extension|'s manifest and re-enables the
307 // extension.
308 void GrantPermissionsAndEnableExtension(
309 const extensions::Extension* extension);
311 // Updates the |extension|'s granted permissions lists to include all
312 // permissions in the |extensions|'s manifest.
313 void GrantPermissions(const extensions::Extension* extension);
315 // Check for updates (or potentially new extensions from external providers)
316 void CheckForExternalUpdates();
318 // Called when the initial extensions load has completed.
319 virtual void OnLoadedInstalledExtensions();
321 // Informs the service that an extension's files are in place for loading.
323 // |extension| the extension
324 // |page_ordinal| the location of the extension in the app launcher
325 // |install_flags| a bitmask of extensions::InstallFlags
326 void OnExtensionInstalled(const extensions::Extension* extension,
327 const syncer::StringOrdinal& page_ordinal,
328 int install_flags);
329 void OnExtensionInstalled(const extensions::Extension* extension,
330 const syncer::StringOrdinal& page_ordinal) {
331 OnExtensionInstalled(extension,
332 page_ordinal,
333 static_cast<int>(extensions::kInstallFlagNone));
336 // Checks for delayed installation for all pending installs.
337 void MaybeFinishDelayedInstallations();
339 // Promotes an ephemeral app to a regular installed app. Ephemeral apps
340 // are already installed in extension system (albiet transiently) and only
341 // need to be exposed in the UI. Set |is_from_sync| to true if the
342 // install was initiated via sync.
343 void PromoteEphemeralApp(
344 const extensions::Extension* extension, bool is_from_sync);
346 // ExtensionHost of background page calls this method right after its render
347 // view has been created.
348 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
350 // Changes sequenced task runner for crx installation tasks to |task_runner|.
351 void SetFileTaskRunnerForTesting(
352 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
354 // Postpone installations so that we don't have to worry about race
355 // conditions.
356 void OnGarbageCollectIsolatedStorageStart();
358 // Restart any extension installs which were delayed for isolated storage
359 // garbage collection.
360 void OnGarbageCollectIsolatedStorageFinished();
362 // Record a histogram using the PermissionMessage enum values for each
363 // permission in |e|.
364 // NOTE: If this is ever called with high frequency, the implementation may
365 // need to be made more efficient.
366 static void RecordPermissionMessagesHistogram(
367 const extensions::Extension* extension, const char* histogram);
369 // Unloads the given extension and mark the extension as terminated. This
370 // doesn't notify the user that the extension was terminated, if such a
371 // notification is desired the calling code is responsible for doing that.
372 void TerminateExtension(const std::string& extension_id);
374 // Register self and content settings API with the specified map.
375 void RegisterContentSettings(
376 HostContentSettingsMap* host_content_settings_map);
378 // Adds/Removes update observers.
379 void AddUpdateObserver(extensions::UpdateObserver* observer);
380 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
382 //////////////////////////////////////////////////////////////////////////////
383 // Simple Accessors
385 // Returns a WeakPtr to the ExtensionService.
386 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
388 // Returns profile_ as a BrowserContext.
389 content::BrowserContext* GetBrowserContext() const;
391 bool extensions_enabled() const { return extensions_enabled_; }
392 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
394 const base::FilePath& install_directory() const { return install_directory_; }
396 const extensions::ExtensionSet* delayed_installs() const {
397 return &delayed_installs_;
400 bool show_extensions_prompts() const { return show_extensions_prompts_; }
401 void set_show_extensions_prompts(bool show_extensions_prompts) {
402 show_extensions_prompts_ = show_extensions_prompts;
405 Profile* profile() { return profile_; }
407 void set_extension_sync_service(
408 ExtensionSyncService* extension_sync_service) {
409 extension_sync_service_ = extension_sync_service;
412 // Note that this may return NULL if autoupdate is not turned on.
413 extensions::ExtensionUpdater* updater() { return updater_.get(); }
415 extensions::ComponentLoader* component_loader() {
416 return component_loader_.get();
419 bool browser_terminating() const { return browser_terminating_; }
421 extensions::SharedModuleService* shared_module_service() {
422 return shared_module_service_.get();
425 extensions::ExternalInstallManager* external_install_manager() {
426 return external_install_manager_.get();
429 //////////////////////////////////////////////////////////////////////////////
430 // For Testing
432 // Unload all extensions. Does not send notifications.
433 void UnloadAllExtensionsForTest();
435 // Reloads all extensions. Does not notify that extensions are ready.
436 void ReloadExtensionsForTest();
438 // Clear all ExternalProviders.
439 void ClearProvidersForTesting();
441 // Adds an ExternalProviderInterface for the service to use during testing.
442 // Takes ownership of |test_provider|.
443 void AddProviderForTesting(
444 extensions::ExternalProviderInterface* test_provider);
446 // Simulate an extension being blacklisted for tests.
447 void BlacklistExtensionForTest(const std::string& extension_id);
449 #if defined(UNIT_TEST)
450 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
451 TrackTerminatedExtension(extension);
454 void FinishInstallationForTest(const extensions::Extension* extension) {
455 FinishInstallation(extension, false /* not ephemeral */);
457 #endif
459 void set_browser_terminating_for_test(bool value) {
460 browser_terminating_ = value;
463 // By default ExtensionService will wait with installing an updated extension
464 // until the extension is idle. Tests might not like this behavior, so you can
465 // disable it with this method.
466 void set_install_updates_when_idle_for_test(bool value) {
467 install_updates_when_idle_ = value;
470 // Set a callback to be called when all external providers are ready and their
471 // extensions have been installed.
472 void set_external_updates_finished_callback_for_test(
473 const base::Closure& callback) {
474 external_updates_finished_callback_ = callback;
478 private:
479 // Creates an ExtensionDownloader for use by the updater.
480 scoped_ptr<extensions::ExtensionDownloader> CreateExtensionDownloader(
481 extensions::ExtensionDownloaderDelegate* delegate);
483 // Reloads the specified extension, sending the onLaunched() event to it if it
484 // currently has any window showing. |be_noisy| determines whether noisy
485 // failures are allowed for unpacked extension installs.
486 void ReloadExtensionImpl(const std::string& extension_id, bool be_noisy);
488 // content::NotificationObserver implementation:
489 void Observe(int type,
490 const content::NotificationSource& source,
491 const content::NotificationDetails& details) override;
493 // extensions::Blacklist::Observer implementation.
494 void OnBlacklistUpdated() override;
496 // Similar to FinishInstallation, but first checks if there still is an update
497 // pending for the extension, and makes sure the extension is still idle.
498 void MaybeFinishDelayedInstallation(const std::string& extension_id);
500 // For the extension in |version_path| with |id|, check to see if it's an
501 // externally managed extension. If so, uninstall it.
502 void CheckExternalUninstall(const std::string& id);
504 // Attempt to enable all disabled extensions which the only disabled reason is
505 // reloading.
506 void EnabledReloadableExtensions();
508 // Finish install (if possible) of extensions that were still delayed while
509 // the browser was shut down.
510 void MaybeFinishShutdownDelayed();
512 // Populates greylist_.
513 void LoadGreylistFromPrefs();
515 // Signals *ready_ and sends a notification to the listeners.
516 void SetReadyAndNotifyListeners();
518 // Returns true if all the external extension providers are ready.
519 bool AreAllExternalProvidersReady() const;
521 // Called once all external providers are ready. Checks for unclaimed
522 // external extensions.
523 void OnAllExternalProvidersReady();
525 // Adds the given extension to the list of terminated extensions if
526 // it is not already there and unloads it.
527 void TrackTerminatedExtension(const extensions::Extension* extension);
529 // Removes the extension with the given id from the list of
530 // terminated extensions if it is there.
531 void UntrackTerminatedExtension(const std::string& id);
533 // Update preferences for a new or updated extension; notify observers that
534 // the extension is installed, e.g., to update event handlers on background
535 // pages; and perform other extension install tasks before calling
536 // AddExtension.
537 // |install_flags| is a bitmask of extensions::InstallFlags.
538 void AddNewOrUpdatedExtension(const extensions::Extension* extension,
539 extensions::Extension::State initial_state,
540 int install_flags,
541 const syncer::StringOrdinal& page_ordinal,
542 const std::string& install_parameter);
544 // Handles sending notification that |extension| was loaded.
545 void NotifyExtensionLoaded(const extensions::Extension* extension);
547 // Handles sending notification that |extension| was unloaded.
548 void NotifyExtensionUnloaded(
549 const extensions::Extension* extension,
550 extensions::UnloadedExtensionInfo::Reason reason);
552 // Common helper to finish installing the given extension. |was_ephemeral|
553 // should be true if the extension was previously installed and ephemeral.
554 void FinishInstallation(const extensions::Extension* extension,
555 bool was_ephemeral);
557 // Disables the extension if the privilege level has increased
558 // (e.g., due to an upgrade).
559 void CheckPermissionsIncrease(const extensions::Extension* extension,
560 bool is_extension_installed);
562 // Helper that updates the active extension list used for crash reporting.
563 void UpdateActiveExtensionsInCrashReporter();
565 // Helper to get the disable reasons for an installed (or upgraded) extension.
566 // A return value of Extension::DISABLE_NONE indicates that we should enable
567 // this extension initially.
568 int GetDisableReasonsOnInstalled(const extensions::Extension* extension);
570 // Helper method to determine if an extension can be blocked.
571 bool CanBlockExtension(const extensions::Extension* extension) const;
573 // Helper to determine if updating an extensions should proceed immediately,
574 // or if we should delay the update until further notice.
575 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
576 bool install_immediately) const;
578 // Manages the blacklisted extensions, intended as callback from
579 // Blacklist::GetBlacklistedIDs.
580 void ManageBlacklist(
581 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
583 // Add extensions in |blacklisted| to blacklisted_extensions, remove
584 // extensions that are neither in |blacklisted|, nor in |unchanged|.
585 void UpdateBlacklistedExtensions(
586 const extensions::ExtensionIdSet& to_blacklist,
587 const extensions::ExtensionIdSet& unchanged);
589 void UpdateGreylistedExtensions(
590 const extensions::ExtensionIdSet& greylist,
591 const extensions::ExtensionIdSet& unchanged,
592 const extensions::Blacklist::BlacklistStateMap& state_map);
594 // Used only by test code.
595 void UnloadAllExtensionsInternal();
597 // Disable apps & extensions now to stop them from running after a profile
598 // has been conceptually deleted. Don't wait for full browser shutdown and
599 // the actual profile objects to be destroyed.
600 void OnProfileDestructionStarted();
602 // Called on file task runner thread to uninstall extension.
603 static void UninstallExtensionOnFileThread(
604 const std::string& id,
605 Profile* profile,
606 const base::FilePath& install_dir,
607 const base::FilePath& extension_path);
609 // The normal profile associated with this ExtensionService.
610 Profile* profile_;
612 // The ExtensionSystem for the profile above.
613 extensions::ExtensionSystem* system_;
615 // Preferences for the owning profile.
616 extensions::ExtensionPrefs* extension_prefs_;
618 // Blacklist for the owning profile.
619 extensions::Blacklist* blacklist_;
621 // The ExtensionSyncService that is used by this ExtensionService.
622 ExtensionSyncService* extension_sync_service_;
624 // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
625 extensions::ExtensionRegistry* registry_;
627 // Set of greylisted extensions. These extensions are disabled if they are
628 // already installed in Chromium at the time when they are added to
629 // the greylist. Unlike blacklisted extensions, greylisted ones are visible
630 // to the user and if user re-enables such an extension, they remain enabled.
632 // These extensions should appear in registry_.
633 extensions::ExtensionSet greylist_;
635 // The list of extension installs delayed for various reasons. The reason
636 // for delayed install is stored in ExtensionPrefs. These are not part of
637 // ExtensionRegistry because they are not yet installed.
638 extensions::ExtensionSet delayed_installs_;
640 // Hold the set of pending extensions.
641 extensions::PendingExtensionManager pending_extension_manager_;
643 // The full path to the directory where extensions are installed.
644 base::FilePath install_directory_;
646 // Whether or not extensions are enabled.
647 bool extensions_enabled_;
649 // Whether to notify users when they attempt to install an extension.
650 bool show_extensions_prompts_;
652 // Whether to delay installing of extension updates until the extension is
653 // idle.
654 bool install_updates_when_idle_;
656 // Signaled when all extensions are loaded.
657 extensions::OneShotEvent* const ready_;
659 // Our extension updater, if updates are turned on.
660 scoped_ptr<extensions::ExtensionUpdater> updater_;
662 // Map unloaded extensions' ids to their paths. When a temporarily loaded
663 // extension is unloaded, we lose the information about it and don't have
664 // any in the extension preferences file.
665 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
666 UnloadedExtensionPathMap unloaded_extension_paths_;
668 // Map of DevToolsAgentHost instances that are detached,
669 // waiting for an extension to be reloaded.
670 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
671 OrphanedDevTools;
672 OrphanedDevTools orphaned_dev_tools_;
674 content::NotificationRegistrar registrar_;
676 // Keeps track of loading and unloading component extensions.
677 scoped_ptr<extensions::ComponentLoader> component_loader_;
679 // A collection of external extension providers. Each provider reads
680 // a source of external extension information. Examples include the
681 // windows registry and external_extensions.json.
682 extensions::ProviderCollection external_extension_providers_;
684 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
685 // extension URL is found, and by CheckForUpdatesSoon() when an update check
686 // has to wait for the external providers. Used in
687 // OnAllExternalProvidersReady() to determine if an update check is needed to
688 // install pending extensions.
689 bool update_once_all_providers_are_ready_;
691 // A callback to be called when all external providers are ready and their
692 // extensions have been installed. Normally this is a null callback, but
693 // is used in external provider related tests.
694 base::Closure external_updates_finished_callback_;
696 // Set when the browser is terminating. Prevents us from installing or
697 // updating additional extensions and allows in-progress installations to
698 // decide to abort.
699 bool browser_terminating_;
701 // Set to true to delay all new extension installations. Acts as a lock to
702 // allow background processing of garbage collection of on-disk state without
703 // needing to worry about race conditions caused by extension installation and
704 // reinstallation.
705 bool installs_delayed_for_gc_;
707 // Set to true if this is the first time this ExtensionService has run.
708 // Used for specially handling external extensions that are installed the
709 // first time.
710 bool is_first_run_;
712 // Set to true if extensions are all to be blocked.
713 bool block_extensions_;
715 // Store the ids of reloading extensions. We use this to re-enable extensions
716 // which were disabled for a reload.
717 std::set<std::string> reloading_extensions_;
719 // A set of the extension ids currently being terminated. We use this to
720 // avoid trying to unload the same extension twice.
721 std::set<std::string> extensions_being_terminated_;
723 // The controller for the UI that alerts the user about any blacklisted
724 // extensions.
725 scoped_ptr<extensions::ExtensionErrorController> error_controller_;
727 // The manager for extensions that were externally installed that is
728 // responsible for prompting the user about suspicious extensions.
729 scoped_ptr<extensions::ExternalInstallManager> external_install_manager_;
731 // Sequenced task runner for extension related file operations.
732 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
734 scoped_ptr<extensions::ExtensionActionStorageManager>
735 extension_action_storage_manager_;
736 scoped_ptr<extensions::ManagementPolicy::Provider>
737 shared_module_policy_provider_;
739 // The SharedModuleService used to check for import dependencies.
740 scoped_ptr<extensions::SharedModuleService> shared_module_service_;
742 ObserverList<extensions::UpdateObserver, true> update_observers_;
744 // Migrates app data when upgrading a legacy packaged app to a platform app
745 scoped_ptr<extensions::AppDataMigrator> app_data_migrator_;
747 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
748 DestroyingProfileClearsExtensions);
749 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
750 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
751 BlacklistedExtensionWillNotInstall);
752 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
753 UnloadBlacklistedExtensionPolicy);
754 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
755 WillNotLoadBlacklistedExtensionsFromDirectory);
756 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension);
757 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup);
758 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
759 GreylistedExtensionDisabled);
760 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
761 GreylistDontEnableManuallyDisabled);
762 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
763 GreylistUnknownDontChange);
764 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
765 ManagementPolicyProhibitsEnableOnInstalled);
766 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
767 BlockAndUnblockBlacklistedExtension);
769 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
772 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_