diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-05 00:38:25 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-05 00:38:25 +0000 |
commit | 6014d67a9c2006e15cfa09babfe5eaf63d57a331 (patch) | |
tree | 9c0d36df02bd5b4a0e7fca1fa23045e3e6f26f27 /chrome/browser/extensions/extensions_service.h | |
parent | fad84eab5e64996804824f2c7b8fce98da13b2cd (diff) | |
download | chromium_src-6014d67a9c2006e15cfa09babfe5eaf63d57a331.zip chromium_src-6014d67a9c2006e15cfa09babfe5eaf63d57a331.tar.gz chromium_src-6014d67a9c2006e15cfa09babfe5eaf63d57a331.tar.bz2 |
Introduce ExtensionsService. Load extensions on startup from a directory in
the profile if a command-line flag is present.
Please carefully scrutinize the threading/ref-counting schenanigans.
Review URL: http://codereview.chromium.org/12876
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extensions_service.h')
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h new file mode 100644 index 0000000..17f25b7 --- /dev/null +++ b/chrome/browser/extensions/extensions_service.h @@ -0,0 +1,106 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ + +#include <vector> + +#include "base/file_path.h" +#include "base/message_loop.h" +#include "base/ref_counted.h" +#include "base/task.h" +#include "chrome/browser/extensions/extension.h" + +typedef std::vector<Extension*> ExtensionList; +class ExtensionsServiceBackend; + +// Interface for the frontend to implement. Typically, this will be +// ExtensionsService, but it can also be a test harness. +class ExtensionsServiceFrontendInterface + : public base::RefCountedThreadSafe<ExtensionsServiceFrontendInterface> { + public: + virtual ~ExtensionsServiceFrontendInterface(){} + + // The message loop to invoke the frontend's methods on. + virtual MessageLoop* GetMessageLoop() = 0; + + // Called when loading an extension fails. + virtual void OnExtensionLoadError(const std::wstring& message) = 0; + + // Called with results from LoadExtensionsFromDirectory(). The frontend + // takes ownership of the list. + virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions) = 0; +}; + + +// Manages installed and running Chromium extensions. +class ExtensionsService : public ExtensionsServiceFrontendInterface { + public: + ExtensionsService(const FilePath& profile_directory); + ~ExtensionsService(); + + // Gets the list of currently installed extensions. + const ExtensionList* extensions() const { + return &extensions_; + } + + // Initialize and start all installed extensions. + bool Init(); + + // ExtensionsServiceFrontendInterface + virtual MessageLoop* GetMessageLoop(); + virtual void OnExtensionLoadError(const std::wstring& message); + virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions); + + private: + // The name of the directory inside the profile where extensions are + // installed to. + static const FilePath::CharType* kInstallDirectoryName; + + // The message loop for the thread the ExtensionsService is running on. + MessageLoop* message_loop_; + + // The backend that will do IO on behalf of this instance. + scoped_refptr<ExtensionsServiceBackend> backend_; + + // The current list of installed extensions. + ExtensionList extensions_; + + // The full path to the directory where extensions are installed. + FilePath install_directory_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionsService); +}; + +// Implements IO for the ExtensionsService. +// TODO(aa): Extract an interface out of this for testing the frontend, once the +// frontend has significant logic to test. +class ExtensionsServiceBackend + : public base::RefCountedThreadSafe<ExtensionsServiceBackend> { + public: + ExtensionsServiceBackend(){}; + + // Loads extensions from a directory. The extensions are assumed to be + // unpacked in directories that are direct children of the specified path. + // Errors are reported through OnExtensionLoadError(). On completion, + // OnExtensionsLoadedFromDirectory() is called with any successfully loaded + // extensions. + bool LoadExtensionsFromDirectory( + const FilePath &path, + scoped_refptr<ExtensionsServiceFrontendInterface> frontend); + + private: + // Notify a frontend that there was an error loading an extension. + void ReportExtensionLoadError(ExtensionsServiceFrontendInterface* frontend, + const std::wstring& error); + + // Notify a frontend that extensions were loaded. + void ReportExtensionsLoaded(ExtensionsServiceFrontendInterface* frontend, + ExtensionList* extensions); + + DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |