Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: chrome/common/extensions/extension.cc

Issue 256049: Generate IDs for --load-extension by hashing the path instead (Closed)
Patch Set: Removed support for default Extension constructor Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 2ac504e0fee5d3bf465ad210deb649f56ffa2005..f00db656e26fd0ac45373cc694768770c81bb2de 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -64,9 +64,6 @@ static bool IsAPIPermission(const std::string& str) {
} // namespace
-// static
-int Extension::id_counter_ = 0;
-
const char Extension::kManifestFilename[] = "manifest.json";
const char Extension::kLocaleFolder[] = "_locales";
const char Extension::kMessagesFilename[] = "messages.json";
@@ -176,8 +173,7 @@ Extension::Location Extension::ExternalExtensionInstallType(
return Extension::EXTERNAL_PREF;
}
-bool Extension::GenerateIdFromPublicKey(const std::string& input,
- std::string* output) {
+bool Extension::GenerateId(const std::string& input, std::string* output) {
CHECK(output);
if (input.length() == 0)
return false;
@@ -607,7 +603,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
std::string public_key_bytes;
if (!source.GetString(keys::kPublicKey, &public_key_) ||
!ParsePEMKeyBytes(public_key_, &public_key_bytes) ||
- !GenerateIdFromPublicKey(public_key_bytes, &id_)) {
+ !GenerateId(public_key_bytes, &id_)) {
*error = errors::kInvalidKey;
return false;
}
@@ -615,14 +611,13 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
*error = errors::kInvalidKey;
return false;
} else {
- // Generate a random ID
- id_ = StringPrintf("%x", NextGeneratedId());
-
- // pad the string out to kIdSize*2 chars with zeroes.
- id_.insert(0, Extension::kIdSize*2 - id_.length(), '0');
-
- // Convert to our mp-decimal.
- ConvertHexadecimalToIDAlphabet(&id_);
+ // If there is a path, we generate the ID from it. This is useful for
+ // development mode, because it keeps the ID stable across restarts and
+ // reloading the extension.
+ if (!GenerateId(WideToUTF8(path_.ToWStringHack()), &id_)) {
+ NOTREACHED() << "Could not create ID from path.";
+ return false;
+ }
}
// Make a copy of the manifest so we can store it in prefs.
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698