summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_prefs.cc
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 21:03:23 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 21:03:23 +0000
commita9b00acc0c03fff42673e3eb0d953768640a5fb1 (patch)
tree06b8d431e7760a10fcab5ee2a2493b8b22118fca /chrome/browser/extensions/extension_prefs.cc
parent6501bc016d78c6d419b89bf991314148e6e4494b (diff)
downloadchromium_src-a9b00acc0c03fff42673e3eb0d953768640a5fb1.zip
chromium_src-a9b00acc0c03fff42673e3eb0d953768640a5fb1.tar.gz
chromium_src-a9b00acc0c03fff42673e3eb0d953768640a5fb1.tar.bz2
Refactored ExtensionsPrefs to store paths relative to the extensions install directory. Fix & reenabled two extensions_service unit_tests.
R=erikkay BUG=14714 Review URL: http://codereview.chromium.org/140018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19285 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_prefs.cc')
-rw-r--r--chrome/browser/extensions/extension_prefs.cc73
1 files changed, 70 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 32d6fd5..08a99a4 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -68,11 +68,76 @@ void InstalledExtensions::VisitInstalledExtensions(
////////////////////////////////////////////////////////////////////////////////
-ExtensionPrefs::ExtensionPrefs(PrefService* prefs) : prefs_(prefs) {
+ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir)
+ : prefs_(prefs),
+ install_directory_(root_dir) {
if (!prefs_->FindPreference(kExtensionsPref))
prefs_->RegisterDictionaryPref(kExtensionsPref);
if (!prefs->FindPreference(kExtensionShelf))
prefs->RegisterListPref(kExtensionShelf);
+ MakePathsRelative();
+}
+
+static FilePath::StringType MakePathRelative(const FilePath& parent,
+ const FilePath& child,
+ bool *dirty) {
+ if (!parent.IsParent(child))
+ return child.value();
+
+ if (dirty)
+ *dirty = true;
+ FilePath::StringType retval = child.value().substr(
+ parent.value().length());
+ if (FilePath::IsSeparator(retval[0]))
+ return retval.substr(1);
+ else
+ return retval;
+}
+
+void ExtensionPrefs::MakePathsRelative() {
+ bool dirty = false;
+ const DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref);
+ if (!dict || dict->GetSize() == 0)
+ return;
+
+ for (DictionaryValue::key_iterator i = dict->begin_keys();
+ i != dict->end_keys(); ++i) {
+ DictionaryValue* extension_dict;
+ if (!dict->GetDictionary(*i, &extension_dict))
+ continue;
+ FilePath::StringType path_string;
+ if (!extension_dict->GetString(kPrefPath, &path_string))
+ continue;
+ FilePath path(path_string);
+ if (path.IsAbsolute()) {
+ extension_dict->SetString(kPrefPath,
+ MakePathRelative(install_directory_, path, &dirty));
+ }
+ }
+ if (dirty)
+ prefs_->ScheduleSavePersistentPrefs();
+}
+
+void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) {
+ if (!dict || dict->GetSize() == 0)
+ return;
+
+ for (DictionaryValue::key_iterator i = dict->begin_keys();
+ i != dict->end_keys(); ++i) {
+ DictionaryValue* extension_dict;
+ if (!dict->GetDictionary(*i, &extension_dict)) {
+ NOTREACHED();
+ continue;
+ }
+ FilePath::StringType path_string;
+ if (!extension_dict->GetString(kPrefPath, &path_string)) {
+ NOTREACHED();
+ continue;
+ }
+ DCHECK(!FilePath(path_string).IsAbsolute());
+ extension_dict->SetString(
+ kPrefPath, install_directory_.Append(path_string).value());
+ }
}
DictionaryValue* ExtensionPrefs::CopyCurrentExtensions() {
@@ -80,6 +145,7 @@ DictionaryValue* ExtensionPrefs::CopyCurrentExtensions() {
if (extensions) {
DictionaryValue* copy =
static_cast<DictionaryValue*>(extensions->DeepCopy());
+ MakePathsAbsolute(copy);
return copy;
}
return new DictionaryValue;
@@ -144,8 +210,9 @@ void ExtensionPrefs::OnExtensionInstalled(Extension* extension) {
Value::CreateIntegerValue(Extension::ENABLED));
UpdateExtensionPref(id, kPrefLocation,
Value::CreateIntegerValue(extension->location()));
- UpdateExtensionPref(id, kPrefPath,
- Value::CreateStringValue(extension->path().value()));
+ FilePath::StringType path = MakePathRelative(install_directory_,
+ extension->path(), NULL);
+ UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path));
prefs_->ScheduleSavePersistentPrefs();
}