Chromium Code Reviews| Index: chrome/browser/extensions/component_loader.h |
| diff --git a/chrome/browser/extensions/component_loader.h b/chrome/browser/extensions/component_loader.h |
| index 6961098a73174cb5ae09c17f04d470b4fc9df541..9c2816f901b0337db19a280b4eeb23472f52821e 100644 |
| --- a/chrome/browser/extensions/component_loader.h |
| +++ b/chrome/browser/extensions/component_loader.h |
| @@ -9,30 +9,40 @@ |
| #include <string> |
| #include "base/file_path.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/prefs/pref_change_registrar.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "testing/gtest/include/gtest/gtest_prod.h" |
| class Extension; |
| -class ExtensionService; |
| +class ExtensionServiceInterface; |
| +class PrefService; |
| namespace extensions { |
| // For registering, loading, and unloading component extensions. |
| -class ComponentLoader { |
| +class ComponentLoader : public content::NotificationObserver { |
| public: |
| - explicit ComponentLoader(ExtensionService* extension_service); |
| + ComponentLoader(ExtensionServiceInterface* extension_service, |
| + PrefService *prefs); |
| virtual ~ComponentLoader(); |
| // Loads any registered component extensions. |
| void LoadAll(); |
| - // Loads and registers a component extension. If ExtensionService has been |
| - // initialized, the extension is loaded; otherwise, the load is deferred |
| - // until LoadAll is called. |
| - const Extension* Add(const std::string& manifest, |
| + // Registers and possibly loads a component extension. If ExtensionService |
| + // has been initialized, the extension is loaded; otherwise, the load is |
| + // deferred until LoadAll is called. |
| + const Extension* Add(std::string& manifest_contents, |
| + const FilePath& root_directory); |
| + |
| + // Convenience method for registering a component extension by resource id. |
| + const Extension* Add(int manifest_resource_id, |
| const FilePath& root_directory); |
| // Unloads a component extension and removes it from the list of component |
| // extensions to be loaded. |
| - void Remove(const std::string& manifest_str); |
| + void Remove(const FilePath& root_directory); |
| // Adds the default component extensions. |
| // |
| @@ -44,38 +54,61 @@ class ComponentLoader { |
| // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 |
| void AddDefaultComponentExtensions(); |
| + // content::NotificationObserver implementation |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + static void RegisterUserPrefs(PrefService* prefs); |
| + |
| private: |
| + FRIEND_TEST(ComponentLoaderTest, ParseManifest); |
| + FRIEND_TEST(ComponentLoaderTest, EnterpriseWebStore); |
|
Aaron Boodman
2011/11/15 17:34:47
Hate friend. Can you modify the public API to make
Patrick Dubroy
2011/11/15 19:19:16
Sure, if you'd prefer. What's the problem with usi
|
| + |
| // Information about a registered component extension. |
| struct ComponentExtensionInfo { |
| - ComponentExtensionInfo(const std::string& manifest, |
| + ComponentExtensionInfo(const DictionaryValue* manifest, |
| const FilePath& root_directory) |
| : manifest(manifest), |
| root_directory(root_directory) { |
| } |
| - bool Equals(const ComponentExtensionInfo& other) const; |
| - |
| - // The extension's manifest. This is required for component extensions so |
| - // that ExtensionService doesn't need to go to disk to load them. |
| - std::string manifest; |
| + // The parsed contents of the extensions's manifest file. |
| + const DictionaryValue* manifest; |
| // Directory where the extension is stored. |
| FilePath root_directory; |
| }; |
| + // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if |
| + // if the result is not a DictionaryValue. |
| + DictionaryValue* ParseManifest(const std::string& manifest_contents) const; |
| + |
| + const Extension* Add(const DictionaryValue* parsed_manifest, |
| + const FilePath& root_directory); |
| + |
| // Loads a registered component extension. |
| const Extension* Load(const ComponentExtensionInfo& info); |
| - // Registers an extension to be loaded as a component extension. |
| - void Register(const ComponentExtensionInfo& info) { |
| - component_extensions_.push_back(info); |
| + void AddFileManagerExtension(); |
| + |
| + // Add the enterprise webstore extension, or reload it if already loaded. |
| + void AddOrReloadEnterpriseWebStore(); |
| + |
| + // Clear the list of registered extensions (used for testing). |
| + void ClearAllRegisteredForTesting() { |
| + component_extensions_.clear(); |
| } |
| + PrefService* prefs_; |
| + |
| + ExtensionServiceInterface* extension_service_; |
| + |
| // List of registered component extensions (see Extension::Location). |
| typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; |
| RegisteredComponentExtensions component_extensions_; |
| - ExtensionService* extension_service_; |
| + PrefChangeRegistrar pref_change_registrar_; |
| }; |
| } // namespace extensions |