summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/extension_file_util.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 22:32:07 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 22:32:07 +0000
commit0f9f337262c383b94dce482aba0fac7e5778c852 (patch)
tree9359ce10553fadfb4583601da2b7fe58dba7edce /chrome/common/extensions/extension_file_util.cc
parentcc3d6f596df5fa5fa6258b69e947c8977ade7dc7 (diff)
downloadchromium_src-0f9f337262c383b94dce482aba0fac7e5778c852.zip
chromium_src-0f9f337262c383b94dce482aba0fac7e5778c852.tar.gz
chromium_src-0f9f337262c383b94dce482aba0fac7e5778c852.tar.bz2
Unrevert r63919: "Part 2 of immutable Extension refactor."
I made Extension a refcounted object, and privitized the existing con/destructor and InitFromValue. The only way to get an Extension is to call a factory method. In the next CL, I plan to make the factory method return a const Extension, to guarantee that no one can modify the Extension object after creation. Note: There was a tricky part of this CL because of the difference in semantics between scoped_ptr and scoped_refptr. I had to be careful not to use ptr.release(), since that would result in leaks (an un-Released AddRef). BUG=56558 TEST=no functional change Original Review URL: http://codereview.chromium.org/3982001 TBR=aa Review URL: http://codereview.chromium.org/4186002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/extension_file_util.cc')
-rw-r--r--chrome/common/extensions/extension_file_util.cc29
1 files changed, 12 insertions, 17 deletions
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc
index d530357..c7be522 100644
--- a/chrome/common/extensions/extension_file_util.cc
+++ b/chrome/common/extensions/extension_file_util.cc
@@ -81,15 +81,14 @@ void UninstallExtension(const FilePath& extensions_dir,
file_util::Delete(extensions_dir.AppendASCII(id), true); // recursive.
}
-Extension* LoadExtension(const FilePath& extension_path,
- Extension::Location location,
- bool require_key,
- std::string* error) {
+scoped_refptr<Extension> LoadExtension(const FilePath& extension_path,
+ Extension::Location location,
+ bool require_key,
+ std::string* error) {
FilePath manifest_path =
extension_path.Append(Extension::kManifestFilename);
if (!file_util::PathExists(manifest_path)) {
- *error =
- l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
+ *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
return NULL;
}
@@ -101,8 +100,7 @@ Extension* LoadExtension(const FilePath& extension_path,
// It would be cleaner to have the JSON reader give a specific error
// in this case, but other code tests for a file error with
// error->empty(). For now, be consistent.
- *error =
- l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
+ *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
} else {
*error = StringPrintf("%s %s",
errors::kManifestParseError,
@@ -112,26 +110,23 @@ Extension* LoadExtension(const FilePath& extension_path,
}
if (!root->IsType(Value::TYPE_DICTIONARY)) {
- *error =
- l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID);
+ *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID);
return NULL;
}
DictionaryValue* manifest = static_cast<DictionaryValue*>(root.get());
-
- scoped_ptr<Extension> extension(new Extension(extension_path));
- extension->set_location(location);
-
- if (!extension_l10n_util::LocalizeExtension(extension.get(), manifest, error))
+ if (!extension_l10n_util::LocalizeExtension(extension_path, manifest, error))
return NULL;
- if (!extension->InitFromValue(*manifest, require_key, error))
+ scoped_refptr<Extension> extension(Extension::Create(
+ extension_path, location, *manifest, require_key, error));
+ if (!extension.get())
return NULL;
if (!ValidateExtension(extension.get(), error))
return NULL;
- return extension.release();
+ return extension;
}
bool ValidateExtension(Extension* extension, std::string* error) {