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

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

Issue 8198007: Remove PrefService::ScheduleSavePersistentPrefs and SavePersistentPrefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos Created 9 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 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 // A preference that contains extension-set content settings. 153 // A preference that contains extension-set content settings.
154 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; 154 const char kPrefIncognitoContentSettings[] = "incognito_content_settings";
155 155
156 // Provider of write access to a dictionary storing extension prefs. 156 // Provider of write access to a dictionary storing extension prefs.
157 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 157 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
158 public: 158 public:
159 ScopedExtensionPrefUpdate(PrefService* service, 159 ScopedExtensionPrefUpdate(PrefService* service,
160 const std::string& extension_id) : 160 const std::string& extension_id) :
161 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), 161 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref),
162 prefs_(service),
163 extension_id_(extension_id) {} 162 extension_id_(extension_id) {}
164 163
165 virtual ~ScopedExtensionPrefUpdate() { 164 virtual ~ScopedExtensionPrefUpdate() {
166 prefs_->ScheduleSavePersistentPrefs();
167 } 165 }
168 166
169 virtual DictionaryValue* Get() { 167 virtual DictionaryValue* Get() {
170 DictionaryValue* dict = DictionaryPrefUpdate::Get(); 168 DictionaryValue* dict = DictionaryPrefUpdate::Get();
171 DictionaryValue* extension = NULL; 169 DictionaryValue* extension = NULL;
172 if (!dict->GetDictionary(extension_id_, &extension)) { 170 if (!dict->GetDictionary(extension_id_, &extension)) {
173 // Extension pref does not exist, create it. 171 // Extension pref does not exist, create it.
174 extension = new DictionaryValue(); 172 extension = new DictionaryValue();
175 dict->Set(extension_id_, extension); 173 dict->Set(extension_id_, extension);
176 } 174 }
177 return extension; 175 return extension;
178 } 176 }
179 177
180 private: 178 private:
181 PrefService* prefs_;
182 const std::string extension_id_; 179 const std::string extension_id_;
183 180
184 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); 181 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate);
185 }; 182 };
186 183
187 // Provider of write access to a dictionary storing extension controlled prefs. 184 // Provider of write access to a dictionary storing extension controlled prefs.
188 class ScopedExtensionControlledPrefUpdate : public DictionaryPrefUpdate { 185 class ScopedExtensionControlledPrefUpdate : public DictionaryPrefUpdate {
189 public: 186 public:
190 // |incognito_or_regular_path| indicates the sub-path where the 187 // |incognito_or_regular_path| indicates the sub-path where the
191 // extension controlled preferences are stored. This has to be either 188 // extension controlled preferences are stored. This has to be either
192 // kPrefPreferences or kPrefIncognitoPreferences. 189 // kPrefPreferences or kPrefIncognitoPreferences.
193 ScopedExtensionControlledPrefUpdate( 190 ScopedExtensionControlledPrefUpdate(
194 PrefService* service, 191 PrefService* service,
195 const std::string& extension_id, 192 const std::string& extension_id,
196 const std::string& incognito_or_regular_path) : 193 const std::string& incognito_or_regular_path) :
197 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), 194 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref),
198 prefs_(service),
199 extension_id_(extension_id), 195 extension_id_(extension_id),
200 incognito_or_regular_path_(incognito_or_regular_path) {} 196 incognito_or_regular_path_(incognito_or_regular_path) {}
201 197
202 virtual ~ScopedExtensionControlledPrefUpdate() { 198 virtual ~ScopedExtensionControlledPrefUpdate() {
203 prefs_->ScheduleSavePersistentPrefs();
204 } 199 }
205 200
206 virtual DictionaryValue* Get() { 201 virtual DictionaryValue* Get() {
207 DictionaryValue* dict = DictionaryPrefUpdate::Get(); 202 DictionaryValue* dict = DictionaryPrefUpdate::Get();
208 DictionaryValue* preferences = NULL; 203 DictionaryValue* preferences = NULL;
209 std::string key = 204 std::string key =
210 extension_id_ + std::string(".") + incognito_or_regular_path_; 205 extension_id_ + std::string(".") + incognito_or_regular_path_;
211 if (!dict->GetDictionary(key, &preferences)) { 206 if (!dict->GetDictionary(key, &preferences)) {
212 preferences = new DictionaryValue; 207 preferences = new DictionaryValue;
213 dict->Set(key, preferences); 208 dict->Set(key, preferences);
214 } 209 }
215 return preferences; 210 return preferences;
216 } 211 }
217 212
218 private: 213 private:
219 PrefService* prefs_;
220 const std::string extension_id_; 214 const std::string extension_id_;
221 const std::string incognito_or_regular_path_; 215 const std::string incognito_or_regular_path_;
222 216
223 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionControlledPrefUpdate); 217 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionControlledPrefUpdate);
224 }; 218 };
225 219
226 std::string JoinPrefs(std::string parent, const char* child) { 220 std::string JoinPrefs(std::string parent, const char* child) {
227 return parent + "." + child; 221 return parent + "." + child;
228 } 222 }
229 223
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (!update_dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { 297 if (!update_dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) {
304 NOTREACHED() << "Control should never reach here for extension " << *i; 298 NOTREACHED() << "Control should never reach here for extension " << *i;
305 continue; 299 continue;
306 } 300 }
307 FilePath::StringType path_string; 301 FilePath::StringType path_string;
308 extension_dict->GetString(kPrefPath, &path_string); 302 extension_dict->GetString(kPrefPath, &path_string);
309 FilePath path(path_string); 303 FilePath path(path_string);
310 extension_dict->SetString(kPrefPath, 304 extension_dict->SetString(kPrefPath,
311 MakePathRelative(install_directory_, path)); 305 MakePathRelative(install_directory_, path));
312 } 306 }
313 SavePrefs();
314 } 307 }
315 308
316 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { 309 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) {
317 if (!dict || dict->empty()) 310 if (!dict || dict->empty())
318 return; 311 return;
319 312
320 for (DictionaryValue::key_iterator i = dict->begin_keys(); 313 for (DictionaryValue::key_iterator i = dict->begin_keys();
321 i != dict->end_keys(); ++i) { 314 i != dict->end_keys(); ++i) {
322 DictionaryValue* extension_dict = NULL; 315 DictionaryValue* extension_dict = NULL;
323 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { 316 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 502 }
510 503
511 // Set the scriptable host permissions. 504 // Set the scriptable host permissions.
512 if (!new_value->scriptable_hosts().is_empty()) { 505 if (!new_value->scriptable_hosts().is_empty()) {
513 SetExtensionPrefURLPatternSet(extension_id, 506 SetExtensionPrefURLPatternSet(extension_id,
514 JoinPrefs(pref_key, kPrefScriptableHosts), 507 JoinPrefs(pref_key, kPrefScriptableHosts),
515 new_value->scriptable_hosts()); 508 new_value->scriptable_hosts());
516 } 509 }
517 } 510 }
518 511
519 void ExtensionPrefs::SavePrefs() {
520 prefs_->ScheduleSavePersistentPrefs();
521 }
522
523 // static 512 // static
524 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { 513 bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) {
525 return ReadBooleanFromPref(ext, kPrefBlacklist); 514 return ReadBooleanFromPref(ext, kPrefBlacklist);
526 } 515 }
527 516
528 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { 517 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) {
529 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); 518 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist);
530 } 519 }
531 520
532 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { 521 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 988
1000 void ExtensionPrefs::SetToolbarOrder( 989 void ExtensionPrefs::SetToolbarOrder(
1001 const std::vector<std::string>& extension_ids) { 990 const std::vector<std::string>& extension_ids) {
1002 ListPrefUpdate update(prefs_, kExtensionToolbar); 991 ListPrefUpdate update(prefs_, kExtensionToolbar);
1003 ListValue* toolbar_order = update.Get(); 992 ListValue* toolbar_order = update.Get();
1004 toolbar_order->Clear(); 993 toolbar_order->Clear();
1005 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); 994 for (std::vector<std::string>::const_iterator iter = extension_ids.begin();
1006 iter != extension_ids.end(); ++iter) { 995 iter != extension_ids.end(); ++iter) {
1007 toolbar_order->Append(new StringValue(*iter)); 996 toolbar_order->Append(new StringValue(*iter));
1008 } 997 }
1009 SavePrefs();
1010 } 998 }
1011 999
1012 void ExtensionPrefs::OnExtensionInstalled( 1000 void ExtensionPrefs::OnExtensionInstalled(
1013 const Extension* extension, 1001 const Extension* extension,
1014 Extension::State initial_state, 1002 Extension::State initial_state,
1015 bool from_webstore, 1003 bool from_webstore,
1016 int page_index) { 1004 int page_index) {
1017 const std::string& id = extension->id(); 1005 const std::string& id = extension->id();
1018 CHECK(Extension::IdIsValid(id)); 1006 CHECK(Extension::IdIsValid(id));
1019 ScopedExtensionPrefUpdate update(prefs_, id); 1007 ScopedExtensionPrefUpdate update(prefs_, id);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 update->Set(key, data_value); 1151 update->Set(key, data_value);
1164 else 1152 else
1165 update->Remove(key, NULL); 1153 update->Remove(key, NULL);
1166 } 1154 }
1167 1155
1168 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { 1156 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) {
1169 extension_pref_value_map_->UnregisterExtension(extension_id); 1157 extension_pref_value_map_->UnregisterExtension(extension_id);
1170 content_settings_store_->UnregisterExtension(extension_id); 1158 content_settings_store_->UnregisterExtension(extension_id);
1171 DictionaryPrefUpdate update(prefs_, kExtensionsPref); 1159 DictionaryPrefUpdate update(prefs_, kExtensionsPref);
1172 DictionaryValue* dict = update.Get(); 1160 DictionaryValue* dict = update.Get();
1173 if (dict->HasKey(extension_id)) { 1161 dict->Remove(extension_id, NULL);
1174 dict->Remove(extension_id, NULL);
1175 SavePrefs();
1176 }
1177 } 1162 }
1178 1163
1179 const DictionaryValue* ExtensionPrefs::GetExtensionPref( 1164 const DictionaryValue* ExtensionPrefs::GetExtensionPref(
1180 const std::string& extension_id) const { 1165 const std::string& extension_id) const {
1181 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); 1166 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref);
1182 if (!dict) 1167 if (!dict)
1183 return NULL; 1168 return NULL;
1184 DictionaryValue* extension = NULL; 1169 DictionaryValue* extension = NULL;
1185 dict->GetDictionary(extension_id, &extension); 1170 dict->GetDictionary(extension_id, &extension);
1186 return extension; 1171 return extension;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 bool ExtensionPrefs::GetWebStoreLogin(std::string* result) { 1358 bool ExtensionPrefs::GetWebStoreLogin(std::string* result) {
1374 if (prefs_->HasPrefPath(kWebStoreLogin)) { 1359 if (prefs_->HasPrefPath(kWebStoreLogin)) {
1375 *result = prefs_->GetString(kWebStoreLogin); 1360 *result = prefs_->GetString(kWebStoreLogin);
1376 return true; 1361 return true;
1377 } 1362 }
1378 return false; 1363 return false;
1379 } 1364 }
1380 1365
1381 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { 1366 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) {
1382 prefs_->SetString(kWebStoreLogin, login); 1367 prefs_->SetString(kWebStoreLogin, login);
1383 SavePrefs();
1384 } 1368 }
1385 1369
1386 int ExtensionPrefs::GetAppLaunchIndex(const std::string& extension_id) { 1370 int ExtensionPrefs::GetAppLaunchIndex(const std::string& extension_id) {
1387 int value; 1371 int value;
1388 if (ReadExtensionPrefInteger(extension_id, kPrefAppLaunchIndex, &value)) 1372 if (ReadExtensionPrefInteger(extension_id, kPrefAppLaunchIndex, &value))
1389 return value; 1373 return value;
1390 1374
1391 return -1; 1375 return -1;
1392 } 1376 }
1393 1377
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, 1754 prefs->RegisterListPref(prefs::kExtensionInstallAllowList,
1771 PrefService::UNSYNCABLE_PREF); 1755 PrefService::UNSYNCABLE_PREF);
1772 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, 1756 prefs->RegisterListPref(prefs::kExtensionInstallDenyList,
1773 PrefService::UNSYNCABLE_PREF); 1757 PrefService::UNSYNCABLE_PREF);
1774 prefs->RegisterListPref(prefs::kExtensionInstallForceList, 1758 prefs->RegisterListPref(prefs::kExtensionInstallForceList,
1775 PrefService::UNSYNCABLE_PREF); 1759 PrefService::UNSYNCABLE_PREF);
1776 prefs->RegisterStringPref(kWebStoreLogin, 1760 prefs->RegisterStringPref(kWebStoreLogin,
1777 std::string() /* default_value */, 1761 std::string() /* default_value */,
1778 PrefService::UNSYNCABLE_PREF); 1762 PrefService::UNSYNCABLE_PREF);
1779 } 1763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698