summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-23 12:39:01 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-23 12:39:01 +0000
commitf00768e58f44e2343b1ed6c0456a07dad5ec66ed (patch)
tree16d9a46fc3076e44d4342a6e0f0643bff3b18f28 /base
parent7fd3fd82e83460bdc85da8ee4dd5ad06ce8426db (diff)
downloadchromium_src-f00768e58f44e2343b1ed6c0456a07dad5ec66ed.zip
chromium_src-f00768e58f44e2343b1ed6c0456a07dad5ec66ed.tar.gz
chromium_src-f00768e58f44e2343b1ed6c0456a07dad5ec66ed.tar.bz2
Handle policy refresh internally in ConfigurationPolicyPrefStore.
This removes the final bits of thread-switching madness from PrefValueStore and also makes sure only the PrefStores and PrefService instances that are actually affected by a policy change get reconfigured. BUG=67715 TEST=unit tests in configuration_policy_provider_unittest.cc Review URL: http://codereview.chromium.org/6074003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/values.cc108
-rw-r--r--base/values.h21
-rw-r--r--base/values_unittest.cc133
3 files changed, 1 insertions, 261 deletions
diff --git a/base/values.cc b/base/values.cc
index b06df12..4553e68 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -685,114 +685,6 @@ void DictionaryValue::MergeDictionary(const DictionaryValue* dictionary) {
}
}
-bool DictionaryValue::GetDifferingPathsHelper(
- const std::string& path_prefix,
- const DictionaryValue* other,
- std::vector<std::string>* different_paths) const {
- bool added_path = false;
- std::map<std::string, Value*>::const_iterator current_this;
- std::map<std::string, Value*>::const_iterator end_this;
- current_this = dictionary_.begin();
- end_this = dictionary_.end();
- if (!other) {
- // Recursively add all paths from the |this| dictionary, since they are
- // not in |other|.
- for (; current_this != end_this; ++current_this) {
- std::string full_path_for_key(path_prefix.empty() ? current_this->first :
- path_prefix + "." + current_this->first);
- different_paths->push_back(full_path_for_key);
- added_path = true;
- if (current_this->second->IsType(Value::TYPE_DICTIONARY)) {
- const DictionaryValue* dictionary_this =
- static_cast<const DictionaryValue*>(current_this->second);
- dictionary_this->GetDifferingPathsHelper(full_path_for_key,
- NULL,
- different_paths);
- }
- }
- } else {
- // Both the |this| and |other| dictionaries have entries. Iterate over
- // both simultaneously. Paths that are in one but not the other are
- // added to |different_paths| and DictionaryValues are processed
- // recursively.
- std::map<std::string, Value*>::const_iterator current_other =
- other->dictionary_.begin();
- std::map<std::string, Value*>::const_iterator end_other =
- other->dictionary_.end();
- while (current_this != end_this || current_other != end_other) {
- const Value* recursion_this = NULL;
- const Value* recursion_other = NULL;
- const std::string* key_name = NULL;
- bool current_value_known_equal = false;
- if (current_this == end_this ||
- (current_other != end_other &&
- (current_other->first < current_this->first))) {
- key_name = &current_other->first;
- if (current_other->second->IsType(Value::TYPE_DICTIONARY))
- recursion_this = current_other->second;
- ++current_other;
- } else {
- key_name = &current_this->first;
- if (current_other == end_other ||
- current_this->first < current_other->first) {
- if (current_this->second->IsType(Value::TYPE_DICTIONARY))
- recursion_this = current_this->second;
- ++current_this;
- } else {
- DCHECK(current_this->first == current_other->first);
- if (current_this->second->IsType(Value::TYPE_DICTIONARY)) {
- recursion_this = current_this->second;
- if (current_other->second->IsType(Value::TYPE_DICTIONARY)) {
- recursion_other = current_other->second;
- }
- } else {
- if (current_other->second->IsType(Value::TYPE_DICTIONARY)) {
- recursion_this = current_other->second;
- } else {
- current_value_known_equal =
- current_this->second->Equals(current_other->second);
- }
- }
- ++current_this;
- ++current_other;
- }
- }
- const std::string& full_path_for_key(path_prefix.empty() ?
- *key_name : path_prefix + "." + *key_name);
- if (!current_value_known_equal)
- different_paths->push_back(full_path_for_key);
- if (recursion_this) {
- const DictionaryValue* dictionary_this =
- static_cast<const DictionaryValue*>(recursion_this);
- bool subtree_changed = dictionary_this->GetDifferingPathsHelper(
- full_path_for_key,
- static_cast<const DictionaryValue*>(recursion_other),
- different_paths);
- if (subtree_changed) {
- added_path = true;
- } else {
- // In order to maintain lexicographical sorting order, directory
- // paths are pushed "optimistically" assuming that their subtree will
- // contain differences. If in retrospect there were no differences
- // in the subtree, the assumption was false and the dictionary path
- // must be removed.
- different_paths->pop_back();
- }
- } else {
- added_path |= !current_value_known_equal;
- }
- }
- }
- return added_path;
-}
-
-void DictionaryValue::GetDifferingPaths(
- const DictionaryValue* other,
- std::vector<std::string>* different_paths) const {
- different_paths->clear();
- GetDifferingPathsHelper("", other, different_paths);
-}
-
///////////////////// ListValue ////////////////////
ListValue::ListValue() : Value(TYPE_LIST) {
diff --git a/base/values.h b/base/values.h
index 68b8f00..2719d27 100644
--- a/base/values.h
+++ b/base/values.h
@@ -308,16 +308,6 @@ class DictionaryValue : public Value {
// replaced.
void MergeDictionary(const DictionaryValue* dictionary);
- // Builds a vector containing all of the paths that are different between
- // the dictionary and a second specified dictionary. These are paths of
- // values that are either in one dictionary or the other but not both, OR
- // paths that are present in both dictionaries but differ in value.
- // Path strings are in ascending lexicographical order in the generated
- // vector. |different_paths| is cleared before added any paths.
- void GetDifferingPaths(
- const DictionaryValue* other,
- std::vector<std::string>* different_paths) const;
-
// This class provides an iterator for the keys in the dictionary.
// It can't be used to modify the dictionary.
//
@@ -344,17 +334,6 @@ class DictionaryValue : public Value {
key_iterator end_keys() const { return key_iterator(dictionary_.end()); }
private:
- // Does the actual heavy lifting for GetDifferingPaths.
- // Returns true if a path is added to different_paths, otherwise false.
- // The difference compuation is calculated recursively. The keys for
- // dictionaries that are handled by recursive calls more shallow than
- // the current one are concatenated and passed through to deeper calls in
- // |path_prefix|.
- bool GetDifferingPathsHelper(
- const std::string& path_prefix,
- const DictionaryValue* other,
- std::vector<std::string>* different_paths) const;
-
ValueMap dictionary_;
DISALLOW_COPY_AND_ASSIGN(DictionaryValue);
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index 13f0f19..adcd07e 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -10,27 +10,7 @@
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
-class ValuesTest: public testing::Test {
- protected:
- void CompareDictionariesAndCheckResult(
- const DictionaryValue* dict1,
- const DictionaryValue* dict2,
- const char* expected_paths[],
- size_t expected_paths_count) {
- std::vector<std::string> differing_paths;
- std::vector<std::string> expected_paths_vector(expected_paths,
- expected_paths+expected_paths_count);
- // All comparisons should be commutative, check dict1 against dict2
- // and vice-versa.
- dict1->GetDifferingPaths(dict2, &differing_paths);
- ASSERT_EQ(expected_paths_count, differing_paths.size());
- EXPECT_TRUE(equal(differing_paths.begin(), differing_paths.end(),
- expected_paths_vector.begin()));
- dict2->GetDifferingPaths(dict1, &differing_paths);
- ASSERT_EQ(expected_paths_count, differing_paths.size());
- EXPECT_TRUE(equal(differing_paths.begin(), differing_paths.end(),
- expected_paths_vector.begin()));
- }
+class ValuesTest : public testing::Test {
};
TEST_F(ValuesTest, Basic) {
@@ -650,114 +630,3 @@ TEST_F(ValuesTest, MergeDictionary) {
EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value));
EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
}
-
-TEST_F(ValuesTest, GetDifferingPaths) {
- scoped_ptr<DictionaryValue> dict1(new DictionaryValue());
- scoped_ptr<DictionaryValue> dict2(new DictionaryValue());
- std::vector<std::string> differing_paths;
-
- // Test comparing empty dictionaries.
- dict1->GetDifferingPaths(dict2.get(), &differing_paths);
- EXPECT_EQ(differing_paths.size(), 0UL);
-
- // Compare an empty dictionary with various non-empty dictionaries.
- static const char* expected_paths1[] = {
- "segment1"
- };
- dict1->SetString("segment1", "value1");
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths1,
- arraysize(expected_paths1));
-
- static const char* expected_paths2[] = {
- "segment1",
- "segment2",
- "segment2.segment3"
- };
- dict1->SetString("segment2.segment3", "value2");
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths2,
- arraysize(expected_paths2));
-
- static const char* expected_paths3[] = {
- "segment1",
- "segment2",
- "segment2.segment3",
- "segment4",
- "segment4.segment5"
- };
- dict1->SetString("segment4.segment5", "value3");
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths3,
- arraysize(expected_paths3));
-
- // Now various tests with two populated dictionaries.
- static const char* expected_paths4[] = {
- "segment1",
- "segment2",
- "segment2.segment3",
- "segment4",
- "segment4.segment5"
- };
- dict2->Set("segment2", new DictionaryValue());
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths4,
- arraysize(expected_paths4));
-
- static const char* expected_paths5[] = {
- "segment1",
- "segment4",
- "segment4.segment5"
- };
- dict2->SetString("segment2.segment3", "value2");
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths5,
- arraysize(expected_paths5));
-
- dict2->SetBoolean("segment2.segment3", true);
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths4,
- arraysize(expected_paths4));
-
- // Test two identical dictionaries.
- dict2.reset(static_cast<DictionaryValue*>(dict1->DeepCopy()));
- dict2->GetDifferingPaths(dict1.get(), &differing_paths);
- EXPECT_EQ(differing_paths.size(), 0UL);
-
- // Test a deep dictionary structure.
- static const char* expected_paths6[] = {
- "s1",
- "s1.s2",
- "s1.s2.s3",
- "s1.s2.s3.s4",
- "s1.s2.s3.s4.s5"
- };
- dict1.reset(new DictionaryValue());
- dict2.reset(new DictionaryValue());
- dict1->Set("s1.s2.s3.s4.s5", new DictionaryValue());
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths6,
- arraysize(expected_paths6));
-
- // Make sure disjoint dictionaries generate the right differing path list.
- static const char* expected_paths7[] = {
- "a",
- "b",
- "c",
- "d"
- };
- dict1.reset(new DictionaryValue());
- dict1->SetBoolean("a", true);
- dict1->SetBoolean("c", true);
- dict2.reset(new DictionaryValue());
- dict1->SetBoolean("b", true);
- dict1->SetBoolean("d", true);
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths7,
- arraysize(expected_paths7));
-
- // For code coverage completeness. Make sure that all branches
- // that were not covered are executed.
- static const char* expected_paths8[] = {
- "s1",
- "s1.s2"
- };
- dict1.reset(new DictionaryValue());
- dict1->Set("s1.s2", new DictionaryValue());
- dict2.reset(new DictionaryValue());
- dict2->SetInteger("s1", 1);
- CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths8,
- arraysize(expected_paths8));
-}