| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_EXTENSIONS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 ExtensionsService(Profile* profile, | 80 ExtensionsService(Profile* profile, |
| 81 const CommandLine* command_line, | 81 const CommandLine* command_line, |
| 82 PrefService* prefs, | 82 PrefService* prefs, |
| 83 const FilePath& install_directory, | 83 const FilePath& install_directory, |
| 84 MessageLoop* frontend_loop, | 84 MessageLoop* frontend_loop, |
| 85 MessageLoop* backend_loop, | 85 MessageLoop* backend_loop, |
| 86 bool autoupdate_enabled); | 86 bool autoupdate_enabled); |
| 87 virtual ~ExtensionsService(); | 87 virtual ~ExtensionsService(); |
| 88 | 88 |
| 89 // Gets the list of currently installed extensions. | 89 // Gets the list of currently installed extensions. |
| 90 virtual const ExtensionList* extensions() const { | 90 virtual const ExtensionList* extensions() const { return &extensions_; } |
| 91 return &extensions_; | 91 virtual const ExtensionList* disabled_extensions() const { |
| 92 return &disabled_extensions_; |
| 92 } | 93 } |
| 93 | 94 |
| 94 const FilePath& install_directory() const { return install_directory_; } | 95 const FilePath& install_directory() const { return install_directory_; } |
| 95 | 96 |
| 96 // Initialize and start all installed extensions. | 97 // Initialize and start all installed extensions. |
| 97 void Init(); | 98 void Init(); |
| 98 | 99 |
| 100 // Look up an extension by ID. |
| 101 Extension* GetExtensionById(const std::string& id) { |
| 102 return GetExtensionByIdInternal(id, true, false); |
| 103 } |
| 104 |
| 99 // Install the extension file at |extension_path|. Will install as an | 105 // Install the extension file at |extension_path|. Will install as an |
| 100 // update if an older version is already installed. | 106 // update if an older version is already installed. |
| 101 // For fresh installs, this method also causes the extension to be | 107 // For fresh installs, this method also causes the extension to be |
| 102 // immediately loaded. | 108 // immediately loaded. |
| 103 // TODO(aa): This method can be removed. It is only used by the unit tests, | 109 // TODO(aa): This method can be removed. It is only used by the unit tests, |
| 104 // and they could use CrxInstaller directly instead. | 110 // and they could use CrxInstaller directly instead. |
| 105 void InstallExtension(const FilePath& extension_path); | 111 void InstallExtension(const FilePath& extension_path); |
| 106 | 112 |
| 107 // Updates a currently-installed extension with the contents from | 113 // Updates a currently-installed extension with the contents from |
| 108 // |extension_path|. | 114 // |extension_path|. |
| 109 // TODO(aa): This method can be removed. ExtensionUpdater could use | 115 // TODO(aa): This method can be removed. ExtensionUpdater could use |
| 110 // CrxInstaller directly instead. | 116 // CrxInstaller directly instead. |
| 111 virtual void UpdateExtension(const std::string& id, | 117 virtual void UpdateExtension(const std::string& id, |
| 112 const FilePath& extension_path); | 118 const FilePath& extension_path); |
| 113 | 119 |
| 114 // Reloads the specified extension. | 120 // Reloads the specified extension. |
| 115 void ReloadExtension(const std::string& extension_id); | 121 void ReloadExtension(const std::string& extension_id); |
| 116 | 122 |
| 117 // Uninstalls the specified extension. Callers should only call this method | 123 // Uninstalls the specified extension. Callers should only call this method |
| 118 // with extensions that exist. |external_uninstall| is a magical parameter | 124 // with extensions that exist. |external_uninstall| is a magical parameter |
| 119 // that is only used to send information to ExtensionPrefs, which external | 125 // that is only used to send information to ExtensionPrefs, which external |
| 120 // callers should never set to true. | 126 // callers should never set to true. |
| 121 // TODO(aa): Remove |external_uninstall| -- this information should be passed | 127 // TODO(aa): Remove |external_uninstall| -- this information should be passed |
| 122 // to ExtensionPrefs some other way. | 128 // to ExtensionPrefs some other way. |
| 123 void UninstallExtension(const std::string& extension_id, | 129 void UninstallExtension(const std::string& extension_id, |
| 124 bool external_uninstall); | 130 bool external_uninstall); |
| 125 | 131 |
| 132 // Enable a previously disabled extension and reload it. The extension should |
| 133 // already exist in the extension prefs. |
| 134 // TODO(mpcomplete): add DisableExtension. |
| 135 void EnableExtension(const std::string& extension_id); |
| 136 |
| 126 // Load the extension from the directory |extension_path|. | 137 // Load the extension from the directory |extension_path|. |
| 127 void LoadExtension(const FilePath& extension_path); | 138 void LoadExtension(const FilePath& extension_path); |
| 128 | 139 |
| 129 // Load all known extensions (used by startup and testing code). | 140 // Load all known extensions (used by startup and testing code). |
| 130 void LoadAllExtensions(); | 141 void LoadAllExtensions(); |
| 131 | 142 |
| 132 // Check for updates (or potentially new extensions from external providers) | 143 // Check for updates (or potentially new extensions from external providers) |
| 133 void CheckForExternalUpdates(); | 144 void CheckForExternalUpdates(); |
| 134 | 145 |
| 135 // Unload the specified extension. | 146 // Unload the specified extension. |
| 136 void UnloadExtension(const std::string& extension_id); | 147 void UnloadExtension(const std::string& extension_id); |
| 137 | 148 |
| 138 // Unload all extensions. | 149 // Unload all extensions. |
| 139 void UnloadAllExtensions(); | 150 void UnloadAllExtensions(); |
| 140 | 151 |
| 141 // Called only by testing. | 152 // Called only by testing. |
| 142 void ReloadExtensions(); | 153 void ReloadExtensions(); |
| 143 | 154 |
| 144 // Scan the extension directory and clean up the cruft. | 155 // Scan the extension directory and clean up the cruft. |
| 145 void GarbageCollectExtensions(); | 156 void GarbageCollectExtensions(); |
| 146 | 157 |
| 147 // Lookup an extension by |id|. | |
| 148 virtual Extension* GetExtensionById(const std::string& id); | |
| 149 | |
| 150 // Lookup an extension by |url|. This uses the host of the URL as the id. | 158 // Lookup an extension by |url|. This uses the host of the URL as the id. |
| 151 Extension* GetExtensionByURL(const GURL& url); | 159 Extension* GetExtensionByURL(const GURL& url); |
| 152 | 160 |
| 153 // Clear all ExternalExtensionProviders. | 161 // Clear all ExternalExtensionProviders. |
| 154 void ClearProvidersForTesting(); | 162 void ClearProvidersForTesting(); |
| 155 | 163 |
| 156 // Sets an ExternalExtensionProvider for the service to use during testing. | 164 // Sets an ExternalExtensionProvider for the service to use during testing. |
| 157 // |location| specifies what type of provider should be added. | 165 // |location| specifies what type of provider should be added. |
| 158 void SetProviderForTesting(Extension::Location location, | 166 void SetProviderForTesting(Extension::Location location, |
| 159 ExternalExtensionProvider* test_provider); | 167 ExternalExtensionProvider* test_provider); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 203 |
| 196 // Profile calls this when it is destroyed so that we know not to call it. | 204 // Profile calls this when it is destroyed so that we know not to call it. |
| 197 void ProfileDestroyed() { profile_ = NULL; } | 205 void ProfileDestroyed() { profile_ = NULL; } |
| 198 | 206 |
| 199 ExtensionPrefs* extension_prefs() { return extension_prefs_.get(); } | 207 ExtensionPrefs* extension_prefs() { return extension_prefs_.get(); } |
| 200 | 208 |
| 201 // Whether the extension service is ready. | 209 // Whether the extension service is ready. |
| 202 bool is_ready() { return ready_; } | 210 bool is_ready() { return ready_; } |
| 203 | 211 |
| 204 private: | 212 private: |
| 213 // Look up an extension by ID, optionally including either or both of enabled |
| 214 // and disabled extensions. |
| 215 Extension* GetExtensionByIdInternal(const std::string& id, |
| 216 bool include_enabled, |
| 217 bool include_disabled); |
| 218 |
| 205 // The profile this ExtensionsService is part of. | 219 // The profile this ExtensionsService is part of. |
| 206 Profile* profile_; | 220 Profile* profile_; |
| 207 | 221 |
| 208 // Preferences for the owning profile. | 222 // Preferences for the owning profile. |
| 209 scoped_ptr<ExtensionPrefs> extension_prefs_; | 223 scoped_ptr<ExtensionPrefs> extension_prefs_; |
| 210 | 224 |
| 211 // The message loop to use with the backend. | 225 // The message loop to use with the backend. |
| 212 MessageLoop* backend_loop_; | 226 MessageLoop* backend_loop_; |
| 213 | 227 |
| 214 // The current list of installed extensions. | 228 // The current list of installed extensions. |
| 215 ExtensionList extensions_; | 229 ExtensionList extensions_; |
| 216 | 230 |
| 231 // The list of installed extensions that have been disabled. |
| 232 ExtensionList disabled_extensions_; |
| 233 |
| 217 // The full path to the directory where extensions are installed. | 234 // The full path to the directory where extensions are installed. |
| 218 FilePath install_directory_; | 235 FilePath install_directory_; |
| 219 | 236 |
| 220 // Whether or not extensions are enabled. | 237 // Whether or not extensions are enabled. |
| 221 bool extensions_enabled_; | 238 bool extensions_enabled_; |
| 222 | 239 |
| 223 // Whether to notify users when they attempt to install an extension. | 240 // Whether to notify users when they attempt to install an extension. |
| 224 bool show_extensions_prompts_; | 241 bool show_extensions_prompts_; |
| 225 | 242 |
| 226 // The backend that will do IO on behalf of this instance. | 243 // The backend that will do IO on behalf of this instance. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 361 |
| 345 // A map of all external extension providers. | 362 // A map of all external extension providers. |
| 346 typedef std::map<Extension::Location, | 363 typedef std::map<Extension::Location, |
| 347 linked_ptr<ExternalExtensionProvider> > ProviderMap; | 364 linked_ptr<ExternalExtensionProvider> > ProviderMap; |
| 348 ProviderMap external_extension_providers_; | 365 ProviderMap external_extension_providers_; |
| 349 | 366 |
| 350 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); | 367 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); |
| 351 }; | 368 }; |
| 352 | 369 |
| 353 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 370 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
| OLD | NEW |