summaryrefslogtreecommitdiff
path: root/chromium/components/prefs
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-03-08 10:28:10 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-03-20 13:40:30 +0000
commite733310db58160074f574c429d48f8308c0afe17 (patch)
treef8aef4b7e62a69928dbcf880620eece20f98c6df /chromium/components/prefs
parent2f583e4aec1ae3a86fa047829c96b310dc12ecdf (diff)
downloadqtwebengine-chromium-e733310db58160074f574c429d48f8308c0afe17.tar.gz
BASELINE: Update Chromium to 56.0.2924.122
Change-Id: I4e04de8f47e47e501c46ed934c76a431c6337ced Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/prefs')
-rw-r--r--chromium/components/prefs/BUILD.gn2
-rw-r--r--chromium/components/prefs/command_line_pref_store.cc80
-rw-r--r--chromium/components/prefs/command_line_pref_store.h66
-rw-r--r--chromium/components/prefs/default_pref_store.cc6
-rw-r--r--chromium/components/prefs/in_memory_pref_store.cc3
-rw-r--r--chromium/components/prefs/json_pref_store.cc13
-rw-r--r--chromium/components/prefs/overlay_user_pref_store.cc7
-rw-r--r--chromium/components/prefs/pref_notifier_impl.cc9
-rw-r--r--chromium/components/prefs/pref_notifier_impl_unittest.cc7
-rw-r--r--chromium/components/prefs/testing_pref_store.cc10
-rw-r--r--chromium/components/prefs/value_map_pref_store.cc18
11 files changed, 187 insertions, 34 deletions
diff --git a/chromium/components/prefs/BUILD.gn b/chromium/components/prefs/BUILD.gn
index ff4e1f2cb83..b2eb8535845 100644
--- a/chromium/components/prefs/BUILD.gn
+++ b/chromium/components/prefs/BUILD.gn
@@ -4,6 +4,8 @@
component("prefs") {
sources = [
+ "command_line_pref_store.cc",
+ "command_line_pref_store.h",
"default_pref_store.cc",
"default_pref_store.h",
"in_memory_pref_store.cc",
diff --git a/chromium/components/prefs/command_line_pref_store.cc b/chromium/components/prefs/command_line_pref_store.cc
new file mode 100644
index 00000000000..f8a503e5441
--- /dev/null
+++ b/chromium/components/prefs/command_line_pref_store.cc
@@ -0,0 +1,80 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/prefs/command_line_pref_store.h"
+
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/string_number_conversions.h"
+
+CommandLinePrefStore::CommandLinePrefStore(
+ const base::CommandLine* command_line)
+ : command_line_(command_line) {}
+
+CommandLinePrefStore::~CommandLinePrefStore() {}
+
+void CommandLinePrefStore::ApplyStringSwitches(
+ const CommandLinePrefStore::SwitchToPreferenceMapEntry string_switch[],
+ size_t size) {
+ for (size_t i = 0; i < size; ++i) {
+ if (command_line_->HasSwitch(string_switch[i].switch_name)) {
+ SetValue(string_switch[i].preference_path,
+ base::MakeUnique<base::StringValue>(
+ command_line_->GetSwitchValueASCII(
+ string_switch[i].switch_name)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ }
+ }
+}
+
+void CommandLinePrefStore::ApplyPathSwitches(
+ const CommandLinePrefStore::SwitchToPreferenceMapEntry path_switch[],
+ size_t size) {
+ for (size_t i = 0; i < size; ++i) {
+ if (command_line_->HasSwitch(path_switch[i].switch_name)) {
+ SetValue(
+ path_switch[i].preference_path,
+ base::MakeUnique<base::StringValue>(
+ command_line_->GetSwitchValuePath(path_switch[i].switch_name)
+ .value()),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ }
+ }
+}
+
+void CommandLinePrefStore::ApplyIntegerSwitches(
+ const CommandLinePrefStore::SwitchToPreferenceMapEntry integer_switch[],
+ size_t size) {
+ for (size_t i = 0; i < size; ++i) {
+ if (command_line_->HasSwitch(integer_switch[i].switch_name)) {
+ std::string str_value = command_line_->GetSwitchValueASCII(
+ integer_switch[i].switch_name);
+ int int_value = 0;
+ if (!base::StringToInt(str_value, &int_value)) {
+ LOG(ERROR) << "The value " << str_value << " of "
+ << integer_switch[i].switch_name
+ << " can not be converted to integer, ignoring!";
+ continue;
+ }
+ SetValue(integer_switch[i].preference_path,
+ base::MakeUnique<base::FundamentalValue>(int_value),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ }
+ }
+}
+
+void CommandLinePrefStore::ApplyBooleanSwitches(
+ const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
+ boolean_switch_map[], size_t size) {
+ for (size_t i = 0; i < size; ++i) {
+ if (command_line_->HasSwitch(boolean_switch_map[i].switch_name)) {
+ SetValue(boolean_switch_map[i].preference_path,
+ base::MakeUnique<base::FundamentalValue>(
+ boolean_switch_map[i].set_value),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ }
+ }
+}
diff --git a/chromium/components/prefs/command_line_pref_store.h b/chromium/components/prefs/command_line_pref_store.h
new file mode 100644
index 00000000000..03d5da96958
--- /dev/null
+++ b/chromium/components/prefs/command_line_pref_store.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
+#define COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "base/values.h"
+#include "components/prefs/value_map_pref_store.h"
+
+// Base class for a PrefStore that maps command line switches to preferences.
+// The Apply...Switches() methods can be called by subclasses with their own
+// maps, or delegated to other code.
+class COMPONENTS_PREFS_EXPORT CommandLinePrefStore : public ValueMapPrefStore {
+ public:
+ struct SwitchToPreferenceMapEntry {
+ const char* switch_name;
+ const char* preference_path;
+ };
+
+ // |set_value| indicates what the preference should be set to if the switch
+ // is present.
+ struct BooleanSwitchToPreferenceMapEntry {
+ const char* switch_name;
+ const char* preference_path;
+ bool set_value;
+ };
+
+ // Apply command-line switches to the corresponding preferences of the switch
+ // map, where the value associated with the switch is a string.
+ void ApplyStringSwitches(
+ const SwitchToPreferenceMapEntry string_switch_map[], size_t size);
+
+ // Apply command-line switches to the corresponding preferences of the switch
+ // map, where the value associated with the switch is a path.
+ void ApplyPathSwitches(const SwitchToPreferenceMapEntry path_switch_map[],
+ size_t size);
+
+ // Apply command-line switches to the corresponding preferences of the switch
+ // map, where the value associated with the switch is an integer.
+ void ApplyIntegerSwitches(
+ const SwitchToPreferenceMapEntry integer_switch_map[], size_t size);
+
+ // Apply command-line switches to the corresponding preferences of the
+ // boolean switch map.
+ void ApplyBooleanSwitches(
+ const BooleanSwitchToPreferenceMapEntry boolean_switch_map[],
+ size_t size);
+
+
+ protected:
+ explicit CommandLinePrefStore(const base::CommandLine* command_line);
+ ~CommandLinePrefStore() override;
+
+ const base::CommandLine* command_line() { return command_line_; }
+
+ private:
+ // Weak reference.
+ const base::CommandLine* command_line_;
+
+ DISALLOW_COPY_AND_ASSIGN(CommandLinePrefStore);
+};
+
+#endif // COMPONENTS_PREFS_COMMAND_LINE_PREF_STORE_H_
diff --git a/chromium/components/prefs/default_pref_store.cc b/chromium/components/prefs/default_pref_store.cc
index ed401899c87..468c11c7483 100644
--- a/chromium/components/prefs/default_pref_store.cc
+++ b/chromium/components/prefs/default_pref_store.cc
@@ -41,8 +41,10 @@ void DefaultPrefStore::ReplaceDefaultValue(const std::string& key,
GetValue(key, &old_value);
bool notify = !old_value->Equals(value.get());
prefs_.SetValue(key, std::move(value));
- if (notify)
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ if (notify) {
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
+ }
}
DefaultPrefStore::const_iterator DefaultPrefStore::begin() const {
diff --git a/chromium/components/prefs/in_memory_pref_store.cc b/chromium/components/prefs/in_memory_pref_store.cc
index c222a3680ac..d0d35582523 100644
--- a/chromium/components/prefs/in_memory_pref_store.cc
+++ b/chromium/components/prefs/in_memory_pref_store.cc
@@ -72,5 +72,6 @@ PersistentPrefStore::PrefReadError InMemoryPrefStore::ReadPrefs() {
void InMemoryPrefStore::ReportValueChanged(const std::string& key,
uint32_t flags) {
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
}
diff --git a/chromium/components/prefs/json_pref_store.cc b/chromium/components/prefs/json_pref_store.cc
index 811d2be0787..4076433dbb8 100644
--- a/chromium/components/prefs/json_pref_store.cc
+++ b/chromium/components/prefs/json_pref_store.cc
@@ -320,7 +320,8 @@ void JsonPrefStore::ReportValueChanged(const std::string& key, uint32_t flags) {
if (pref_filter_)
pref_filter_->FilterUpdate(key);
- FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+ for (PrefStore::Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
ScheduleWrite(flags);
}
@@ -488,9 +489,8 @@ void JsonPrefStore::FinalizeFileRead(
filtering_in_progress_ = false;
if (!initialization_successful) {
- FOR_EACH_OBSERVER(PrefStore::Observer,
- observers_,
- OnInitializationCompleted(false));
+ for (PrefStore::Observer& observer : observers_)
+ observer.OnInitializationCompleted(false);
return;
}
@@ -504,9 +504,8 @@ void JsonPrefStore::FinalizeFileRead(
if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE)
error_delegate_->OnError(read_error_);
- FOR_EACH_OBSERVER(PrefStore::Observer,
- observers_,
- OnInitializationCompleted(true));
+ for (PrefStore::Observer& observer : observers_)
+ observer.OnInitializationCompleted(true);
return;
}
diff --git a/chromium/components/prefs/overlay_user_pref_store.cc b/chromium/components/prefs/overlay_user_pref_store.cc
index 125dece15f8..2b2208ed821 100644
--- a/chromium/components/prefs/overlay_user_pref_store.cc
+++ b/chromium/components/prefs/overlay_user_pref_store.cc
@@ -130,7 +130,8 @@ void OverlayUserPrefStore::SchedulePendingLossyWrites() {
void OverlayUserPrefStore::ReportValueChanged(const std::string& key,
uint32_t flags) {
- FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+ for (PrefStore::Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
}
void OverlayUserPrefStore::OnPrefValueChanged(const std::string& key) {
@@ -139,8 +140,8 @@ void OverlayUserPrefStore::OnPrefValueChanged(const std::string& key) {
}
void OverlayUserPrefStore::OnInitializationCompleted(bool succeeded) {
- FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
- OnInitializationCompleted(succeeded));
+ for (PrefStore::Observer& observer : observers_)
+ observer.OnInitializationCompleted(succeeded);
}
void OverlayUserPrefStore::RegisterOverlayPref(const std::string& key) {
diff --git a/chromium/components/prefs/pref_notifier_impl.cc b/chromium/components/prefs/pref_notifier_impl.cc
index 48dd57c22d2..a28fbaffad9 100644
--- a/chromium/components/prefs/pref_notifier_impl.cc
+++ b/chromium/components/prefs/pref_notifier_impl.cc
@@ -19,10 +19,8 @@ PrefNotifierImpl::~PrefNotifierImpl() {
// Verify that there are no pref observers when we shut down.
for (const auto& observer_list : pref_observers_) {
- PrefObserverList::Iterator obs_iterator(observer_list.second.get());
- if (obs_iterator.GetNext()) {
+ if (observer_list.second->begin() != observer_list.second->end())
LOG(WARNING) << "Pref observer found at shutdown.";
- }
}
// Same for initialization observers.
@@ -95,9 +93,8 @@ void PrefNotifierImpl::FireObservers(const std::string& path) {
if (observer_iterator == pref_observers_.end())
return;
- FOR_EACH_OBSERVER(PrefObserver,
- *(observer_iterator->second),
- OnPreferenceChanged(pref_service_, path));
+ for (PrefObserver& observer : *(observer_iterator->second))
+ observer.OnPreferenceChanged(pref_service_, path);
}
void PrefNotifierImpl::SetPrefService(PrefService* pref_service) {
diff --git a/chromium/components/prefs/pref_notifier_impl_unittest.cc b/chromium/components/prefs/pref_notifier_impl_unittest.cc
index 517a403936a..06ab053045c 100644
--- a/chromium/components/prefs/pref_notifier_impl_unittest.cc
+++ b/chromium/components/prefs/pref_notifier_impl_unittest.cc
@@ -59,12 +59,9 @@ class MockPrefNotifier : public PrefNotifierImpl {
if (observer_iterator == pref_observers()->end())
return false;
- PrefObserverList* observer_list = observer_iterator->second.get();
- PrefObserverList::Iterator it(observer_list);
- PrefObserver* existing_obs;
size_t count = 0;
- while ((existing_obs = it.GetNext()) != NULL) {
- if (existing_obs == obs)
+ for (auto& existing_obs : *observer_iterator->second) {
+ if (&existing_obs == obs)
count++;
}
diff --git a/chromium/components/prefs/testing_pref_store.cc b/chromium/components/prefs/testing_pref_store.cc
index 2060c9fdcec..1e775824a6a 100644
--- a/chromium/components/prefs/testing_pref_store.cc
+++ b/chromium/components/prefs/testing_pref_store.cc
@@ -99,7 +99,8 @@ void TestingPrefStore::SetInitializationCompleted() {
}
void TestingPrefStore::NotifyPrefValueChanged(const std::string& key) {
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
}
void TestingPrefStore::NotifyInitializationCompleted() {
@@ -107,13 +108,14 @@ void TestingPrefStore::NotifyInitializationCompleted() {
init_complete_ = true;
if (read_success_ && read_error_ != PREF_READ_ERROR_NONE && error_delegate_)
error_delegate_->OnError(read_error_);
- FOR_EACH_OBSERVER(
- Observer, observers_, OnInitializationCompleted(read_success_));
+ for (Observer& observer : observers_)
+ observer.OnInitializationCompleted(read_success_);
}
void TestingPrefStore::ReportValueChanged(const std::string& key,
uint32_t flags) {
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
}
void TestingPrefStore::SetString(const std::string& key,
diff --git a/chromium/components/prefs/value_map_pref_store.cc b/chromium/components/prefs/value_map_pref_store.cc
index 15a0eb1e92b..8b828b10d5c 100644
--- a/chromium/components/prefs/value_map_pref_store.cc
+++ b/chromium/components/prefs/value_map_pref_store.cc
@@ -32,13 +32,17 @@ bool ValueMapPrefStore::HasObservers() const {
void ValueMapPrefStore::SetValue(const std::string& key,
std::unique_ptr<base::Value> value,
uint32_t flags) {
- if (prefs_.SetValue(key, std::move(value)))
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ if (prefs_.SetValue(key, std::move(value))) {
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
+ }
}
void ValueMapPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
- if (prefs_.RemoveValue(key))
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ if (prefs_.RemoveValue(key)) {
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
+ }
}
bool ValueMapPrefStore::GetMutableValue(const std::string& key,
@@ -48,7 +52,8 @@ bool ValueMapPrefStore::GetMutableValue(const std::string& key,
void ValueMapPrefStore::ReportValueChanged(const std::string& key,
uint32_t flags) {
- FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
+ for (Observer& observer : observers_)
+ observer.OnPrefValueChanged(key);
}
void ValueMapPrefStore::SetValueSilently(const std::string& key,
@@ -60,5 +65,6 @@ void ValueMapPrefStore::SetValueSilently(const std::string& key,
ValueMapPrefStore::~ValueMapPrefStore() {}
void ValueMapPrefStore::NotifyInitializationCompleted() {
- FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted(true));
+ for (Observer& observer : observers_)
+ observer.OnInitializationCompleted(true);
}