diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-03 23:00:30 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-03 23:00:30 +0000 |
commit | 3cf4f0999332e4406b29ec19401fdde45a377049 (patch) | |
tree | 1ae1929813a73f6b221ae9e53d09af173cd1d7b9 /chrome/browser/extensions | |
parent | f6a9e5f191be83a7d0a867eed5e5754d378101bb (diff) | |
download | chromium_src-3cf4f0999332e4406b29ec19401fdde45a377049.zip chromium_src-3cf4f0999332e4406b29ec19401fdde45a377049.tar.gz chromium_src-3cf4f0999332e4406b29ec19401fdde45a377049.tar.bz2 |
Add a command line flag to load a single extension from an arbitrary (non-versioned) directory. This is designed for developers to iterate on extension development without having to go through the install process.
Review URL: http://codereview.chromium.org/20020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 35 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 14 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 33 |
3 files changed, 63 insertions, 19 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 60f9880..d749fd57 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -70,6 +70,29 @@ MessageLoop* ExtensionsService::GetMessageLoop() { return message_loop_; } +void ExtensionsService::InstallExtension(const FilePath& extension_path) { + // TODO(aa): This message loop should probably come from a backend + // interface, similar to how the message loop for the frontend comes + // from the frontend interface. + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(backend_.get(), + &ExtensionsServiceBackend::InstallExtension, + extension_path, + install_directory_, + scoped_refptr<ExtensionsServiceFrontendInterface>(this))); +} + +void ExtensionsService::LoadExtension(const FilePath& extension_path) { + // TODO(aa): This message loop should probably come from a backend + // interface, similar to how the message loop for the frontend comes + // from the frontend interface. + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(backend_.get(), + &ExtensionsServiceBackend::LoadSingleExtension, + extension_path, + scoped_refptr<ExtensionsServiceFrontendInterface>(this))); +} + void ExtensionsService::OnExtensionsLoadedFromDirectory( ExtensionList* new_extensions) { extensions_.insert(extensions_.end(), new_extensions->begin(), @@ -107,18 +130,6 @@ void ExtensionsService::OnExtensionLoadError(const std::string& error) { LOG(WARNING) << error; } -void ExtensionsService::InstallExtension(const FilePath& extension_path) { - // TODO(aa): This message loop should probably come from a backend - // interface, similar to how the message loop for the frontend comes - // from the frontend interface. - g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(backend_.get(), - &ExtensionsServiceBackend::InstallExtension, - extension_path, - install_directory_, - scoped_refptr<ExtensionsServiceFrontendInterface>(this))); -} - void ExtensionsService::OnExtensionInstallError(const std::string& error) { // TODO(erikkay): Print the error message out somewhere better. LOG(WARNING) << error; diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 3988a5e..0421f4b 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -27,6 +27,12 @@ class ExtensionsServiceFrontendInterface // The message loop to invoke the frontend's methods on. virtual MessageLoop* GetMessageLoop() = 0; + // Install the extension file at |extension_path|. + virtual void InstallExtension(const FilePath& extension_path) = 0; + + // Load the extension from the directory |extension_path|. + virtual void LoadExtension(const FilePath& extension_path) = 0; + // Called when loading an extension fails. virtual void OnExtensionLoadError(const std::string& message) = 0; @@ -34,9 +40,6 @@ class ExtensionsServiceFrontendInterface // takes ownership of the list. virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions) = 0; - // Install the extension file at extension_path. - virtual void InstallExtension(const FilePath& extension_path) = 0; - // Called when installing an extension fails. virtual void OnExtensionInstallError(const std::string& message) = 0; @@ -62,9 +65,10 @@ class ExtensionsService : public ExtensionsServiceFrontendInterface { // ExtensionsServiceFrontendInterface virtual MessageLoop* GetMessageLoop(); + virtual void InstallExtension(const FilePath& extension_path); + virtual void LoadExtension(const FilePath& extension_path); virtual void OnExtensionLoadError(const std::string& message); virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions); - virtual void InstallExtension(const FilePath& extension_path); virtual void OnExtensionInstallError(const std::string& message); virtual void OnExtensionInstalled(FilePath path); @@ -116,6 +120,8 @@ class ExtensionsServiceBackend // Errors are reported through OnExtensionLoadError(). On completion, // OnExtensionsLoadedFromDirectory() is called with any successfully loaded // extensions. + // TODO(erikkay): It might be useful to be able to load a packed extension + // (presumably into memory) without installing it. bool LoadSingleExtension( const FilePath &path, scoped_refptr<ExtensionsServiceFrontendInterface> frontend); diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index c6af8ff..ed86b6b 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -66,6 +66,12 @@ class ExtensionsServiceTestFrontend return &message_loop_; } + virtual void InstallExtension(const FilePath& extension_path) { + } + + virtual void LoadExtension(const FilePath& extension_path) { + } + virtual void OnExtensionLoadError(const std::string& message) { errors_.push_back(message); } @@ -79,9 +85,6 @@ class ExtensionsServiceTestFrontend std::stable_sort(extensions_.begin(), extensions_.end(), ExtensionsOrder()); } - virtual void InstallExtension(const FilePath& extension_path) { - } - virtual void OnExtensionInstallError(const std::string& message) { errors_.push_back(message); } @@ -217,3 +220,27 @@ TEST_F(ExtensionsServiceTest, InstallExtension) { // TODO(erikkay): add tests for upgrade cases. } +TEST_F(ExtensionsServiceTest, LoadExtension) { + FilePath extensions_path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); + extensions_path = extensions_path.AppendASCII("extensions"); + + scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); + scoped_refptr<ExtensionsServiceTestFrontend> frontend( + new ExtensionsServiceTestFrontend); + + FilePath ext1 = extensions_path.AppendASCII("extension1"); + EXPECT_TRUE(backend->LoadSingleExtension(ext1, + scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); + frontend->GetMessageLoop()->RunAllPending(); + EXPECT_EQ(frontend->errors()->size(), 0u); + ASSERT_EQ(1u, frontend->extensions()->size()); + + FilePath no_manifest = extensions_path.AppendASCII("no_manifest"); + EXPECT_FALSE(backend->LoadSingleExtension(no_manifest, + scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); + frontend->GetMessageLoop()->RunAllPending(); + EXPECT_EQ(frontend->errors()->size(), 1u); + ASSERT_EQ(1u, frontend->extensions()->size()); +} + |