Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/extensions/extension_service.h

Issue 8417012: Refactor loading out of ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: components Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 class AppNotificationManager; 47 class AppNotificationManager;
48 class BookmarkExtensionEventRouter; 48 class BookmarkExtensionEventRouter;
49 class CrxInstaller; 49 class CrxInstaller;
50 class ExtensionBrowserEventRouter; 50 class ExtensionBrowserEventRouter;
51 class ExtensionContentSettingsStore; 51 class ExtensionContentSettingsStore;
52 class ExtensionCookiesEventRouter; 52 class ExtensionCookiesEventRouter;
53 class ExtensionDownloadsEventRouter; 53 class ExtensionDownloadsEventRouter;
54 class ExtensionFileBrowserEventRouter; 54 class ExtensionFileBrowserEventRouter;
55 class ExtensionGlobalError; 55 class ExtensionGlobalError;
56 class HistoryExtensionEventRouter;
57 class ExtensionInstallUI; 56 class ExtensionInstallUI;
58 class ExtensionManagementEventRouter; 57 class ExtensionManagementEventRouter;
59 class ExtensionPreferenceEventRouter; 58 class ExtensionPreferenceEventRouter;
60 class ExtensionServiceBackend;
61 class ExtensionSyncData; 59 class ExtensionSyncData;
62 class ExtensionToolbarModel; 60 class ExtensionToolbarModel;
63 class ExtensionUpdater; 61 class ExtensionUpdater;
64 class ExtensionWebNavigationEventRouter; 62 class ExtensionWebNavigationEventRouter;
63 class HistoryExtensionEventRouter;
65 class GURL; 64 class GURL;
66 class PendingExtensionManager; 65 class PendingExtensionManager;
67 class Profile; 66 class Profile;
68 class SyncData; 67 class SyncData;
69 class Version; 68 class Version;
70 69
71 namespace chromeos { 70 namespace chromeos {
72 class ExtensionInputMethodEventRouter; 71 class ExtensionInputMethodEventRouter;
73 } // namespace chromeos 72 }
73
74 namespace extensions {
75 class ComponentLoader;
76 class UnpackedInstaller;
77 }
74 78
75 // This is an interface class to encapsulate the dependencies that 79 // This is an interface class to encapsulate the dependencies that
76 // various classes have on ExtensionService. This allows easy mocking. 80 // various classes have on ExtensionService. This allows easy mocking.
77 class ExtensionServiceInterface : public SyncableService { 81 class ExtensionServiceInterface : public SyncableService {
78 public: 82 public:
79 // A function that returns true if the given extension should be 83 // A function that returns true if the given extension should be
80 // included and false if it should be filtered out. Identical to 84 // included and false if it should be filtered out. Identical to
81 // PendingExtensionInfo::ShouldAllowInstallPredicate. 85 // PendingExtensionInfo::ShouldAllowInstallPredicate.
82 typedef bool (*ExtensionFilter)(const Extension&); 86 typedef bool (*ExtensionFilter)(const Extension&);
83 87
(...skipping 25 matching lines...) Expand all
109 // 113 //
110 // TODO(akalin): Remove this method (and others) once we refactor 114 // TODO(akalin): Remove this method (and others) once we refactor
111 // themes sync to not use it directly. 115 // themes sync to not use it directly.
112 virtual void CheckForUpdatesSoon() = 0; 116 virtual void CheckForUpdatesSoon() = 0;
113 }; 117 };
114 118
115 // Manages installed and running Chromium extensions. 119 // Manages installed and running Chromium extensions.
116 class ExtensionService 120 class ExtensionService
117 : public ExtensionServiceInterface, 121 : public ExtensionServiceInterface,
118 public ExternalExtensionProviderInterface::VisitorInterface, 122 public ExternalExtensionProviderInterface::VisitorInterface,
123 public base::SupportsWeakPtr<ExtensionService>,
119 public content::NotificationObserver { 124 public content::NotificationObserver {
120 public: 125 public:
121 // Information about a registered component extension. 126 using base::SupportsWeakPtr<ExtensionService>::AsWeakPtr;
122 struct ComponentExtensionInfo {
123 ComponentExtensionInfo(const std::string& manifest,
124 const FilePath& root_directory)
125 : manifest(manifest),
126 root_directory(root_directory) {
127 }
128
129 bool Equals(const ComponentExtensionInfo& other) const;
130
131 // The extension's manifest. This is required for component extensions so
132 // that ExtensionService doesn't need to go to disk to load them.
133 std::string manifest;
134
135 // Directory where the extension is stored.
136 FilePath root_directory;
137 };
138 127
139 // The name of the directory inside the profile where extensions are 128 // The name of the directory inside the profile where extensions are
140 // installed to. 129 // installed to.
141 static const char* kInstallDirectoryName; 130 static const char* kInstallDirectoryName;
142 131
143 // If auto-updates are turned on, default to running every 5 hours. 132 // If auto-updates are turned on, default to running every 5 hours.
144 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5; 133 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5;
145 134
146 // The name of the directory inside the profile where per-extension settings 135 // The name of the directory inside the profile where per-extension settings
147 // are stored. 136 // are stored.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 virtual ~ExtensionService(); 172 virtual ~ExtensionService();
184 173
185 // Gets the list of currently installed extensions. 174 // Gets the list of currently installed extensions.
186 virtual const ExtensionList* extensions() const OVERRIDE; 175 virtual const ExtensionList* extensions() const OVERRIDE;
187 const ExtensionList* disabled_extensions() const; 176 const ExtensionList* disabled_extensions() const;
188 const ExtensionList* terminated_extensions() const; 177 const ExtensionList* terminated_extensions() const;
189 178
190 // Gets the object managing the set of pending extensions. 179 // Gets the object managing the set of pending extensions.
191 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE; 180 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
192 181
193 // Registers an extension to be loaded as a component extension.
194 void register_component_extension(const ComponentExtensionInfo& info) {
195 component_extension_manifests_.push_back(info);
196 }
197
198 // Unregisters a component extension from the list of extensions to be loaded
199 void UnregisterComponentExtension(const ComponentExtensionInfo& info);
200
201 const FilePath& install_directory() const { return install_directory_; } 182 const FilePath& install_directory() const { return install_directory_; }
202 183
203 AppsPromo* apps_promo() { return &apps_promo_; } 184 AppsPromo* apps_promo() { return &apps_promo_; }
204 185
205 // Whether this extension can run in an incognito window. 186 // Whether this extension can run in an incognito window.
206 virtual bool IsIncognitoEnabled(const std::string& extension_id) const; 187 virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
207 virtual void SetIsIncognitoEnabled(const std::string& extension_id, 188 virtual void SetIsIncognitoEnabled(const std::string& extension_id,
208 bool enabled); 189 bool enabled);
209 190
210 // Returns true if the given extension can see events and data from another 191 // Returns true if the given extension can see events and data from another
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 289
309 // Updates the |extension|'s granted permissions lists to include all 290 // Updates the |extension|'s granted permissions lists to include all
310 // permissions in the |extension|'s manifest and re-enables the 291 // permissions in the |extension|'s manifest and re-enables the
311 // extension. 292 // extension.
312 void GrantPermissionsAndEnableExtension(const Extension* extension); 293 void GrantPermissionsAndEnableExtension(const Extension* extension);
313 294
314 // Sets the |extension|'s active permissions to |permissions|. 295 // Sets the |extension|'s active permissions to |permissions|.
315 void UpdateActivePermissions(const Extension* extension, 296 void UpdateActivePermissions(const Extension* extension,
316 const ExtensionPermissionSet* permissions); 297 const ExtensionPermissionSet* permissions);
317 298
318 // Loads the extension from the directory |extension_path|.
319 void LoadExtension(const FilePath& extension_path);
320
321 // Loads the extension from the directory |extension_path|.
322 // This version of this method is intended for testing only.
323 void LoadExtension(const FilePath& extension_path, bool prompt_for_plugins);
324
325 // Same as above, but for use with command line switch --load-extension=path.
326 void LoadExtensionFromCommandLine(const FilePath& extension_path);
327
328 // Loads any component extensions.
329 void LoadComponentExtensions();
330
331 // Loads particular component extension.
332 const Extension* LoadComponentExtension(const ComponentExtensionInfo& info);
333
334 // Unloads particular component extension.
335 void UnloadComponentExtension(const ComponentExtensionInfo& info);
336
337 // Loads all known extensions (used by startup and testing code).
338 void LoadAllExtensions();
339
340 // Check for updates (or potentially new extensions from external providers) 299 // Check for updates (or potentially new extensions from external providers)
341 void CheckForExternalUpdates(); 300 void CheckForExternalUpdates();
342 301
343 // Unload the specified extension. 302 // Unload the specified extension.
344 void UnloadExtension(const std::string& extension_id, 303 void UnloadExtension(const std::string& extension_id,
345 extension_misc::UnloadedExtensionReason reason); 304 extension_misc::UnloadedExtensionReason reason);
346 305
347 // Unload all extensions. This is currently only called on shutdown, and 306 // Unload all extensions. This is currently only called on shutdown, and
348 // does not send notifications. 307 // does not send notifications.
349 void UnloadAllExtensions(); 308 void UnloadAllExtensions();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id); 343 const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id);
385 344
386 // Called when the initial extensions load has completed. 345 // Called when the initial extensions load has completed.
387 virtual void OnLoadedInstalledExtensions(); 346 virtual void OnLoadedInstalledExtensions();
388 347
389 // Adds |extension| to this ExtensionService and notifies observers than an 348 // Adds |extension| to this ExtensionService and notifies observers than an
390 // extension has been loaded. Called by the backend after an extension has 349 // extension has been loaded. Called by the backend after an extension has
391 // been loaded from a file and installed. 350 // been loaded from a file and installed.
392 void AddExtension(const Extension* extension); 351 void AddExtension(const Extension* extension);
393 352
394 // Called by the backend when an unpacked extension has been loaded.
395 void OnLoadSingleExtension(const Extension* extension,
396 bool prompt_for_plugins);
397
398 // Called by the backend when an extension has been installed. 353 // Called by the backend when an extension has been installed.
399 void OnExtensionInstalled( 354 void OnExtensionInstalled(
400 const Extension* extension, bool from_webstore, int page_index); 355 const Extension* extension, bool from_webstore, int page_index);
401 356
402 // Initializes the |extension|'s active permission set and disables the 357 // Initializes the |extension|'s active permission set and disables the
403 // extension if the privilege level has increased (e.g., due to an upgrade). 358 // extension if the privilege level has increased (e.g., due to an upgrade).
404 void InitializePermissions(const Extension* extension); 359 void InitializePermissions(const Extension* extension);
405 360
406 // Go through each extensions in pref, unload blacklisted extensions 361 // Go through each extensions in pref, unload blacklisted extensions
407 // and update the blacklist state in pref. 362 // and update the blacklist state in pref.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 396
442 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const, 397 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
443 // ExtensionPrefs* mutable_extension_prefs(). 398 // ExtensionPrefs* mutable_extension_prefs().
444 ExtensionPrefs* extension_prefs(); 399 ExtensionPrefs* extension_prefs();
445 400
446 ExtensionSettingsFrontend* extension_settings_frontend(); 401 ExtensionSettingsFrontend* extension_settings_frontend();
447 402
448 ExtensionContentSettingsStore* GetExtensionContentSettingsStore(); 403 ExtensionContentSettingsStore* GetExtensionContentSettingsStore();
449 404
450 // Whether the extension service is ready. 405 // Whether the extension service is ready.
451 // TODO(skerner): Get rid of this method. crbug.com/63756
452 bool is_ready() { return ready_; } 406 bool is_ready() { return ready_; }
453 407
408 extensions::ComponentLoader* component_loader() {
409 return component_loader_.get();
410 }
411
454 // Note that this may return NULL if autoupdate is not turned on. 412 // Note that this may return NULL if autoupdate is not turned on.
455 ExtensionUpdater* updater(); 413 ExtensionUpdater* updater();
456 414
457 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; } 415 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; }
458 416
459 ExtensionsQuotaService* quota_service() { return &quota_service_; } 417 ExtensionsQuotaService* quota_service() { return &quota_service_; }
460 418
461 ExtensionMenuManager* menu_manager() { return &menu_manager_; } 419 ExtensionMenuManager* menu_manager() { return &menu_manager_; }
462 420
463 AppNotificationManager* app_notification_manager() { 421 AppNotificationManager* app_notification_manager() {
(...skipping 11 matching lines...) Expand all
475 #if defined(OS_CHROMEOS) 433 #if defined(OS_CHROMEOS)
476 ExtensionFileBrowserEventRouter* file_browser_event_router() { 434 ExtensionFileBrowserEventRouter* file_browser_event_router() {
477 return file_browser_event_router_.get(); 435 return file_browser_event_router_.get();
478 } 436 }
479 chromeos::ExtensionInputMethodEventRouter* input_method_event_router() { 437 chromeos::ExtensionInputMethodEventRouter* input_method_event_router() {
480 return input_method_event_router_.get(); 438 return input_method_event_router_.get();
481 } 439 }
482 #endif 440 #endif
483 441
484 // Notify the frontend that there was an error loading an extension. 442 // Notify the frontend that there was an error loading an extension.
485 // This method is public because ExtensionServiceBackend can post to here. 443 // This method is public because UnpackedInstaller and InstalledLoader
444 // can post to here.
445 // TODO(aa): Remove this. It doesn't do enough to be worth the dependency
446 // of these classes on ExtensionService.
486 void ReportExtensionLoadError(const FilePath& extension_path, 447 void ReportExtensionLoadError(const FilePath& extension_path,
487 const std::string& error, 448 const std::string& error,
488 bool be_noisy); 449 bool be_noisy);
489 450
490 // ExtensionHost of background page calls this method right after its render 451 // ExtensionHost of background page calls this method right after its render
491 // view has been created. 452 // view has been created.
492 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); 453 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host);
493 454
494 // For the extension in |version_path| with |id|, check to see if it's an 455 // For the extension in |version_path| with |id|, check to see if it's an
495 // externally managed extension. If so, uninstall it. 456 // externally managed extension. If so, uninstall it.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 // Handles sending notification that |extension| was loaded. 623 // Handles sending notification that |extension| was loaded.
663 void NotifyExtensionLoaded(const Extension* extension); 624 void NotifyExtensionLoaded(const Extension* extension);
664 625
665 // Handles sending notification that |extension| was unloaded. 626 // Handles sending notification that |extension| was unloaded.
666 void NotifyExtensionUnloaded(const Extension* extension, 627 void NotifyExtensionUnloaded(const Extension* extension,
667 extension_misc::UnloadedExtensionReason reason); 628 extension_misc::UnloadedExtensionReason reason);
668 629
669 // Helper that updates the active extension list used for crash reporting. 630 // Helper that updates the active extension list used for crash reporting.
670 void UpdateActiveExtensionsInCrashReporter(); 631 void UpdateActiveExtensionsInCrashReporter();
671 632
672 // Helper method. Loads extension from prefs.
673 void LoadInstalledExtension(const ExtensionInfo& info, bool write_to_prefs);
674
675 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's 633 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's
676 // strong sandbox. Typically, these NaCl modules are stored in extensions 634 // strong sandbox. Typically, these NaCl modules are stored in extensions
677 // and registered here. Not all NaCl modules need to register for a MIME 635 // and registered here. Not all NaCl modules need to register for a MIME
678 // type, just the ones that are responsible for rendering a particular MIME 636 // type, just the ones that are responsible for rendering a particular MIME
679 // type, like application/pdf. Note: We only register NaCl modules in the 637 // type, like application/pdf. Note: We only register NaCl modules in the
680 // browser process. 638 // browser process.
681 void RegisterNaClModule(const GURL& url, const std::string& mime_type); 639 void RegisterNaClModule(const GURL& url, const std::string& mime_type);
682 void UnregisterNaClModule(const GURL& url); 640 void UnregisterNaClModule(const GURL& url);
683 641
684 // Call UpdatePluginListWithNaClModules() after registering or unregistering 642 // Call UpdatePluginListWithNaClModules() after registering or unregistering
685 // a NaCl module to see those changes reflected in the PluginList. 643 // a NaCl module to see those changes reflected in the PluginList.
686 void UpdatePluginListWithNaClModules(); 644 void UpdatePluginListWithNaClModules();
687 645
688 NaClModuleInfoList::iterator FindNaClModule(const GURL& url); 646 NaClModuleInfoList::iterator FindNaClModule(const GURL& url);
689 647
690 // Returns the flags that should be used with Extension::Create() for an
691 // extension that is already installed.
692 int GetExtensionCreateFlagsForInstalledExtension(
693 const ExtensionInfo* info);
694
695 base::WeakPtrFactory<ExtensionService> weak_ptr_factory_;
696
697 // The profile this ExtensionService is part of. 648 // The profile this ExtensionService is part of.
698 Profile* profile_; 649 Profile* profile_;
699 650
700 // Preferences for the owning profile (weak reference). 651 // Preferences for the owning profile (weak reference).
701 ExtensionPrefs* extension_prefs_; 652 ExtensionPrefs* extension_prefs_;
702 653
703 // Settings for the owning profile. 654 // Settings for the owning profile.
704 ExtensionSettingsFrontend extension_settings_frontend_; 655 ExtensionSettingsFrontend extension_settings_frontend_;
705 656
706 // The current list of installed extensions. 657 // The current list of installed extensions.
(...skipping 22 matching lines...) Expand all
729 680
730 // The full path to the directory where extensions are installed. 681 // The full path to the directory where extensions are installed.
731 FilePath install_directory_; 682 FilePath install_directory_;
732 683
733 // Whether or not extensions are enabled. 684 // Whether or not extensions are enabled.
734 bool extensions_enabled_; 685 bool extensions_enabled_;
735 686
736 // Whether to notify users when they attempt to install an extension. 687 // Whether to notify users when they attempt to install an extension.
737 bool show_extensions_prompts_; 688 bool show_extensions_prompts_;
738 689
739 // The backend that will do IO on behalf of this instance. 690 // For loading and unloading component extensions.
740 scoped_refptr<ExtensionServiceBackend> backend_; 691 scoped_ptr<extensions::ComponentLoader> component_loader_;
741 692
742 // Used by dispatchers to limit API quota for individual extensions. 693 // Used by dispatchers to limit API quota for individual extensions.
743 ExtensionsQuotaService quota_service_; 694 ExtensionsQuotaService quota_service_;
744 695
745 // Record that Init() has been called, and chrome::EXTENSIONS_READY 696 // Record that Init() has been called, and chrome::EXTENSIONS_READY
746 // has fired. 697 // has fired.
747 bool ready_; 698 bool ready_;
748 699
749 // Our extension updater, if updates are turned on. 700 // Our extension updater, if updates are turned on.
750 scoped_ptr<ExtensionUpdater> updater_; 701 scoped_ptr<ExtensionUpdater> updater_;
(...skipping 27 matching lines...) Expand all
778 // Keeps track of app notifications. 729 // Keeps track of app notifications.
779 scoped_refptr<AppNotificationManager> app_notification_manager_; 730 scoped_refptr<AppNotificationManager> app_notification_manager_;
780 731
781 // Keeps track of extension permissions. 732 // Keeps track of extension permissions.
782 ExtensionPermissionsManager permissions_manager_; 733 ExtensionPermissionsManager permissions_manager_;
783 734
784 // Keeps track of favicon-sized omnibox icons for extensions. 735 // Keeps track of favicon-sized omnibox icons for extensions.
785 ExtensionIconManager omnibox_icon_manager_; 736 ExtensionIconManager omnibox_icon_manager_;
786 ExtensionIconManager omnibox_popup_icon_manager_; 737 ExtensionIconManager omnibox_popup_icon_manager_;
787 738
788 // List of registered component extensions (see Extension::Location).
789 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions;
790 RegisteredComponentExtensions component_extension_manifests_;
791
792 // Manages the promotion of the web store. 739 // Manages the promotion of the web store.
793 AppsPromo apps_promo_; 740 AppsPromo apps_promo_;
794 741
795 // Flag to make sure event routers are only initialized once. 742 // Flag to make sure event routers are only initialized once.
796 bool event_routers_initialized_; 743 bool event_routers_initialized_;
797 744
798 scoped_ptr<ExtensionDownloadsEventRouter> downloads_event_router_; 745 scoped_ptr<ExtensionDownloadsEventRouter> downloads_event_router_;
799 746
800 scoped_ptr<HistoryExtensionEventRouter> history_event_router_; 747 scoped_ptr<HistoryExtensionEventRouter> history_event_router_;
801 748
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 ExtensionWarningSet extension_warnings_; 783 ExtensionWarningSet extension_warnings_;
837 784
838 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 785 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
839 InstallAppsWithUnlimtedStorage); 786 InstallAppsWithUnlimtedStorage);
840 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 787 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
841 InstallAppsAndCheckStorageProtection); 788 InstallAppsAndCheckStorageProtection);
842 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 789 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
843 }; 790 };
844 791
845 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 792 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698