diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-27 01:38:24 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-27 01:38:24 +0000 |
commit | aa328339ae43ec67bab64fa26bf5b68f7902b9c1 (patch) | |
tree | 29b65f26021c062dfad773a1b5fc6e942aef306f /chrome | |
parent | f0fa95012ce88263ca65e8cf5fb4e7667bfc54e6 (diff) | |
download | chromium_src-aa328339ae43ec67bab64fa26bf5b68f7902b9c1.zip chromium_src-aa328339ae43ec67bab64fa26bf5b68f7902b9c1.tar.gz chromium_src-aa328339ae43ec67bab64fa26bf5b68f7902b9c1.tar.bz2 |
Remove JsonPrefStore pruning of empty values on write.
Written from https://codereview.chromium.org/12092021
The entire source code was surveyed for existing list/dict prefs for which this change could be problematic, it doesn't look like anything is relying on this internal detail of the API, see this for details: https://docs.google.com/a/chromium.org/spreadsheet/ccc?key=0AtwXJ4IPPZBAdG9rX3RTc3k5Z1pyN3U4b3d4Tkota3c#gid=0
TBR=joth (for minor android_webview side-effects)
BUG=323346
Review URL: https://codereview.chromium.org/81183005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/prefs/chrome_pref_service_unittest.cc | 53 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_metrics_service.cc | 16 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_metrics_service.h | 4 |
3 files changed, 0 insertions, 73 deletions
diff --git a/chrome/browser/prefs/chrome_pref_service_unittest.cc b/chrome/browser/prefs/chrome_pref_service_unittest.cc index 4a453fd4..0d27501 100644 --- a/chrome/browser/prefs/chrome_pref_service_unittest.cc +++ b/chrome/browser/prefs/chrome_pref_service_unittest.cc @@ -88,59 +88,6 @@ class ChromePrefServiceUserFilePrefsTest : public testing::Test { base::MessageLoop message_loop_; }; -// Verifies that ListValue and DictionaryValue pref with non emtpy default -// preserves its empty value. -TEST_F(ChromePrefServiceUserFilePrefsTest, PreserveEmptyValue) { - base::FilePath pref_file = temp_dir_.path().AppendASCII("write.json"); - - ASSERT_TRUE(base::CopyFile( - data_dir_.AppendASCII("read.need_empty_value.json"), - pref_file)); - - PrefServiceMockFactory factory; - factory.SetUserPrefsFile(pref_file, - message_loop_.message_loop_proxy().get()); - scoped_refptr<user_prefs::PrefRegistrySyncable> registry( - new user_prefs::PrefRegistrySyncable); - scoped_ptr<PrefServiceSyncable> prefs(factory.CreateSyncable(registry.get())); - - // Register testing prefs. - registry->RegisterListPref("list", - user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); - registry->RegisterDictionaryPref( - "dict", - user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); - - base::ListValue* non_empty_list = new base::ListValue; - non_empty_list->Append(base::Value::CreateStringValue("test")); - registry->RegisterListPref("list_needs_empty_value", - non_empty_list, - user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); - - base::DictionaryValue* non_empty_dict = new base::DictionaryValue; - non_empty_dict->SetString("dummy", "whatever"); - registry->RegisterDictionaryPref( - "dict_needs_empty_value", - non_empty_dict, - user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); - - // Set all testing prefs to empty. - ClearListValue(prefs.get(), "list"); - ClearListValue(prefs.get(), "list_needs_empty_value"); - ClearDictionaryValue(prefs.get(), "dict"); - ClearDictionaryValue(prefs.get(), "dict_needs_empty_value"); - - // Write to file. - prefs->CommitPendingWrite(); - message_loop_.RunUntilIdle(); - - // Compare to expected output. - base::FilePath golden_output_file = - data_dir_.AppendASCII("write.golden.need_empty_value.json"); - ASSERT_TRUE(base::PathExists(golden_output_file)); - EXPECT_TRUE(base::TextContentsEqual(golden_output_file, pref_file)); -} - class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { protected: virtual void SetUp() { diff --git a/chrome/browser/prefs/pref_metrics_service.cc b/chrome/browser/prefs/pref_metrics_service.cc index 6bbfa4a..7c3f920 100644 --- a/chrome/browser/prefs/pref_metrics_service.cc +++ b/chrome/browser/prefs/pref_metrics_service.cc @@ -92,8 +92,6 @@ PrefMetricsService::PrefMetricsService(Profile* profile) RegisterSyncedPrefObservers(); - MarkNeedsEmptyValueForTrackedPreferences(); - // The following code might cause callbacks into this instance before we exit // the constructor. This instance should be initialized at this point. #if defined(OS_WIN) || defined(OS_MACOSX) @@ -122,7 +120,6 @@ PrefMetricsService::PrefMetricsService(Profile* profile, tracked_pref_path_count_(tracked_pref_path_count), checked_tracked_prefs_(false), weak_factory_(this) { - MarkNeedsEmptyValueForTrackedPreferences(); CheckTrackedPreferences(); } @@ -273,19 +270,6 @@ void PrefMetricsService::GetDeviceIdCallback(const std::string& device_id) { CheckTrackedPreferences(); } -void PrefMetricsService::MarkNeedsEmptyValueForTrackedPreferences() { - for (int i = 0; i < tracked_pref_path_count_; ++i) { - // Skip prefs that haven't been registered. - if (!prefs_->FindPreference(tracked_pref_paths_[i])) - continue; - - // Make sure tracked prefs are saved to disk even if empty. - // TODO(gab): Guarantee this for all prefs at a lower level and remove this - // hack. - prefs_->MarkUserStoreNeedsEmptyValue(tracked_pref_paths_[i]); - } -} - // To detect changes to Preferences that happen outside of Chrome, we hash // selected pref values and save them in local state. CheckTrackedPreferences // compares the saved values to the values observed in the profile's prefs. A diff --git a/chrome/browser/prefs/pref_metrics_service.h b/chrome/browser/prefs/pref_metrics_service.h index c776b07..d38a006 100644 --- a/chrome/browser/prefs/pref_metrics_service.h +++ b/chrome/browser/prefs/pref_metrics_service.h @@ -95,10 +95,6 @@ class PrefMetricsService : public BrowserContextKeyedService { // Callback to receive a unique device_id. void GetDeviceIdCallback(const std::string& device_id); - // Marks all tracked preferences as required to save their values even if - // empty. - void MarkNeedsEmptyValueForTrackedPreferences(); - // Checks the tracked preferences against their last known values and reports // any discrepancies. This must be called after |device_id| has been set. void CheckTrackedPreferences(); |