summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extensions_service.h
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 18:24:32 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 18:24:32 +0000
commitd1ca0ed1b1475318b2f286dd7709dd70826809b3 (patch)
tree7dfa4e725ab8ffc362f935cca15ffca09b31a35d /chrome/browser/extensions/extensions_service.h
parent2a122adcdb2cc0e760e45db988ef1817cebcc61b (diff)
downloadchromium_src-d1ca0ed1b1475318b2f286dd7709dd70826809b3.zip
chromium_src-d1ca0ed1b1475318b2f286dd7709dd70826809b3.tar.gz
chromium_src-d1ca0ed1b1475318b2f286dd7709dd70826809b3.tar.bz2
Create an interface just for update-related functions in ExtensionsService.
This abstracts out the pieces that ExtensionUpdater will depend on, to allow easy mocking. BUG=http://crbug.com/12117 TEST=none Review URL: http://codereview.chromium.org/151127 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19747 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extensions_service.h')
-rw-r--r--chrome/browser/extensions/extensions_service.h37
1 files changed, 26 insertions, 11 deletions
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 81a44d7..4b28169 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -37,10 +37,27 @@ class UserScriptMaster;
typedef std::vector<Extension*> ExtensionList;
+// A callback for when installs finish. If the Extension* parameter is
+// null then the install failed.
+typedef Callback2<const FilePath&, Extension*>::Type ExtensionInstallCallback;
+
+// This is an interface class to encapsulate the dependencies that
+// ExtensionUpdater has on ExtensionsService. This allows easy mocking.
+class ExtensionUpdateService {
+ public:
+ virtual ~ExtensionUpdateService() {}
+ virtual const ExtensionList* extensions() const = 0;
+ virtual void UpdateExtension(const std::string& id,
+ const FilePath& path,
+ bool alert_on_error,
+ ExtensionInstallCallback* callback) = 0;
+ virtual Extension* GetExtensionById(const std::string& id) = 0;
+};
// Manages installed and running Chromium extensions.
class ExtensionsService
- : public base::RefCountedThreadSafe<ExtensionsService> {
+ : public ExtensionUpdateService,
+ public base::RefCountedThreadSafe<ExtensionsService> {
public:
// TODO(port): Move Crx package definitions to ExtentionCreator. They are
@@ -84,10 +101,10 @@ class ExtensionsService
const FilePath& install_directory,
MessageLoop* frontend_loop,
MessageLoop* backend_loop);
- ~ExtensionsService();
+ virtual ~ExtensionsService();
// Gets the list of currently installed extensions.
- const ExtensionList* extensions() const {
+ virtual const ExtensionList* extensions() const {
return &extensions_;
}
@@ -100,18 +117,16 @@ class ExtensionsService
// immediately loaded.
void InstallExtension(const FilePath& extension_path);
- // A callback for when installs finish. If the Extension* parameter is
- // null then the install failed.
- typedef Callback2<const FilePath&, Extension*>::Type Callback;
-
// Updates a currently-installed extension with the contents from
// |extension_path|. The |alert_on_error| parameter controls whether the
// user will be notified in the event of failure. If |callback| is non-null,
// it will be called back when the update is finished (in success or failure).
// This is useful to know when the service is done using |extension_path|.
// Also, this takes ownership of |callback| if it's non-null.
- void UpdateExtension(const std::string& id, const FilePath& extension_path,
- bool alert_on_error, Callback* callback);
+ virtual void UpdateExtension(const std::string& id,
+ const FilePath& extension_path,
+ bool alert_on_error,
+ ExtensionInstallCallback* callback);
// Uninstalls the specified extension. Callers should only call this method
// with extensions that exist.
@@ -140,7 +155,7 @@ class ExtensionsService
void GarbageCollectExtensions();
// Lookup an extension by |id|.
- Extension* GetExtensionById(const std::string& id);
+ virtual Extension* GetExtensionById(const std::string& id);
// Lookup an extension by |url|. This uses the host of the URL as the id.
Extension* GetExtensionByURL(const GURL& url);
@@ -220,7 +235,7 @@ class ExtensionsService
scoped_refptr<ExtensionsServiceBackend> backend_;
// Stores data we'll need to do callbacks as installs complete.
- typedef std::map<FilePath, linked_ptr<Callback> > CallbackMap;
+ typedef std::map<FilePath, linked_ptr<ExtensionInstallCallback> > CallbackMap;
CallbackMap install_callbacks_;
// Is the service ready to go?