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

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: 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
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 DCHECK(!dictionary->HasKey(computed_id));
asargent_no_longer_on_chrome 2011/04/04 23:46:15 Are you positive it's not possible for someone's p
Mihai Parparita -not on Chrome 2011/04/05 00:22:47 Just deleting the value under the incorrect key se
161 remapped_keys[prefs_id] = computed_id;
135 } 162 }
136 } 163 }
137 bool dirty = false; 164
138 for (std::set<std::string>::iterator i = bad_keys.begin(); 165 if (!remapped_keys.empty()) {
139 i != bad_keys.end(); ++i) { 166 for (std::map<std::string, std::string>::const_iterator i =
140 dirty = true; 167 remapped_keys.begin();
141 dictionary->Remove(*i, NULL); 168 i != remapped_keys.end();
169 ++i) {
170 Value* extension_prefs;
asargent_no_longer_on_chrome 2011/04/04 23:46:15 nit: initialize to NULL
Mihai Parparita -not on Chrome 2011/04/05 00:22:47 Done.
171 DCHECK(dictionary->RemoveWithoutPathExpansion(
172 i->first, &extension_prefs));
asargent_no_longer_on_chrome 2011/04/04 23:46:15 You should probably either change this to a CHECK,
Mihai Parparita -not on Chrome 2011/04/05 00:22:47 Changed to CHECK.
173 dictionary->SetWithoutPathExpansion(i->second, extension_prefs);
174 }
175
176 prefs->ScheduleSavePersistentPrefs();
142 } 177 }
143 if (dirty)
144 prefs->ScheduleSavePersistentPrefs();
145 } 178 }
146 179
147 static void ExtentToStringSet(const ExtensionExtent& host_extent, 180 static void ExtentToStringSet(const ExtensionExtent& host_extent,
148 std::set<std::string>* result) { 181 std::set<std::string>* result) {
149 ExtensionExtent::PatternList patterns = host_extent.patterns(); 182 ExtensionExtent::PatternList patterns = host_extent.patterns();
150 ExtensionExtent::PatternList::const_iterator i; 183 ExtensionExtent::PatternList::const_iterator i;
151 184
152 for (i = patterns.begin(); i != patterns.end(); ++i) 185 for (i = patterns.begin(); i != patterns.end(); ++i)
153 result->insert(i->GetAsString()); 186 result->insert(i->GetAsString());
154 } 187 }
155 188
156 } // namespace 189 } // namespace
157 190
158 ExtensionPrefs::ExtensionPrefs( 191 ExtensionPrefs::ExtensionPrefs(
159 PrefService* prefs, 192 PrefService* prefs,
160 const FilePath& root_dir, 193 const FilePath& root_dir,
161 ExtensionPrefValueMap* extension_pref_value_map) 194 ExtensionPrefValueMap* extension_pref_value_map)
162 : prefs_(prefs), 195 : prefs_(prefs),
163 install_directory_(root_dir), 196 install_directory_(root_dir),
164 extension_pref_value_map_(extension_pref_value_map) { 197 extension_pref_value_map_(extension_pref_value_map) {
165 // TODO(asargent) - Remove this in a couple of months. (See comment above 198 // TODO(mihaip): Remove this by July 2011 (see comment above).
166 // CleanupBadExtensionKeys). 199 CleanupBadExtensionKeys(root_dir, prefs_);
167 CleanupBadExtensionKeys(prefs_);
168 200
169 MakePathsRelative(); 201 MakePathsRelative();
170 202
171 InitPrefStore(); 203 InitPrefStore();
172 } 204 }
173 205
174 ExtensionPrefs::~ExtensionPrefs() {} 206 ExtensionPrefs::~ExtensionPrefs() {}
175 207
176 // static 208 // static
177 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; 209 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings";
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 1462 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
1431 prefs->RegisterDictionaryPref(kExtensionsPref); 1463 prefs->RegisterDictionaryPref(kExtensionsPref);
1432 prefs->RegisterListPref(kExtensionToolbar); 1464 prefs->RegisterListPref(kExtensionToolbar);
1433 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 1465 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
1434 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 1466 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
1435 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); 1467 prefs->RegisterListPref(prefs::kExtensionInstallAllowList);
1436 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); 1468 prefs->RegisterListPref(prefs::kExtensionInstallDenyList);
1437 prefs->RegisterListPref(prefs::kExtensionInstallForceList); 1469 prefs->RegisterListPref(prefs::kExtensionInstallForceList);
1438 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 1470 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
1439 } 1471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698