Chromium Code Reviews| Index: chrome/browser/extensions/component_loader.cc |
| diff --git a/chrome/browser/extensions/component_loader.cc b/chrome/browser/extensions/component_loader.cc |
| index eda4325544da66db88b917aafac91a28d709a962..f20f842ed04149d74a983fded5111f805b3c4a02 100644 |
| --- a/chrome/browser/extensions/component_loader.cc |
| +++ b/chrome/browser/extensions/component_loader.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/extensions/component_loader.h" |
| #include "base/command_line.h" |
| +#include "base/file_util.h" |
| #include "base/path_service.h" |
| #include "base/json/json_value_serializer.h" |
| #include "chrome/browser/browser_process.h" |
| @@ -16,6 +17,7 @@ |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/extensions/extension_file_util.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_source.h" |
| @@ -116,6 +118,30 @@ const Extension* ComponentLoader::Add( |
| return NULL; |
| } |
| +const Extension* ComponentLoader::AddFromCommandLine(const FilePath& path) { |
| + // Load extensions from the command line synchronously to avoid a race |
| + // between extension loading and loading an URL from the command line. |
| + base::ThreadRestrictions::ScopedAllowIO allow_io; |
|
Aaron Boodman
2011/11/29 05:32:25
Move this up to the call site in profile_impl.cc.
SeRya
2011/11/29 21:31:00
Removed completely. It's not necessary for the pla
|
| + |
| + FilePath absolute_path = path; |
| + file_util::AbsolutePath(&absolute_path); |
| + std::string error; |
| + scoped_ptr<DictionaryValue> manifest( |
| + extension_file_util::LoadManifest(absolute_path, &error)); |
| + if (!manifest.get()) { |
| + LOG(ERROR) << "Could not load extension from '" << |
| + absolute_path.value() << "'. " << error; |
| + return NULL; |
| + } |
| + Remove(GenerateId(manifest.get())); |
|
Aaron Boodman
2011/11/29 05:32:25
What happens if the extension is already loaded? Y
SeRya
2011/11/29 21:31:00
Previous will be removed and unloaded.
|
| + |
| + ComponentExtensionInfo info(manifest.release(), absolute_path); |
|
Aaron Boodman
2011/11/29 05:32:25
Can you delegate to the Add() method that takes a
SeRya
2011/11/29 21:31:00
Done.
|
| + component_extensions_.push_back(info); |
| + if (extension_service_->is_ready()) |
| + return Load(info); |
| + return NULL; |
| +} |
| + |
| const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { |
| int flags = Extension::REQUIRE_KEY; |
| if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) |
| @@ -153,7 +179,30 @@ void ComponentLoader::Remove(const FilePath& root_directory) { |
| *it = component_extensions_.back(); |
| component_extensions_.pop_back(); |
| - // Determine the extension id and unload the extension. |
| + std::string id = GenerateId(manifest.get()); |
| + if (id.empty()) { |
| + LOG(ERROR) << "Failed to get extension id"; |
| + return; |
| + } |
| + extension_service_-> |
| + UnloadExtension(id, extension_misc::UNLOAD_REASON_DISABLE); |
| +} |
| + |
| +void ComponentLoader::Remove(const std::string& id) { |
|
Aaron Boodman
2011/11/29 05:32:25
Don't duplicate code. One of these methods should
SeRya
2011/11/29 21:31:00
Done.
|
| + RegisteredComponentExtensions::iterator it = component_extensions_.begin(); |
| + for (; it != component_extensions_.end(); ++it) { |
| + if (GenerateId(it->manifest) == id) { |
| + delete it->manifest; |
| + it = component_extensions_.erase(it); |
| + if (extension_service_->is_ready()) |
| + extension_service_-> |
| + UnloadExtension(id, extension_misc::UNLOAD_REASON_DISABLE); |
| + break; |
| + } |
| + } |
| +} |
| + |
| +std::string ComponentLoader::GenerateId(const DictionaryValue* manifest) { |
| std::string public_key; |
| std::string public_key_bytes; |
| std::string id; |
| @@ -161,11 +210,9 @@ void ComponentLoader::Remove(const FilePath& root_directory) { |
| extension_manifest_keys::kPublicKey, &public_key) || |
| !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) || |
| !Extension::GenerateId(public_key_bytes, &id)) { |
| - LOG(ERROR) << "Failed to get extension id"; |
| - return; |
| + return std::string(); |
| } |
| - extension_service_-> |
| - UnloadExtension(id, extension_misc::UNLOAD_REASON_DISABLE); |
| + return id; |
| } |
| void ComponentLoader::AddFileManagerExtension() { |