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

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 6677147: Handle changes in extension ID generation logic better. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback. Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_pref_store.h" 10 #include "chrome/browser/extensions/extension_pref_store.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 // A preference that contains any extension-controlled preferences. 113 // A preference that contains any extension-controlled preferences.
114 const char kPrefPreferences[] = "preferences"; 114 const char kPrefPreferences[] = "preferences";
115 115
116 } // namespace 116 } // namespace
117 117
118 //////////////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////////////////
119 119
120 namespace { 120 namespace {
121 121
122 // TODO(asargent) - This is cleanup code for a key that was introduced into 122 // TODO(mihaip): This is cleanup code for keys for unpacked extensions (which
123 // the extensions.settings sub-dictionary which wasn't a valid extension 123 // are derived from paths). As part of the wstring removal, we changed the way
124 // id. We can remove this in a couple of months. (See http://crbug.com/40017 124 // we hash paths, so we need to move prefs from their old synthesized IDs to
125 // and http://crbug.com/39745 for more details). 125 // their new ones. We can remove this by July 2011. (See http://crbug.com/75945
126 static void CleanupBadExtensionKeys(PrefService* prefs) { 126 // for more details).
127 static void CleanupBadExtensionKeys(const FilePath& root_dir,
128 PrefService* prefs) {
127 DictionaryValue* dictionary = 129 DictionaryValue* dictionary =
128 prefs->GetMutableDictionary(ExtensionPrefs::kExtensionsPref); 130 prefs->GetMutableDictionary(ExtensionPrefs::kExtensionsPref);
129 std::set<std::string> bad_keys; 131 std::map<std::string, std::string> remapped_keys;
130 for (DictionaryValue::key_iterator i = dictionary->begin_keys(); 132 for (DictionaryValue::key_iterator i = dictionary->begin_keys();
131 i != dictionary->end_keys(); ++i) { 133 i != dictionary->end_keys(); ++i) {
132 const std::string& key_name(*i); 134 DictionaryValue* ext;
133 if (!Extension::IdIsValid(key_name)) { 135 if (!dictionary->GetDictionaryWithoutPathExpansion(*i, &ext))
134 bad_keys.insert(key_name); 136 continue;
137
138 int location;
139 FilePath::StringType path_str;
140 if (!ext->GetInteger(kPrefLocation, &location) ||
141 !ext->GetString(kPrefPath, &path_str)) {
142 continue;
143 }
144
145 // Only unpacked extensions have generated IDs.
146 if (location != Extension::LOAD)
147 continue;
148
149 const std::string& prefs_id(*i);
150 FilePath path(path_str);
151 // The persisted path can be relative to the root dir (see
152 // MakePath(s)Relative), but the ID is generated before that, using the
153 // absolute path, so we need to undo that.
154 if (!path.IsAbsolute()) {
155 path = root_dir.Append(path);
156 }
157 std::string computed_id = Extension::GenerateIdForPath(path);
158
159 if (prefs_id != computed_id) {
160 remapped_keys[prefs_id] = computed_id;
135 } 161 }
136 } 162 }
137 bool dirty = false; 163
138 for (std::set<std::string>::iterator i = bad_keys.begin(); 164 if (!remapped_keys.empty()) {
139 i != bad_keys.end(); ++i) { 165 for (std::map<std::string, std::string>::const_iterator i =
140 dirty = true; 166 remapped_keys.begin();
141 dictionary->Remove(*i, NULL); 167 i != remapped_keys.end();
168 ++i) {
169 // Don't clobber prefs under the correct ID if they already exist.
170 if (dictionary->HasKey(i->second)) {
171 CHECK(dictionary->RemoveWithoutPathExpansion(i->first, NULL));
172 continue;
173 }
174 Value* extension_prefs = NULL;
175 CHECK(dictionary->RemoveWithoutPathExpansion(
176 i->first, &extension_prefs));
177 dictionary->SetWithoutPathExpansion(i->second, extension_prefs);
178 }
179
180 prefs->ScheduleSavePersistentPrefs();
142 } 181 }
143 if (dirty)
144 prefs->ScheduleSavePersistentPrefs();
145 } 182 }
146 183
147 static void ExtentToStringSet(const ExtensionExtent& host_extent, 184 static void ExtentToStringSet(const ExtensionExtent& host_extent,
148 std::set<std::string>* result) { 185 std::set<std::string>* result) {
149 ExtensionExtent::PatternList patterns = host_extent.patterns(); 186 ExtensionExtent::PatternList patterns = host_extent.patterns();
150 ExtensionExtent::PatternList::const_iterator i; 187 ExtensionExtent::PatternList::const_iterator i;
151 188
152 for (i = patterns.begin(); i != patterns.end(); ++i) 189 for (i = patterns.begin(); i != patterns.end(); ++i)
153 result->insert(i->GetAsString()); 190 result->insert(i->GetAsString());
154 } 191 }
155 192
156 } // namespace 193 } // namespace
157 194
158 ExtensionPrefs::ExtensionPrefs( 195 ExtensionPrefs::ExtensionPrefs(
159 PrefService* prefs, 196 PrefService* prefs,
160 const FilePath& root_dir, 197 const FilePath& root_dir,
161 ExtensionPrefValueMap* extension_pref_value_map) 198 ExtensionPrefValueMap* extension_pref_value_map)
162 : prefs_(prefs), 199 : prefs_(prefs),
163 install_directory_(root_dir), 200 install_directory_(root_dir),
164 extension_pref_value_map_(extension_pref_value_map) { 201 extension_pref_value_map_(extension_pref_value_map) {
165 // TODO(asargent) - Remove this in a couple of months. (See comment above 202 // TODO(mihaip): Remove this by July 2011 (see comment above).
166 // CleanupBadExtensionKeys). 203 CleanupBadExtensionKeys(root_dir, prefs_);
167 CleanupBadExtensionKeys(prefs_);
168 204
169 MakePathsRelative(); 205 MakePathsRelative();
170 206
171 InitPrefStore(); 207 InitPrefStore();
172 } 208 }
173 209
174 ExtensionPrefs::~ExtensionPrefs() {} 210 ExtensionPrefs::~ExtensionPrefs() {}
175 211
176 // static 212 // static
177 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; 213 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings";
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 1466 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
1431 prefs->RegisterDictionaryPref(kExtensionsPref); 1467 prefs->RegisterDictionaryPref(kExtensionsPref);
1432 prefs->RegisterListPref(kExtensionToolbar); 1468 prefs->RegisterListPref(kExtensionToolbar);
1433 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 1469 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
1434 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 1470 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
1435 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); 1471 prefs->RegisterListPref(prefs::kExtensionInstallAllowList);
1436 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); 1472 prefs->RegisterListPref(prefs::kExtensionInstallDenyList);
1437 prefs->RegisterListPref(prefs::kExtensionInstallForceList); 1473 prefs->RegisterListPref(prefs::kExtensionInstallForceList);
1438 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 1474 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
1439 } 1475 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698