NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_service.h
blobe6c521562af6c8716f26f563f7f9b007a6e6071f
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 <list>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
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_sync_service.h"
24 #include "chrome/common/extensions/extension_constants.h"
25 #include "content/public/browser/devtools_agent_host.h"
26 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_registrar.h"
28 #include "extensions/browser/extension_prefs.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/common/extension.h"
34 #include "extensions/common/extension_set.h"
35 #include "extensions/common/manifest.h"
36 #include "extensions/common/manifest_handlers/shared_module_info.h"
37 #include "extensions/common/one_shot_event.h"
39 class CommandLine;
40 class ExtensionErrorUI;
41 class ExtensionToolbarModel;
42 class GURL;
43 class Profile;
45 namespace base {
46 class SequencedTaskRunner;
47 class Version;
50 namespace extensions {
51 class BrowserEventRouter;
52 class ComponentLoader;
53 class ContentSettingsStore;
54 class CrxInstaller;
55 class ExtensionActionStorageManager;
56 class ExtensionRegistry;
57 class ExtensionSystem;
58 class ExtensionUpdater;
59 class PendingExtensionManager;
60 class RendererStartupHelper;
61 class SettingsFrontend;
62 class UpdateObserver;
63 } // namespace extensions
65 using extensions::ExtensionIdSet;
67 namespace syncer {
68 class SyncErrorFactory;
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 // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
79 // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
80 virtual const extensions::ExtensionSet* extensions() const = 0;
82 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
84 // Install an update. Return true if the install can be started.
85 // Set out_crx_installer to the installer if one was started.
86 virtual bool UpdateExtension(
87 const std::string& id,
88 const base::FilePath& path,
89 bool file_ownership_passed,
90 const GURL& download_url,
91 extensions::CrxInstaller** out_crx_installer) = 0;
92 virtual const extensions::Extension* GetExtensionById(
93 const std::string& id,
94 bool include_disabled) const = 0;
95 virtual const extensions::Extension* GetInstalledExtension(
96 const std::string& id) const = 0;
98 virtual const extensions::Extension* GetPendingExtensionUpdate(
99 const std::string& extension_id) const = 0;
100 virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
102 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
103 virtual bool IsExternalExtensionUninstalled(
104 const std::string& extension_id) const = 0;
106 virtual void CheckManagementPolicy() = 0;
108 // Safe to call multiple times in a row.
110 // TODO(akalin): Remove this method (and others) once we refactor
111 // themes sync to not use it directly.
112 virtual void CheckForUpdatesSoon() = 0;
114 virtual void AddExtension(const extensions::Extension* extension) = 0;
115 virtual void AddComponentExtension(
116 const extensions::Extension* extension) = 0;
118 virtual void UnloadExtension(
119 const std::string& extension_id,
120 extensions::UnloadedExtensionInfo::Reason reason) = 0;
121 virtual void RemoveComponentExtension(const std::string& extension_id) = 0;
123 virtual bool is_ready() = 0;
125 // Returns task runner for crx installation file I/O operations.
126 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
129 // Manages installed and running Chromium extensions. An instance is shared
130 // between normal and incognito profiles.
131 class ExtensionService
132 : public ExtensionServiceInterface,
133 public extensions::ExternalProviderInterface::VisitorInterface,
134 public content::NotificationObserver,
135 public extensions::Blacklist::Observer {
136 public:
137 // Returns the Extension for a given url or NULL if the url doesn't belong to
138 // an installed extension. This may be a hosted app extent or a
139 // chrome-extension:// url.
140 const extensions::Extension* GetInstalledExtensionByUrl(
141 const GURL& url) const;
143 // Returns the Extension of hosted or packaged apps, NULL otherwise.
144 const extensions::Extension* GetInstalledApp(const GURL& url) const;
146 // Returns whether the URL is from either a hosted or packaged app.
147 bool IsInstalledApp(const GURL& url) const;
149 // Attempts to uninstall an extension from a given ExtensionService. Returns
150 // true iff the target extension exists.
151 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
152 const std::string& extension_id);
154 // Constructor stores pointers to |profile| and |extension_prefs| but
155 // ownership remains at caller.
156 ExtensionService(Profile* profile,
157 const CommandLine* command_line,
158 const base::FilePath& install_directory,
159 extensions::ExtensionPrefs* extension_prefs,
160 extensions::Blacklist* blacklist,
161 bool autoupdate_enabled,
162 bool extensions_enabled,
163 extensions::OneShotEvent* ready);
165 virtual ~ExtensionService();
167 // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
168 // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
169 virtual const extensions::ExtensionSet* extensions() const OVERRIDE;
171 const extensions::ExtensionSet* delayed_installs() const;
173 // Returns a set of all installed, disabled, blacklisted, and terminated
174 // extensions.
175 scoped_ptr<extensions::ExtensionSet> GenerateInstalledExtensionsSet() const;
177 // Gets the object managing the set of pending extensions.
178 virtual extensions::PendingExtensionManager*
179 pending_extension_manager() OVERRIDE;
181 const base::FilePath& install_directory() const { return install_directory_; }
183 // Updates the app launcher value for the moved extension so that it is now
184 // located after the given predecessor and before the successor. This will
185 // trigger a sync if needed. Empty strings are used to indicate no successor
186 // or predecessor.
187 void OnExtensionMoved(const std::string& moved_extension_id,
188 const std::string& predecessor_extension_id,
189 const std::string& successor_extension_id);
191 // Getter and setter for the flag that specifies whether the extension is
192 // being reloaded.
193 bool IsBeingReloaded(const std::string& extension_id) const;
194 void SetBeingReloaded(const std::string& extension_id, bool value);
196 // Initialize and start all installed extensions.
197 void Init();
199 // See if we need to bootstrap the install verifier.
200 void MaybeBootstrapVerifier();
202 // Attempts to verify all extensions using the InstallVerifier. The
203 // |bootstrap| parameter indicates whether we're doing this because the
204 // InstallVerifier needed to be bootstrapped (otherwise it's for another
205 // reason, e.g. extension install/uninstall).
206 void VerifyAllExtensions(bool bootstrap);
208 // Once the verifier work is finished, we may want to re-check management
209 // policy if |success| indicates the verifier got a new signature back.
210 void FinishVerifyAllExtensions(bool bootstrap, bool success);
212 // Called when the associated Profile is going to be destroyed.
213 void Shutdown();
215 // Look up an extension by ID. Does not include terminated
216 // extensions.
217 virtual const extensions::Extension* GetExtensionById(
218 const std::string& id, bool include_disabled) const OVERRIDE;
220 // Returns the site of the given |extension_id|. Suitable for use with
221 // BrowserContext::GetStoragePartitionForSite().
222 GURL GetSiteForExtensionId(const std::string& extension_id);
224 // Looks up a terminated (crashed) extension by ID.
225 // DEPRECATED: Replace with:
226 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::TERMINATED).
227 const extensions::Extension*
228 GetTerminatedExtension(const std::string& id) const;
230 // Looks up an extension by ID, regardless of whether it's enabled,
231 // disabled, blacklisted, or terminated.
232 // DEPRECATED: Replace with:
233 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING).
234 virtual const extensions::Extension* GetInstalledExtension(
235 const std::string& id) const OVERRIDE;
237 // Updates a currently-installed extension with the contents from
238 // |extension_path|.
239 // TODO(aa): This method can be removed. ExtensionUpdater could use
240 // CrxInstaller directly instead.
241 virtual bool UpdateExtension(
242 const std::string& id,
243 const base::FilePath& extension_path,
244 bool file_ownership_passed,
245 const GURL& download_url,
246 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
248 // Reloads the specified extension, sending the onLaunched() event to it if it
249 // currently has any window showing.
250 void ReloadExtension(const std::string extension_id);
252 // Uninstalls the specified extension. Callers should only call this method
253 // with extensions that exist. |external_uninstall| is a magical parameter
254 // that is only used to send information to ExtensionPrefs, which external
255 // callers should never set to true.
257 // We pass the |extension_id| by value to avoid having it deleted from under
258 // us incase someone calls it with Extension::id() or another string that we
259 // are going to delete in this function.
261 // TODO(aa): Remove |external_uninstall| -- this information should be passed
262 // to ExtensionPrefs some other way.
263 virtual bool UninstallExtension(std::string extension_id,
264 bool external_uninstall,
265 base::string16* error);
267 virtual bool IsExtensionEnabled(
268 const std::string& extension_id) const OVERRIDE;
269 virtual bool IsExternalExtensionUninstalled(
270 const std::string& extension_id) const OVERRIDE;
272 // Enables the extension. If the extension is already enabled, does
273 // nothing.
274 virtual void EnableExtension(const std::string& extension_id);
276 // Disables the extension. If the extension is already disabled, or
277 // cannot be disabled, does nothing.
278 virtual void DisableExtension(const std::string& extension_id,
279 extensions::Extension::DisableReason disable_reason);
281 // Disable non-default and non-managed extensions with ids not in
282 // |except_ids|. Default extensions are those from the Web Store with
283 // |was_installed_by_default| flag.
284 void DisableUserExtensions(const std::vector<std::string>& except_ids);
286 // Updates the |extension|'s granted permissions lists to include all
287 // permissions in the |extension|'s manifest and re-enables the
288 // extension.
289 void GrantPermissionsAndEnableExtension(
290 const extensions::Extension* extension);
292 // Updates the |extension|'s granted permissions lists to include all
293 // permissions in the |extensions|'s manifest.
294 void GrantPermissions(
295 const extensions::Extension* extension);
297 // Check for updates (or potentially new extensions from external providers)
298 void CheckForExternalUpdates();
300 // Unload the specified extension.
301 virtual void UnloadExtension(
302 const std::string& extension_id,
303 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
305 // Remove the specified component extension.
306 virtual void RemoveComponentExtension(const std::string& extension_id)
307 OVERRIDE;
309 // Unload all extensions. Does not send notifications.
310 void UnloadAllExtensionsForTest();
312 // Reloads all extensions. Does not notify that extensions are ready.
313 void ReloadExtensionsForTest();
315 // Scan the extension directory and clean up the cruft.
316 void GarbageCollectExtensions();
318 // Returns true if |url| should get extension api bindings and be permitted
319 // to make api calls. Note that this is independent of what extension
320 // permissions the given extension has been granted.
321 bool ExtensionBindingsAllowed(const GURL& url);
323 // Returns true if a normal browser window should avoid showing |url| in a
324 // tab. In this case, |url| is also rewritten to an error URL.
325 bool ShouldBlockUrlInBrowserTab(GURL* url);
327 // Called when the initial extensions load has completed.
328 virtual void OnLoadedInstalledExtensions();
330 // Adds |extension| to this ExtensionService and notifies observers that the
331 // extensions have been loaded.
332 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
334 // Check if we have preferences for the component extension and, if not or if
335 // the stored version differs, install the extension (without requirements
336 // checking) before calling AddExtension.
337 virtual void AddComponentExtension(const extensions::Extension* extension)
338 OVERRIDE;
340 enum ImportStatus {
341 IMPORT_STATUS_OK,
342 IMPORT_STATUS_UNSATISFIED,
343 IMPORT_STATUS_UNRECOVERABLE
346 // Checks an extension's imports. No installed and outdated imports will be
347 // stored in |missing_modules| and |outdated_modules|.
348 ImportStatus CheckImports(
349 const extensions::Extension* extension,
350 std::list<extensions::SharedModuleInfo::ImportInfo>* missing_modules,
351 std::list<extensions::SharedModuleInfo::ImportInfo>* outdated_modules);
353 // Checks an extension's shared module imports to see if they are satisfied.
354 // If they are not, this function adds the dependencies to the pending install
355 // list if |extension| came from the webstore.
356 ImportStatus SatisfyImports(const extensions::Extension* extension);
358 // Returns a set of extensions that import a given extension.
359 scoped_ptr<const extensions::ExtensionSet> GetDependentExtensions(
360 const extensions::Extension* extension);
362 // Uninstalls shared modules that were only referenced by |extension|.
363 void PruneSharedModulesOnUninstall(const extensions::Extension* extension);
365 // Informs the service that an extension's files are in place for loading.
367 // |page_ordinal| is the location of the extension in the app launcher.
368 // |has_requirement_errors| is true if requirements of the extension weren't
369 // met (for example graphics capabilities).
370 // |blacklist_state| will be BLACKLISTED if the extension is blacklisted.
371 // |wait_for_idle| may be false to install the extension immediately.
372 void OnExtensionInstalled(
373 const extensions::Extension* extension,
374 const syncer::StringOrdinal& page_ordinal,
375 bool has_requirement_errors,
376 extensions::BlacklistState blacklist_state,
377 bool wait_for_idle);
379 // Checks for delayed installation for all pending installs.
380 void MaybeFinishDelayedInstallations();
382 // Similar to FinishInstallation, but first checks if there still is an update
383 // pending for the extension, and makes sure the extension is still idle.
384 void MaybeFinishDelayedInstallation(const std::string& extension_id);
386 // Finishes installation of an update for an extension with the specified id,
387 // when installation of that extension was previously delayed because the
388 // extension was in use.
389 virtual void FinishDelayedInstallation(
390 const std::string& extension_id) OVERRIDE;
392 // Returns an update for an extension with the specified id, if installation
393 // of that update was previously delayed because the extension was in use. If
394 // no updates are pending for the extension returns NULL.
395 virtual const extensions::Extension* GetPendingExtensionUpdate(
396 const std::string& extension_id) const OVERRIDE;
398 // Go through each extension and unload those that are not allowed to run by
399 // management policy providers (ie. network admin and Google-managed
400 // blacklist).
401 virtual void CheckManagementPolicy() OVERRIDE;
403 virtual void CheckForUpdatesSoon() OVERRIDE;
405 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
406 bool extensions_enabled() { return extensions_enabled_; }
408 void set_show_extensions_prompts(bool enabled) {
409 show_extensions_prompts_ = enabled;
412 bool show_extensions_prompts() {
413 return show_extensions_prompts_;
416 Profile* profile();
418 // Returns profile_ as a BrowserContext.
419 content::BrowserContext* GetBrowserContext() const;
421 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
422 // ExtensionPrefs* mutable_extension_prefs().
423 extensions::ExtensionPrefs* extension_prefs();
424 const extensions::ExtensionPrefs* extension_prefs() const;
426 extensions::SettingsFrontend* settings_frontend();
428 void set_extension_sync_service(
429 ExtensionSyncService* extension_sync_service) {
430 extension_sync_service_ = extension_sync_service;
433 extensions::ContentSettingsStore* GetContentSettingsStore();
435 // Whether the extension service is ready.
436 virtual bool is_ready() OVERRIDE;
438 virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
440 extensions::ComponentLoader* component_loader() {
441 return component_loader_.get();
444 // Note that this may return NULL if autoupdate is not turned on.
445 extensions::ExtensionUpdater* updater();
447 // Sets the name, id and icon resource path of the given extension into the
448 // returned dictionary. Returns an empty dictionary if the given extension id
449 // is not found.
450 scoped_ptr<base::DictionaryValue> GetExtensionInfo(
451 const std::string& extension_id) const;
453 // Notify the frontend that there was an error loading an extension.
454 // This method is public because UnpackedInstaller and InstalledLoader
455 // can post to here.
456 // TODO(aa): Remove this. It doesn't do enough to be worth the dependency
457 // of these classes on ExtensionService.
458 void ReportExtensionLoadError(const base::FilePath& extension_path,
459 const std::string& error,
460 bool be_noisy);
462 // ExtensionHost of background page calls this method right after its render
463 // view has been created.
464 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
466 // For the extension in |version_path| with |id|, check to see if it's an
467 // externally managed extension. If so, uninstall it.
468 void CheckExternalUninstall(const std::string& id);
470 // Changes sequenced task runner for crx installation tasks to |task_runner|.
471 void SetFileTaskRunnerForTesting(base::SequencedTaskRunner* task_runner);
473 // Clear all ExternalProviders.
474 void ClearProvidersForTesting();
476 // Adds an ExternalProviderInterface for the service to use during testing.
477 // Takes ownership of |test_provider|.
478 void AddProviderForTesting(
479 extensions::ExternalProviderInterface* test_provider);
481 // ExternalProvider::Visitor implementation.
482 virtual bool OnExternalExtensionFileFound(
483 const std::string& id,
484 const base::Version* version,
485 const base::FilePath& path,
486 extensions::Manifest::Location location,
487 int creation_flags,
488 bool mark_acknowledged) OVERRIDE;
490 virtual bool OnExternalExtensionUpdateUrlFound(
491 const std::string& id,
492 const GURL& update_url,
493 extensions::Manifest::Location location,
494 int creation_flags,
495 bool mark_acknowledged) OVERRIDE;
497 virtual void OnExternalProviderReady(
498 const extensions::ExternalProviderInterface* provider) OVERRIDE;
500 // Returns true when all the external extension providers are ready.
501 bool AreAllExternalProvidersReady() const;
503 void OnAllExternalProvidersReady();
505 // Once all external providers are done, generates any needed alerts about
506 // extensions.
507 void IdentifyAlertableExtensions();
509 // Given an ExtensionErrorUI alert, populates it with any extensions that
510 // need alerting. Returns true if the alert should be displayed at all.
512 // This method takes the extension_error_ui argument rather than using
513 // the member variable to make it easier to test the method in isolation.
514 bool PopulateExtensionErrorUI(ExtensionErrorUI* extension_error_ui);
516 // Checks if there are any new external extensions to notify the user about.
517 void UpdateExternalExtensionAlert();
519 // Given a (presumably just-installed) extension id, mark that extension as
520 // acknowledged.
521 void AcknowledgeExternalExtension(const std::string& id);
523 // Returns true if this extension is an external one that has yet to be
524 // marked as acknowledged.
525 bool IsUnacknowledgedExternalExtension(
526 const extensions::Extension* extension);
528 // Disable extensions that are known to be disabled yet are currently enabled.
529 void ReconcileKnownDisabled();
531 // Opens the Extensions page because the user wants to get more details
532 // about the alerts.
533 void HandleExtensionAlertDetails();
535 // Called when the extension alert is closed. Updates prefs and deletes
536 // the active |extension_error_ui_|.
537 void HandleExtensionAlertClosed();
539 // Marks alertable extensions as acknowledged, after the user presses the
540 // accept button.
541 void HandleExtensionAlertAccept();
543 // content::NotificationObserver
544 virtual void Observe(int type,
545 const content::NotificationSource& source,
546 const content::NotificationDetails& details) OVERRIDE;
548 // Whether there are any apps installed. Component apps are not included.
549 bool HasApps() const;
551 // Gets the set of loaded app ids. Component apps are not included.
552 extensions::ExtensionIdSet GetAppIds() const;
554 // Record a histogram using the PermissionMessage enum values for each
555 // permission in |e|.
556 // NOTE: If this is ever called with high frequency, the implementation may
557 // need to be made more efficient.
558 static void RecordPermissionMessagesHistogram(
559 const extensions::Extension* e, const char* histogram);
561 #if defined(UNIT_TEST)
562 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
563 TrackTerminatedExtension(extension);
566 void FinishInstallationForTest(const extensions::Extension* extension) {
567 FinishInstallation(extension);
569 #endif
571 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
573 bool browser_terminating() const { return browser_terminating_; }
575 // For testing.
576 void set_browser_terminating_for_test(bool value) {
577 browser_terminating_ = value;
580 // By default ExtensionService will wait with installing an updated extension
581 // until the extension is idle. Tests might not like this behavior, so you can
582 // disable it with this method.
583 void set_install_updates_when_idle_for_test(bool value) {
584 install_updates_when_idle_ = value;
587 // Set a callback to be called when all external providers are ready and their
588 // extensions have been installed.
589 void set_external_updates_finished_callback_for_test(
590 const base::Closure& callback) {
591 external_updates_finished_callback_ = callback;
594 // Adds/Removes update observers.
595 void AddUpdateObserver(extensions::UpdateObserver* observer);
596 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
598 #if defined(OS_CHROMEOS)
599 void disable_garbage_collection() {
600 disable_garbage_collection_ = true;
602 void enable_garbage_collection() {
603 disable_garbage_collection_ = false;
605 #endif
607 private:
608 // Populates greylist_.
609 void LoadGreylistFromPrefs();
611 // Signals *ready_ and sends a notification to the listeners.
612 void SetReadyAndNotifyListeners();
614 // Return true if the sync type of |extension| matches |type|.
615 void OnExtensionInstallPrefChanged();
617 // Adds the given extension to the list of terminated extensions if
618 // it is not already there and unloads it.
619 void TrackTerminatedExtension(const extensions::Extension* extension);
621 // Removes the extension with the given id from the list of
622 // terminated extensions if it is there.
623 void UntrackTerminatedExtension(const std::string& id);
625 // Update preferences for a new or updated extension; notify observers that
626 // the extension is installed, e.g., to update event handlers on background
627 // pages; and perform other extension install tasks before calling
628 // AddExtension.
629 void AddNewOrUpdatedExtension(
630 const extensions::Extension* extension,
631 extensions::Extension::State initial_state,
632 extensions::BlacklistState blacklist_state,
633 const syncer::StringOrdinal& page_ordinal);
635 // Handles sending notification that |extension| was loaded.
636 void NotifyExtensionLoaded(const extensions::Extension* extension);
638 // Handles sending notification that |extension| was unloaded.
639 void NotifyExtensionUnloaded(
640 const extensions::Extension* extension,
641 extensions::UnloadedExtensionInfo::Reason reason);
643 // Common helper to finish installing the given extension.
644 void FinishInstallation(const extensions::Extension* extension);
646 // Updates the |extension|'s active permission set to include only permissions
647 // currently requested by the extension and all the permissions required by
648 // the extension.
649 void UpdateActivePermissions(const extensions::Extension* extension);
651 // Disables the extension if the privilege level has increased
652 // (e.g., due to an upgrade).
653 void CheckPermissionsIncrease(const extensions::Extension* extension,
654 bool is_extension_installed);
656 // Helper that updates the active extension list used for crash reporting.
657 void UpdateActiveExtensionsInCrashReporter();
659 // Helper to determine whether we should initially enable an installed
660 // (or upgraded) extension.
661 bool ShouldEnableOnInstall(const extensions::Extension* extension);
663 // Helper to determine if updating an extensions should proceed immediately,
664 // or if we should delay the update until further notice.
665 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
666 bool wait_for_idle) const;
668 // Helper to search storage directories for extensions with isolated storage
669 // that have been orphaned by an uninstall.
670 void GarbageCollectIsolatedStorage();
671 void OnGarbageCollectIsolatedStorageFinished();
673 // extensions::Blacklist::Observer implementation.
674 virtual void OnBlacklistUpdated() OVERRIDE;
676 // Manages the blacklisted extensions, intended as callback from
677 // Blacklist::GetBlacklistedIDs.
678 void ManageBlacklist(
679 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
681 // Add extensions in |blocked| to blacklisted_extensions, remove extensions
682 // that are neither in |blocked|, nor in |unchanged|.
683 void UpdateBlockedExtensions(const ExtensionIdSet& blocked,
684 const ExtensionIdSet& unchanged);
686 void UpdateGreylistedExtensions(
687 const ExtensionIdSet& greylist,
688 const ExtensionIdSet& unchanged,
689 const extensions::Blacklist::BlacklistStateMap& state_map);
691 // Controls if installs are delayed. See comment for
692 // |installs_delayed_for_gc_|.
693 void set_installs_delayed_for_gc(bool value) {
694 installs_delayed_for_gc_ = value;
696 bool installs_delayed_for_gc() const { return installs_delayed_for_gc_; }
698 // Used only by test code.
699 void UnloadAllExtensionsInternal();
701 // The normal profile associated with this ExtensionService.
702 Profile* profile_;
704 // The ExtensionSystem for the profile above.
705 extensions::ExtensionSystem* system_;
707 // Preferences for the owning profile.
708 extensions::ExtensionPrefs* extension_prefs_;
710 // Blacklist for the owning profile.
711 extensions::Blacklist* blacklist_;
713 // Settings for the owning profile.
714 scoped_ptr<extensions::SettingsFrontend> settings_frontend_;
716 // The ExtensionSyncService that is used by this ExtensionService.
717 ExtensionSyncService* extension_sync_service_;
719 // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
720 extensions::ExtensionRegistry* registry_;
722 // Set of greylisted extensions. These extensions are disabled if they are
723 // already installed in Chromium at the time when they are added to
724 // the greylist. Unlike blacklisted extensions, greylisted ones are visible
725 // to the user and if user re-enables such an extension, they remain enabled.
727 // These extensions should appear in registry_.
728 extensions::ExtensionSet greylist_;
730 // The list of extension installs delayed for various reasons. The reason
731 // for delayed install is stored in ExtensionPrefs. These are not part of
732 // ExtensionRegistry because they are not yet installed.
733 extensions::ExtensionSet delayed_installs_;
735 // Hold the set of pending extensions.
736 extensions::PendingExtensionManager pending_extension_manager_;
738 // The full path to the directory where extensions are installed.
739 base::FilePath install_directory_;
741 // Whether or not extensions are enabled.
742 bool extensions_enabled_;
744 // Whether to notify users when they attempt to install an extension.
745 bool show_extensions_prompts_;
747 // Whether to delay installing of extension updates until the extension is
748 // idle.
749 bool install_updates_when_idle_;
751 // Signaled when all extensions are loaded.
752 extensions::OneShotEvent* const ready_;
754 // Our extension updater, if updates are turned on.
755 scoped_ptr<extensions::ExtensionUpdater> updater_;
757 // Map unloaded extensions' ids to their paths. When a temporarily loaded
758 // extension is unloaded, we lose the information about it and don't have
759 // any in the extension preferences file.
760 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
761 UnloadedExtensionPathMap unloaded_extension_paths_;
763 // Store the ids of reloading extensions.
764 std::set<std::string> reloading_extensions_;
766 // Map of DevToolsAgentHost instances that are detached,
767 // waiting for an extension to be reloaded.
768 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
769 OrphanedDevTools;
770 OrphanedDevTools orphaned_dev_tools_;
772 content::NotificationRegistrar registrar_;
773 PrefChangeRegistrar pref_change_registrar_;
775 // Keeps track of loading and unloading component extensions.
776 scoped_ptr<extensions::ComponentLoader> component_loader_;
778 // A collection of external extension providers. Each provider reads
779 // a source of external extension information. Examples include the
780 // windows registry and external_extensions.json.
781 extensions::ProviderCollection external_extension_providers_;
783 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
784 // extension URL is found, and by CheckForUpdatesSoon() when an update check
785 // has to wait for the external providers. Used in
786 // OnAllExternalProvidersReady() to determine if an update check is needed to
787 // install pending extensions.
788 bool update_once_all_providers_are_ready_;
790 // A callback to be called when all external providers are ready and their
791 // extensions have been installed. Normally this is a null callback, but
792 // is used in external provider related tests.
793 base::Closure external_updates_finished_callback_;
795 // Set when the browser is terminating. Prevents us from installing or
796 // updating additional extensions and allows in-progress installations to
797 // decide to abort.
798 bool browser_terminating_;
800 // Set to true to delay all new extension installations. Acts as a lock to
801 // allow background processing of garbage collection of on-disk state without
802 // needing to worry about race conditions caused by extension installation and
803 // reinstallation.
804 bool installs_delayed_for_gc_;
806 // Set to true if this is the first time this ExtensionService has run.
807 // Used for specially handling external extensions that are installed the
808 // first time.
809 bool is_first_run_;
811 // A set of the extension ids currently being reloaded. We use this to
812 // avoid showing a "new install" notice for an extension reinstall.
813 std::set<std::string> extensions_being_reloaded_;
815 // A set of the extension ids currently being terminated. We use this to
816 // avoid trying to unload the same extension twice.
817 std::set<std::string> extensions_being_terminated_;
819 scoped_ptr<ExtensionErrorUI> extension_error_ui_;
820 // Sequenced task runner for extension related file operations.
821 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
823 #if defined(ENABLE_EXTENSIONS)
824 scoped_ptr<extensions::ExtensionActionStorageManager>
825 extension_action_storage_manager_;
826 #endif
827 scoped_ptr<extensions::ManagementPolicy::Provider>
828 shared_module_policy_provider_;
830 ObserverList<extensions::UpdateObserver, true> update_observers_;
832 #if defined(OS_CHROMEOS)
833 // TODO(rkc): HACK alert - this is only in place to allow the
834 // kiosk_mode_screensaver to prevent its extension from getting garbage
835 // collected. Remove this once KioskModeScreensaver is removed.
836 // See crbug.com/280363
837 bool disable_garbage_collection_;
838 #endif
840 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
841 InstallAppsWithUnlimtedStorage);
842 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
843 InstallAppsAndCheckStorageProtection);
844 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
845 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
846 BlacklistedExtensionWillNotInstall);
847 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
848 UnloadBlacklistedExtensionPolicy);
849 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
850 WillNotLoadBlacklistedExtensionsFromDirectory);
851 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
852 BlacklistedInPrefsFromStartup);
853 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
854 GreylistedExtensionDisabled);
855 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
856 GreylistDontEnableManuallyDisabled);
857 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
858 GreylistUnknownDontChange);
859 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
862 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_