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_prefs.h"
24 #include "chrome/browser/extensions/extension_sync_service.h"
25 #include "chrome/common/extensions/extension_constants.h"
26 #include "content/public/browser/devtools_agent_host.h"
27 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h"
29 #include "extensions/browser/external_provider_interface.h"
30 #include "extensions/browser/management_policy.h"
31 #include "extensions/browser/pending_extension_manager.h"
32 #include "extensions/browser/process_manager.h"
33 #include "extensions/browser/quota_service.h"
34 #include "extensions/common/extension.h"
35 #include "extensions/common/extension_set.h"
36 #include "extensions/common/manifest.h"
37 #include "extensions/common/manifest_handlers/shared_module_info.h"
38 #include "extensions/common/one_shot_event.h"
41 class ExtensionErrorUI
;
42 class ExtensionToolbarModel
;
47 class SequencedTaskRunner
;
51 namespace extensions
{
52 class BrowserEventRouter
;
53 class ComponentLoader
;
54 class ContentSettingsStore
;
56 class ExtensionActionStorageManager
;
57 class ExtensionRegistry
;
58 class ExtensionSystem
;
59 class ExtensionUpdater
;
60 class PendingExtensionManager
;
61 class SettingsFrontend
;
63 } // namespace extensions
66 class SyncErrorFactory
;
69 // This is an interface class to encapsulate the dependencies that
70 // various classes have on ExtensionService. This allows easy mocking.
71 class ExtensionServiceInterface
72 : public base::SupportsWeakPtr
<ExtensionServiceInterface
> {
74 virtual ~ExtensionServiceInterface() {}
76 // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
77 // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
78 virtual const extensions::ExtensionSet
* extensions() const = 0;
79 virtual const extensions::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. An instance is shared
128 // between normal and incognito profiles.
129 class ExtensionService
130 : public ExtensionServiceInterface
,
131 public extensions::ExternalProviderInterface::VisitorInterface
,
132 public content::NotificationObserver
,
133 public extensions::Blacklist::Observer
{
135 // Returns the Extension for a given url or NULL if the url doesn't belong to
136 // an installed extension. This may be a hosted app extent or a
137 // chrome-extension:// url.
138 const extensions::Extension
* GetInstalledExtensionByUrl(
139 const GURL
& url
) const;
141 // Returns the Extension of hosted or packaged apps, NULL otherwise.
142 const extensions::Extension
* GetInstalledApp(const GURL
& url
) const;
144 // Returns whether the URL is from either a hosted or packaged app.
145 bool IsInstalledApp(const GURL
& url
) const;
147 // Attempts to uninstall an extension from a given ExtensionService. Returns
148 // true iff the target extension exists.
149 static bool UninstallExtensionHelper(ExtensionService
* extensions_service
,
150 const std::string
& extension_id
);
152 // Constructor stores pointers to |profile| and |extension_prefs| but
153 // ownership remains at caller.
154 ExtensionService(Profile
* profile
,
155 const CommandLine
* command_line
,
156 const base::FilePath
& install_directory
,
157 extensions::ExtensionPrefs
* extension_prefs
,
158 extensions::Blacklist
* blacklist
,
159 bool autoupdate_enabled
,
160 bool extensions_enabled
,
161 extensions::OneShotEvent
* ready
);
163 virtual ~ExtensionService();
165 // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
166 // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
167 virtual const extensions::ExtensionSet
* extensions() const OVERRIDE
;
168 virtual const extensions::ExtensionSet
* disabled_extensions() const OVERRIDE
;
170 const extensions::ExtensionSet
* delayed_installs() const;
172 // Returns a set of all installed, disabled, blacklisted, and terminated
174 scoped_ptr
<extensions::ExtensionSet
> GenerateInstalledExtensionsSet() const;
176 // Gets the object managing the set of pending extensions.
177 virtual extensions::PendingExtensionManager
*
178 pending_extension_manager() OVERRIDE
;
180 const base::FilePath
& install_directory() const { return install_directory_
; }
182 // Updates the app launcher value for the moved extension so that it is now
183 // located after the given predecessor and before the successor. This will
184 // trigger a sync if needed. Empty strings are used to indicate no successor
186 void OnExtensionMoved(const std::string
& moved_extension_id
,
187 const std::string
& predecessor_extension_id
,
188 const std::string
& successor_extension_id
);
190 // Whether the persistent background page, if any, is ready. We don't load
191 // other components until then. If there is no background page, or if it is
192 // non-persistent (lazy), we consider it to be ready.
193 bool IsBackgroundPageReady(const extensions::Extension
* extension
) const;
194 void SetBackgroundPageReady(const extensions::Extension
* extension
);
196 // Getter and setter for the flag that specifies whether the extension is
198 bool IsBeingUpgraded(const extensions::Extension
* extension
) const;
199 void SetBeingUpgraded(const extensions::Extension
* extension
, bool value
);
201 // Getter and setter for the flag that specifies whether the extension is
203 bool IsBeingReloaded(const std::string
& extension_id
) const;
204 void SetBeingReloaded(const std::string
& extension_id
, bool value
);
206 // Getter and setter for the flag that specifies if the extension has used
207 // the webrequest API.
208 // TODO(mpcomplete): remove. http://crbug.com/100411
209 bool HasUsedWebRequest(const extensions::Extension
* extension
) const;
210 void SetHasUsedWebRequest(const extensions::Extension
* extension
, bool value
);
212 // Initialize and start all installed extensions.
215 // Attempts to verify all extensions using the InstallVerifier.
216 void VerifyAllExtensions();
218 // Once the verifier work is finished, we may want to re-check management
219 // policy if |success| indicates the verifier got a new signature back.
220 void FinishVerifyAllExtensions(bool success
);
222 // Called when the associated Profile is going to be destroyed.
225 // Look up an extension by ID. Does not include terminated
227 virtual const extensions::Extension
* GetExtensionById(
228 const std::string
& id
, bool include_disabled
) const OVERRIDE
;
230 // Returns the site of the given |extension_id|. Suitable for use with
231 // BrowserContext::GetStoragePartitionForSite().
232 GURL
GetSiteForExtensionId(const std::string
& extension_id
);
234 // Looks up a terminated (crashed) extension by ID.
235 // DEPRECATED: Replace with:
236 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::TERMINATED).
237 const extensions::Extension
*
238 GetTerminatedExtension(const std::string
& id
) const;
240 // Looks up an extension by ID, regardless of whether it's enabled,
241 // disabled, blacklisted, or terminated.
242 // DEPRECATED: Replace with:
243 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING).
244 virtual const extensions::Extension
* GetInstalledExtension(
245 const std::string
& id
) const OVERRIDE
;
247 // Updates a currently-installed extension with the contents from
249 // TODO(aa): This method can be removed. ExtensionUpdater could use
250 // CrxInstaller directly instead.
251 virtual bool UpdateExtension(
252 const std::string
& id
,
253 const base::FilePath
& extension_path
,
254 const GURL
& download_url
,
255 extensions::CrxInstaller
** out_crx_installer
) OVERRIDE
;
257 // Reloads the specified extension, sending the onLaunched() event to it if it
258 // currently has any window showing.
259 void ReloadExtension(const std::string extension_id
);
261 // Uninstalls the specified extension. Callers should only call this method
262 // with extensions that exist. |external_uninstall| is a magical parameter
263 // that is only used to send information to ExtensionPrefs, which external
264 // callers should never set to true.
266 // We pass the |extension_id| by value to avoid having it deleted from under
267 // us incase someone calls it with Extension::id() or another string that we
268 // are going to delete in this function.
270 // TODO(aa): Remove |external_uninstall| -- this information should be passed
271 // to ExtensionPrefs some other way.
272 virtual bool UninstallExtension(std::string extension_id
,
273 bool external_uninstall
,
274 base::string16
* error
);
276 virtual bool IsExtensionEnabled(
277 const std::string
& extension_id
) const OVERRIDE
;
278 virtual bool IsExternalExtensionUninstalled(
279 const std::string
& extension_id
) const OVERRIDE
;
281 // Enables the extension. If the extension is already enabled, does
283 virtual void EnableExtension(const std::string
& extension_id
);
285 // Disables the extension. If the extension is already disabled, or
286 // cannot be disabled, does nothing.
287 virtual void DisableExtension(const std::string
& extension_id
,
288 extensions::Extension::DisableReason disable_reason
);
290 // Disable non-default and non-managed extensions with ids not in
291 // |except_ids|. Default extensions are those from the Web Store with
292 // |was_installed_by_default| flag.
293 void DisableUserExtensions(const std::vector
<std::string
>& except_ids
);
295 // Updates the |extension|'s granted permissions lists to include all
296 // permissions in the |extension|'s manifest and re-enables the
298 void GrantPermissionsAndEnableExtension(
299 const extensions::Extension
* extension
);
301 // Updates the |extension|'s granted permissions lists to include all
302 // permissions in the |extensions|'s manifest.
303 void GrantPermissions(
304 const extensions::Extension
* extension
);
306 // Check for updates (or potentially new extensions from external providers)
307 void CheckForExternalUpdates();
309 // Unload the specified extension.
310 virtual void UnloadExtension(
311 const std::string
& extension_id
,
312 extensions::UnloadedExtensionInfo::Reason reason
) OVERRIDE
;
314 // Remove the specified component extension.
315 virtual void RemoveComponentExtension(const std::string
& extension_id
)
318 // Unload all extensions. Does not send notifications.
319 void UnloadAllExtensionsForTest();
321 // Reloads all extensions. Does not notify that extensions are ready.
322 void ReloadExtensionsForTest();
324 // Scan the extension directory and clean up the cruft.
325 void GarbageCollectExtensions();
327 // Returns true if |url| should get extension api bindings and be permitted
328 // to make api calls. Note that this is independent of what extension
329 // permissions the given extension has been granted.
330 bool ExtensionBindingsAllowed(const GURL
& url
);
332 // Returns true if a normal browser window should avoid showing |url| in a
333 // tab. In this case, |url| is also rewritten to an error URL.
334 bool ShouldBlockUrlInBrowserTab(GURL
* url
);
336 // Called when the initial extensions load has completed.
337 virtual void OnLoadedInstalledExtensions();
339 // Adds |extension| to this ExtensionService and notifies observers that the
340 // extensions have been loaded.
341 virtual void AddExtension(const extensions::Extension
* extension
) OVERRIDE
;
343 // Check if we have preferences for the component extension and, if not or if
344 // the stored version differs, install the extension (without requirements
345 // checking) before calling AddExtension.
346 virtual void AddComponentExtension(const extensions::Extension
* extension
)
351 IMPORT_STATUS_UNSATISFIED
,
352 IMPORT_STATUS_UNRECOVERABLE
355 // Checks an extension's imports. No installed and outdated imports will be
356 // stored in |missing_modules| and |outdated_modules|.
357 ImportStatus
CheckImports(
358 const extensions::Extension
* extension
,
359 std::list
<extensions::SharedModuleInfo::ImportInfo
>* missing_modules
,
360 std::list
<extensions::SharedModuleInfo::ImportInfo
>* outdated_modules
);
362 // Checks an extension's shared module imports to see if they are satisfied.
363 // If they are not, this function adds the dependencies to the pending install
364 // list if |extension| came from the webstore.
365 ImportStatus
SatisfyImports(const extensions::Extension
* extension
);
367 // Returns a set of extensions that import a given extension.
368 scoped_ptr
<const extensions::ExtensionSet
> GetDependentExtensions(
369 const extensions::Extension
* extension
);
371 // Uninstalls shared modules that were only referenced by |extension|.
372 void PruneSharedModulesOnUninstall(const extensions::Extension
* extension
);
374 // Informs the service that an extension's files are in place for loading.
376 // |page_ordinal| is the location of the extension in the app launcher.
377 // |has_requirement_errors| is true if requirements of the extension weren't
378 // met (for example graphics capabilities).
379 // |blacklist_state| will be BLACKLISTED if the extension is blacklisted.
380 // |wait_for_idle| may be false to install the extension immediately.
381 void OnExtensionInstalled(
382 const extensions::Extension
* extension
,
383 const syncer::StringOrdinal
& page_ordinal
,
384 bool has_requirement_errors
,
385 extensions::BlacklistState blacklist_state
,
388 // Checks for delayed installation for all pending installs.
389 void MaybeFinishDelayedInstallations();
391 // Similar to FinishInstallation, but first checks if there still is an update
392 // pending for the extension, and makes sure the extension is still idle.
393 void MaybeFinishDelayedInstallation(const std::string
& extension_id
);
395 // Finishes installation of an update for an extension with the specified id,
396 // when installation of that extension was previously delayed because the
397 // extension was in use.
398 virtual void FinishDelayedInstallation(
399 const std::string
& extension_id
) OVERRIDE
;
401 // Returns an update for an extension with the specified id, if installation
402 // of that update was previously delayed because the extension was in use. If
403 // no updates are pending for the extension returns NULL.
404 virtual const extensions::Extension
* GetPendingExtensionUpdate(
405 const std::string
& extension_id
) const OVERRIDE
;
407 // Go through each extension and unload those that are not allowed to run by
408 // management policy providers (ie. network admin and Google-managed
410 virtual void CheckManagementPolicy() OVERRIDE
;
412 virtual void CheckForUpdatesSoon() OVERRIDE
;
414 void set_extensions_enabled(bool enabled
) { extensions_enabled_
= enabled
; }
415 bool extensions_enabled() { return extensions_enabled_
; }
417 void set_show_extensions_prompts(bool enabled
) {
418 show_extensions_prompts_
= enabled
;
421 bool show_extensions_prompts() {
422 return show_extensions_prompts_
;
427 // Returns profile_ as a BrowserContext.
428 content::BrowserContext
* GetBrowserContext() const;
430 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
431 // ExtensionPrefs* mutable_extension_prefs().
432 extensions::ExtensionPrefs
* extension_prefs();
433 const extensions::ExtensionPrefs
* extension_prefs() const;
435 extensions::SettingsFrontend
* settings_frontend();
437 void set_extension_sync_service(
438 ExtensionSyncService
* extension_sync_service
) {
439 extension_sync_service_
= extension_sync_service
;
442 extensions::ContentSettingsStore
* GetContentSettingsStore();
444 // Whether the extension service is ready.
445 virtual bool is_ready() OVERRIDE
;
447 virtual base::SequencedTaskRunner
* GetFileTaskRunner() OVERRIDE
;
449 extensions::ComponentLoader
* component_loader() {
450 return component_loader_
.get();
453 // Note that this may return NULL if autoupdate is not turned on.
454 extensions::ExtensionUpdater
* updater();
456 extensions::QuotaService
* quota_service() { return "a_service_
; }
458 // Sets the name, id and icon resource path of the given extension into the
459 // returned dictionary. Returns an empty dictionary if the given extension id
461 scoped_ptr
<base::DictionaryValue
> GetExtensionInfo(
462 const std::string
& extension_id
) const;
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 // Set a callback to be called when all external providers are ready and their
599 // extensions have been installed.
600 void set_external_updates_finished_callback_for_test(
601 const base::Closure
& callback
) {
602 external_updates_finished_callback_
= callback
;
605 // Adds/Removes update observers.
606 void AddUpdateObserver(extensions::UpdateObserver
* observer
);
607 void RemoveUpdateObserver(extensions::UpdateObserver
* observer
);
609 #if defined(OS_CHROMEOS)
610 void disable_garbage_collection() {
611 disable_garbage_collection_
= true;
613 void enable_garbage_collection() {
614 disable_garbage_collection_
= false;
619 // Contains Extension data that can change during the life of the process,
620 // but does not persist across restarts.
621 struct ExtensionRuntimeData
{
622 // True if the background page is ready.
623 bool background_page_ready
;
625 // True while the extension is being upgraded.
628 // True if the extension has used the webRequest API.
629 bool has_used_webrequest
;
631 ExtensionRuntimeData();
632 ~ExtensionRuntimeData();
634 typedef std::map
<std::string
, ExtensionRuntimeData
> ExtensionRuntimeDataMap
;
636 // Signals *ready_ and sends a notification to the listeners.
637 void SetReadyAndNotifyListeners();
639 // Return true if the sync type of |extension| matches |type|.
640 void OnExtensionInstallPrefChanged();
642 // Adds the given extension to the list of terminated extensions if
643 // it is not already there and unloads it.
644 void TrackTerminatedExtension(const extensions::Extension
* extension
);
646 // Removes the extension with the given id from the list of
647 // terminated extensions if it is there.
648 void UntrackTerminatedExtension(const std::string
& id
);
650 // Update preferences for a new or updated extension; notify observers that
651 // the extension is installed, e.g., to update event handlers on background
652 // pages; and perform other extension install tasks before calling
654 void AddNewOrUpdatedExtension(
655 const extensions::Extension
* extension
,
656 extensions::Extension::State initial_state
,
657 extensions::BlacklistState blacklist_state
,
658 const syncer::StringOrdinal
& page_ordinal
);
660 // Handles sending notification that |extension| was loaded.
661 void NotifyExtensionLoaded(const extensions::Extension
* extension
);
663 // Handles sending notification that |extension| was unloaded.
664 void NotifyExtensionUnloaded(
665 const extensions::Extension
* extension
,
666 extensions::UnloadedExtensionInfo::Reason reason
);
668 // Common helper to finish installing the given extension.
669 void FinishInstallation(const extensions::Extension
* extension
);
671 // Updates the |extension|'s active permission set to include only permissions
672 // currently requested by the extension and all the permissions required by
674 void UpdateActivePermissions(const extensions::Extension
* extension
);
676 // Disables the extension if the privilege level has increased
677 // (e.g., due to an upgrade).
678 void CheckPermissionsIncrease(const extensions::Extension
* extension
,
679 bool is_extension_installed
);
681 // Helper that updates the active extension list used for crash reporting.
682 void UpdateActiveExtensionsInCrashReporter();
684 // Helper to determine whether we should initially enable an installed
685 // (or upgraded) extension.
686 bool ShouldEnableOnInstall(const extensions::Extension
* extension
);
688 // Helper to determine if updating an extensions should proceed immediately,
689 // or if we should delay the update until further notice.
690 bool ShouldDelayExtensionUpdate(const std::string
& extension_id
,
691 bool wait_for_idle
) const;
693 // Helper to search storage directories for extensions with isolated storage
694 // that have been orphaned by an uninstall.
695 void GarbageCollectIsolatedStorage();
696 void OnGarbageCollectIsolatedStorageFinished();
698 // extensions::Blacklist::Observer implementation.
699 virtual void OnBlacklistUpdated() OVERRIDE
;
701 // Manages the blacklisted extensions, intended as callback from
702 // Blacklist::GetBlacklistedIDs.
703 void ManageBlacklist(const std::set
<std::string
>& blacklisted_ids
);
705 // Controls if installs are delayed. See comment for
706 // |installs_delayed_for_gc_|.
707 void set_installs_delayed_for_gc(bool value
) {
708 installs_delayed_for_gc_
= value
;
710 bool installs_delayed_for_gc() const { return installs_delayed_for_gc_
; }
712 // Used only by test code.
713 void UnloadAllExtensionsInternal();
715 // The normal profile associated with this ExtensionService.
718 // The ExtensionSystem for the profile above.
719 extensions::ExtensionSystem
* system_
;
721 // Preferences for the owning profile.
722 extensions::ExtensionPrefs
* extension_prefs_
;
724 // Blacklist for the owning profile.
725 extensions::Blacklist
* blacklist_
;
727 // Settings for the owning profile.
728 scoped_ptr
<extensions::SettingsFrontend
> settings_frontend_
;
730 // The ExtensionSyncService that is used by this ExtensionService.
731 ExtensionSyncService
* extension_sync_service_
;
733 // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
734 extensions::ExtensionRegistry
* registry_
;
736 // The list of extension installs delayed for various reasons. The reason
737 // for delayed install is stored in ExtensionPrefs. These are not part of
738 // ExtensionRegistry because they are not yet installed.
739 extensions::ExtensionSet delayed_installs_
;
741 // Hold the set of pending extensions.
742 extensions::PendingExtensionManager pending_extension_manager_
;
744 // The map of extension IDs to their runtime data.
745 ExtensionRuntimeDataMap extension_runtime_data_
;
747 // The full path to the directory where extensions are installed.
748 base::FilePath install_directory_
;
750 // Whether or not extensions are enabled.
751 bool extensions_enabled_
;
753 // Whether to notify users when they attempt to install an extension.
754 bool show_extensions_prompts_
;
756 // Whether to delay installing of extension updates until the extension is
758 bool install_updates_when_idle_
;
760 // Used by dispatchers to limit API quota for individual extensions.
761 extensions::QuotaService quota_service_
;
763 // Signaled when all extensions are loaded.
764 extensions::OneShotEvent
* const ready_
;
766 // Our extension updater, if updates are turned on.
767 scoped_ptr
<extensions::ExtensionUpdater
> updater_
;
769 // Map unloaded extensions' ids to their paths. When a temporarily loaded
770 // extension is unloaded, we lose the information about it and don't have
771 // any in the extension preferences file.
772 typedef std::map
<std::string
, base::FilePath
> UnloadedExtensionPathMap
;
773 UnloadedExtensionPathMap unloaded_extension_paths_
;
775 // Store the ids of reloading extensions.
776 std::set
<std::string
> reloading_extensions_
;
778 // Map of DevToolsAgentHost instances that are detached,
779 // waiting for an extension to be reloaded.
780 typedef std::map
<std::string
, scoped_refptr
<content::DevToolsAgentHost
> >
782 OrphanedDevTools orphaned_dev_tools_
;
784 content::NotificationRegistrar registrar_
;
785 PrefChangeRegistrar pref_change_registrar_
;
787 // Keeps track of loading and unloading component extensions.
788 scoped_ptr
<extensions::ComponentLoader
> component_loader_
;
790 // A collection of external extension providers. Each provider reads
791 // a source of external extension information. Examples include the
792 // windows registry and external_extensions.json.
793 extensions::ProviderCollection external_extension_providers_
;
795 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
796 // extension URL is found, and by CheckForUpdatesSoon() when an update check
797 // has to wait for the external providers. Used in
798 // OnAllExternalProvidersReady() to determine if an update check is needed to
799 // install pending extensions.
800 bool update_once_all_providers_are_ready_
;
802 // A callback to be called when all external providers are ready and their
803 // extensions have been installed. Normally this is a null callback, but
804 // is used in external provider related tests.
805 base::Closure external_updates_finished_callback_
;
807 // Set when the browser is terminating. Prevents us from installing or
808 // updating additional extensions and allows in-progress installations to
810 bool browser_terminating_
;
812 // Set to true to delay all new extension installations. Acts as a lock to
813 // allow background processing of garbage collection of on-disk state without
814 // needing to worry about race conditions caused by extension installation and
816 bool installs_delayed_for_gc_
;
818 // Set to true if this is the first time this ExtensionService has run.
819 // Used for specially handling external extensions that are installed the
823 // A set of the extension ids currently being reloaded. We use this to
824 // avoid showing a "new install" notice for an extension reinstall.
825 std::set
<std::string
> extensions_being_reloaded_
;
827 scoped_ptr
<ExtensionErrorUI
> extension_error_ui_
;
828 // Sequenced task runner for extension related file operations.
829 scoped_refptr
<base::SequencedTaskRunner
> file_task_runner_
;
831 #if defined(ENABLE_EXTENSIONS)
832 scoped_ptr
<extensions::ExtensionActionStorageManager
>
833 extension_action_storage_manager_
;
835 scoped_ptr
<extensions::ManagementPolicy::Provider
>
836 shared_module_policy_provider_
;
838 ObserverList
<extensions::UpdateObserver
, true> update_observers_
;
840 #if defined(OS_CHROMEOS)
841 // TODO(rkc): HACK alert - this is only in place to allow the
842 // kiosk_mode_screensaver to prevent its extension from getting garbage
843 // collected. Remove this once KioskModeScreensaver is removed.
844 // See crbug.com/280363
845 bool disable_garbage_collection_
;
848 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
849 InstallAppsWithUnlimtedStorage
);
850 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
851 InstallAppsAndCheckStorageProtection
);
852 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
, SetUnsetBlacklistInPrefs
);
853 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
854 BlacklistedExtensionWillNotInstall
);
855 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
856 UnloadBlacklistedExtensionPolicy
);
857 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
858 WillNotLoadBlacklistedExtensionsFromDirectory
);
859 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
860 BlacklistedInPrefsFromStartup
);
861 DISALLOW_COPY_AND_ASSIGN(ExtensionService
);
864 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_