diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-13 16:23:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-14 10:37:21 +0000 |
commit | 38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch) | |
tree | c4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/components/prefs | |
parent | e684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff) | |
download | qtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz |
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/prefs')
-rw-r--r-- | chromium/components/prefs/json_pref_store_unittest.cc | 24 | ||||
-rw-r--r-- | chromium/components/prefs/overlay_user_pref_store.cc | 4 | ||||
-rw-r--r-- | chromium/components/prefs/pref_notifier_impl.h | 4 | ||||
-rw-r--r-- | chromium/components/prefs/pref_registry.h | 4 | ||||
-rw-r--r-- | chromium/components/prefs/pref_service.cc | 24 | ||||
-rw-r--r-- | chromium/components/prefs/pref_service.h | 4 | ||||
-rw-r--r-- | chromium/components/prefs/pref_service_unittest.cc | 4 | ||||
-rw-r--r-- | chromium/components/prefs/pref_value_map.cc | 47 | ||||
-rw-r--r-- | chromium/components/prefs/pref_value_map.h | 8 | ||||
-rw-r--r-- | chromium/components/prefs/scoped_user_pref_update_unittest.cc | 28 | ||||
-rw-r--r-- | chromium/components/prefs/testing_pref_store.cc | 5 |
11 files changed, 93 insertions, 63 deletions
diff --git a/chromium/components/prefs/json_pref_store_unittest.cc b/chromium/components/prefs/json_pref_store_unittest.cc index 8f5bf74736f..d4e7870c1f6 100644 --- a/chromium/components/prefs/json_pref_store_unittest.cc +++ b/chromium/components/prefs/json_pref_store_unittest.cc @@ -14,12 +14,12 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/metrics/histogram_samples.h" #include "base/path_service.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" @@ -208,8 +208,8 @@ TEST_P(JsonPrefStoreTest, NonExistentFile) { // Test fallback behavior for an invalid file. TEST_P(JsonPrefStoreTest, InvalidFile) { base::FilePath invalid_file = temp_dir_.GetPath().AppendASCII("invalid.json"); - ASSERT_LT(0, base::WriteFile(invalid_file, - kInvalidJson, arraysize(kInvalidJson) - 1)); + ASSERT_LT(0, base::WriteFile(invalid_file, kInvalidJson, + base::size(kInvalidJson) - 1)); auto pref_store = base::MakeRefCounted<JsonPrefStore>(invalid_file); EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE, @@ -305,8 +305,8 @@ void RunBasicJsonPrefStoreTest( TEST_P(JsonPrefStoreTest, Basic) { base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); - ASSERT_LT(0, base::WriteFile(input_file, - kReadJson, arraysize(kReadJson) - 1)); + ASSERT_LT(0, + base::WriteFile(input_file, kReadJson, base::size(kReadJson) - 1)); // Test that the persistent value can be loaded. ASSERT_TRUE(PathExists(input_file)); @@ -331,8 +331,8 @@ TEST_P(JsonPrefStoreTest, Basic) { TEST_P(JsonPrefStoreTest, BasicAsync) { base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); - ASSERT_LT(0, base::WriteFile(input_file, - kReadJson, arraysize(kReadJson) - 1)); + ASSERT_LT(0, + base::WriteFile(input_file, kReadJson, base::size(kReadJson) - 1)); // Test that the persistent value can be loaded. auto pref_store = base::MakeRefCounted<JsonPrefStore>(input_file); @@ -437,8 +437,8 @@ TEST_P(JsonPrefStoreTest, AsyncNonExistingFile) { TEST_P(JsonPrefStoreTest, ReadWithInterceptor) { base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); - ASSERT_LT(0, base::WriteFile(input_file, - kReadJson, arraysize(kReadJson) - 1)); + ASSERT_LT(0, + base::WriteFile(input_file, kReadJson, base::size(kReadJson) - 1)); std::unique_ptr<InterceptingPrefFilter> intercepting_pref_filter( new InterceptingPrefFilter()); @@ -479,8 +479,8 @@ TEST_P(JsonPrefStoreTest, ReadWithInterceptor) { TEST_P(JsonPrefStoreTest, ReadAsyncWithInterceptor) { base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); - ASSERT_LT(0, base::WriteFile(input_file, - kReadJson, arraysize(kReadJson) - 1)); + ASSERT_LT(0, + base::WriteFile(input_file, kReadJson, base::size(kReadJson) - 1)); std::unique_ptr<InterceptingPrefFilter> intercepting_pref_filter( new InterceptingPrefFilter()); @@ -851,7 +851,7 @@ class JsonPrefStoreCallbackTest : public testing::Test { TEST_F(JsonPrefStoreCallbackTest, TestSerializeDataCallbacks) { base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); ASSERT_LT(0, - base::WriteFile(input_file, kReadJson, arraysize(kReadJson) - 1)); + base::WriteFile(input_file, kReadJson, base::size(kReadJson) - 1)); std::unique_ptr<InterceptingPrefFilter> intercepting_pref_filter( new InterceptingPrefFilter(write_callback_observer_.GetCallbackPair())); diff --git a/chromium/components/prefs/overlay_user_pref_store.cc b/chromium/components/prefs/overlay_user_pref_store.cc index e5240ab6468..0baa6c4b8ad 100644 --- a/chromium/components/prefs/overlay_user_pref_store.cc +++ b/chromium/components/prefs/overlay_user_pref_store.cc @@ -115,10 +115,10 @@ bool OverlayUserPrefStore::GetMutableValue(const std::string& key, if (!persistent_user_pref_store_->GetMutableValue(key, &persistent_value)) return false; - *result = persistent_value->DeepCopy(); ephemeral_user_pref_store_->SetValue( - key, base::WrapUnique(*result), + key, persistent_value->CreateDeepCopy(), WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); + ephemeral_user_pref_store_->GetMutableValue(key, result); return true; } diff --git a/chromium/components/prefs/pref_notifier_impl.h b/chromium/components/prefs/pref_notifier_impl.h index 77dfaf42d27..c550103fbc3 100644 --- a/chromium/components/prefs/pref_notifier_impl.h +++ b/chromium/components/prefs/pref_notifier_impl.h @@ -8,10 +8,10 @@ #include <list> #include <memory> #include <string> +#include <unordered_map> #include "base/callback.h" #include "base/compiler_specific.h" -#include "base/containers/hash_tables.h" #include "base/macros.h" #include "base/observer_list.h" #include "base/threading/thread_checker.h" @@ -58,7 +58,7 @@ class COMPONENTS_PREFS_EXPORT PrefNotifierImpl : public PrefNotifier { // order they are added. These should only be accessed externally for unit // testing. typedef base::ObserverList<PrefObserver>::Unchecked PrefObserverList; - typedef base::hash_map<std::string, std::unique_ptr<PrefObserverList>> + typedef std::unordered_map<std::string, std::unique_ptr<PrefObserverList>> PrefObserverMap; typedef std::list<base::OnceCallback<void(bool)>> PrefInitObserverList; diff --git a/chromium/components/prefs/pref_registry.h b/chromium/components/prefs/pref_registry.h index c7515aa6a55..a4d08280e01 100644 --- a/chromium/components/prefs/pref_registry.h +++ b/chromium/components/prefs/pref_registry.h @@ -9,8 +9,8 @@ #include <memory> #include <set> +#include <unordered_map> -#include "base/containers/hash_tables.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "components/prefs/pref_value_map.h" @@ -54,7 +54,7 @@ class COMPONENTS_PREFS_EXPORT PrefRegistry }; typedef PrefValueMap::const_iterator const_iterator; - typedef base::hash_map<std::string, uint32_t> PrefRegistrationFlagsMap; + typedef std::unordered_map<std::string, uint32_t> PrefRegistrationFlagsMap; PrefRegistry(); diff --git a/chromium/components/prefs/pref_service.cc b/chromium/components/prefs/pref_service.cc index 47460cf2525..deb571065e7 100644 --- a/chromium/components/prefs/pref_service.cc +++ b/chromium/components/prefs/pref_service.cc @@ -567,20 +567,18 @@ base::Value* PrefService::GetMutableUserPref(const std::string& path, } // Look for an existing preference in the user store. If it doesn't - // exist or isn't the correct type, create a new user preference. + // exist, create a new user preference. base::Value* value = nullptr; - if (!user_pref_store_->GetMutableValue(path, &value) || - value->type() != type) { - if (type == base::Value::Type::DICTIONARY) { - value = new base::DictionaryValue; - } else if (type == base::Value::Type::LIST) { - value = new base::ListValue; - } else { - NOTREACHED(); - } - user_pref_store_->SetValueSilently(path, base::WrapUnique(value), - GetWriteFlags(pref)); - } + if (user_pref_store_->GetMutableValue(path, &value)) + return value; + + // If no user preference exists, clone default value. + const base::Value* default_value = nullptr; + pref_registry_->defaults()->GetValue(path, &default_value); + DCHECK_EQ(default_value->type(), type); + user_pref_store_->SetValueSilently(path, default_value->CreateDeepCopy(), + GetWriteFlags(pref)); + user_pref_store_->GetMutableValue(path, &value); return value; } diff --git a/chromium/components/prefs/pref_service.h b/chromium/components/prefs/pref_service.h index 1d7e0244adf..28e1b2b3302 100644 --- a/chromium/components/prefs/pref_service.h +++ b/chromium/components/prefs/pref_service.h @@ -16,11 +16,11 @@ #include <memory> #include <set> #include <string> +#include <unordered_map> #include <vector> #include "base/callback.h" #include "base/compiler_specific.h" -#include "base/containers/hash_tables.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" @@ -390,7 +390,7 @@ class COMPONENTS_PREFS_EXPORT PrefService { // string comparisons. Order is unimportant, and deletions are rare. // Confirmed on Android where this speeded Chrome startup by roughly 50ms // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. - typedef base::hash_map<std::string, Preference> PreferenceMap; + typedef std::unordered_map<std::string, Preference> PreferenceMap; // Give access to ReportUserPrefChanged() and GetMutableUserPref(). friend class subtle::ScopedUserPrefUpdateBase; diff --git a/chromium/components/prefs/pref_service_unittest.cc b/chromium/components/prefs/pref_service_unittest.cc index b85f47a52cf..dfc51f6dfa4 100644 --- a/chromium/components/prefs/pref_service_unittest.cc +++ b/chromium/components/prefs/pref_service_unittest.cc @@ -7,7 +7,7 @@ #include <string> -#include "base/macros.h" +#include "base/stl_util.h" #include "base/time/time.h" #include "base/values.h" #include "components/prefs/json_pref_store.h" @@ -377,7 +377,7 @@ TEST(PrefServiceTest, WriteablePrefStoreFlags) { PrefRegistry::LOSSY_PREF | kCustomRegistrationFlag, WriteablePrefStore::LOSSY_PREF_WRITE_FLAG}}; - for (size_t i = 0; i < arraysize(kRegistrationToWriteFlags); ++i) { + for (size_t i = 0; i < base::size(kRegistrationToWriteFlags); ++i) { RegistrationToWriteFlags entry = kRegistrationToWriteFlags[i]; registry->RegisterDictionaryPref(entry.pref_name, std::make_unique<base::DictionaryValue>(), diff --git a/chromium/components/prefs/pref_value_map.cc b/chromium/components/prefs/pref_value_map.cc index 3cd2d8750b7..6ff02b6d216 100644 --- a/chromium/components/prefs/pref_value_map.cc +++ b/chromium/components/prefs/pref_value_map.cc @@ -21,11 +21,10 @@ bool PrefValueMap::GetValue(const std::string& key, if (it == prefs_.end()) return false; - const base::Value* got_value = it->second.get(); - if (value && got_value) - *value = got_value; + if (value) + *value = &it->second; - return !!got_value; + return true; } bool PrefValueMap::GetValue(const std::string& key, base::Value** value) { @@ -33,19 +32,21 @@ bool PrefValueMap::GetValue(const std::string& key, base::Value** value) { if (it == prefs_.end()) return false; - base::Value* got_value = it->second.get(); - if (value && got_value) - *value = got_value; + if (value) + *value = &it->second; - return !!got_value; + return true; } bool PrefValueMap::SetValue(const std::string& key, std::unique_ptr<base::Value> value) { DCHECK(value); + return SetValue(key, base::Value::FromUniquePtrValue(std::move(value))); +} - std::unique_ptr<base::Value>& existing_value = prefs_[key]; - if (existing_value && value->Equals(existing_value.get())) +bool PrefValueMap::SetValue(const std::string& key, base::Value value) { + base::Value& existing_value = prefs_[key]; + if (value == existing_value) return false; existing_value = std::move(value); @@ -91,7 +92,7 @@ bool PrefValueMap::GetBoolean(const std::string& key, } void PrefValueMap::SetBoolean(const std::string& key, bool value) { - SetValue(key, std::make_unique<base::Value>(value)); + SetValue(key, base::Value(value)); } bool PrefValueMap::GetString(const std::string& key, @@ -102,7 +103,7 @@ bool PrefValueMap::GetString(const std::string& key, void PrefValueMap::SetString(const std::string& key, const std::string& value) { - SetValue(key, std::make_unique<base::Value>(value)); + SetValue(key, base::Value(value)); } bool PrefValueMap::GetInteger(const std::string& key, int* value) const { @@ -111,11 +112,11 @@ bool PrefValueMap::GetInteger(const std::string& key, int* value) const { } void PrefValueMap::SetInteger(const std::string& key, const int value) { - SetValue(key, std::make_unique<base::Value>(value)); + SetValue(key, base::Value(value)); } void PrefValueMap::SetDouble(const std::string& key, const double value) { - SetValue(key, std::make_unique<base::Value>(value)); + SetValue(key, base::Value(value)); } void PrefValueMap::GetDifferingKeys( @@ -124,12 +125,12 @@ void PrefValueMap::GetDifferingKeys( differing_keys->clear(); // Put everything into ordered maps. - std::map<std::string, base::Value*> this_prefs; - std::map<std::string, base::Value*> other_prefs; + std::map<std::string, const base::Value*> this_prefs; + std::map<std::string, const base::Value*> other_prefs; for (const auto& pair : prefs_) - this_prefs[pair.first] = pair.second.get(); + this_prefs.emplace(pair.first, &pair.second); for (const auto& pair : other->prefs_) - other_prefs[pair.first] = pair.second.get(); + other_prefs.emplace(pair.first, &pair.second); // Walk over the maps in lockstep, adding everything that is different. auto this_pref = this_prefs.begin(); @@ -152,15 +153,15 @@ void PrefValueMap::GetDifferingKeys( // Add the remaining entries. for ( ; this_pref != this_prefs.end(); ++this_pref) - differing_keys->push_back(this_pref->first); + differing_keys->push_back(this_pref->first); for ( ; other_pref != other_prefs.end(); ++other_pref) - differing_keys->push_back(other_pref->first); + differing_keys->push_back(other_pref->first); } std::unique_ptr<base::DictionaryValue> PrefValueMap::AsDictionaryValue() const { auto dictionary = std::make_unique<base::DictionaryValue>(); - for (const auto& value : prefs_) { - dictionary->Set(value.first, value.second->CreateDeepCopy()); - } + for (const auto& value : prefs_) + dictionary->Set(value.first, value.second.CreateDeepCopy()); + return dictionary; } diff --git a/chromium/components/prefs/pref_value_map.h b/chromium/components/prefs/pref_value_map.h index 12ffc9fbbd9..8188cb1aa85 100644 --- a/chromium/components/prefs/pref_value_map.h +++ b/chromium/components/prefs/pref_value_map.h @@ -5,9 +5,9 @@ #ifndef COMPONENTS_PREFS_PREF_VALUE_MAP_H_ #define COMPONENTS_PREFS_PREF_VALUE_MAP_H_ +#include <map> #include <memory> #include <string> -#include <unordered_map> #include <vector> #include "base/macros.h" @@ -21,7 +21,7 @@ class Value; // A generic string to value map used by the PrefStore implementations. class COMPONENTS_PREFS_EXPORT PrefValueMap { public: - using Map = std::unordered_map<std::string, std::unique_ptr<base::Value>>; + using Map = std::map<std::string, base::Value>; using iterator = Map::iterator; using const_iterator = Map::const_iterator; @@ -36,8 +36,12 @@ class COMPONENTS_PREFS_EXPORT PrefValueMap { // Sets a new |value| for |key|. |value| must be non-null. Returns true if the // value changed. + // DEPRECATED. Use |SetValue(const std::string&, base::Value)| instead. bool SetValue(const std::string& key, std::unique_ptr<base::Value> value); + // Sets a new |value| for |key|. Returns true if the value changed. + bool SetValue(const std::string& key, base::Value value); + // Removes the value for |key| from the map. Returns true if a value was // removed. bool RemoveValue(const std::string& key); diff --git a/chromium/components/prefs/scoped_user_pref_update_unittest.cc b/chromium/components/prefs/scoped_user_pref_update_unittest.cc index 437dff6fe9f..0fcfbd69f33 100644 --- a/chromium/components/prefs/scoped_user_pref_update_unittest.cc +++ b/chromium/components/prefs/scoped_user_pref_update_unittest.cc @@ -79,3 +79,31 @@ TEST_F(ScopedUserPrefUpdateTest, NeverTouchAnything) { EXPECT_EQ(old_value, new_value); Mock::VerifyAndClearExpectations(&observer_); } + +TEST_F(ScopedUserPrefUpdateTest, UpdatingListPrefWithDefaults) { + auto defaults = std::make_unique<base::ListValue>(); + defaults->GetList().emplace_back("firstvalue"); + defaults->GetList().emplace_back("secondvalue"); + + std::string pref_name = "mypref"; + prefs_.registry()->RegisterListPref(pref_name, std::move(defaults)); + EXPECT_EQ(2u, prefs_.GetList(pref_name)->GetList().size()); + + ListPrefUpdate update(&prefs_, pref_name); + update->AppendString("thirdvalue"); + EXPECT_EQ(3u, prefs_.GetList(pref_name)->GetList().size()); +} + +TEST_F(ScopedUserPrefUpdateTest, UpdatingDictionaryPrefWithDefaults) { + auto defaults = std::make_unique<base::DictionaryValue>(); + defaults->SetKey("firstkey", base::Value("value")); + defaults->SetKey("secondkey", base::Value("value")); + + std::string pref_name = "mypref"; + prefs_.registry()->RegisterDictionaryPref(pref_name, std::move(defaults)); + EXPECT_EQ(2u, prefs_.GetDictionary(pref_name)->size()); + + DictionaryPrefUpdate update(&prefs_, pref_name); + update->SetKey("thirdkey", base::Value("value")); + EXPECT_EQ(3u, prefs_.GetDictionary(pref_name)->size()); +} diff --git a/chromium/components/prefs/testing_pref_store.cc b/chromium/components/prefs/testing_pref_store.cc index 94b86eeb38c..16257da8d8b 100644 --- a/chromium/components/prefs/testing_pref_store.cc +++ b/chromium/components/prefs/testing_pref_store.cc @@ -203,9 +203,8 @@ void TestingPrefStore::set_read_error( } TestingPrefStore::~TestingPrefStore() { - for (auto& pref : prefs_) { - CheckPrefIsSerializable(pref.first, *pref.second); - } + for (auto& pref : prefs_) + CheckPrefIsSerializable(pref.first, pref.second); } void TestingPrefStore::CheckPrefIsSerializable(const std::string& key, |