summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 13:24:14 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 13:24:14 +0000
commitebd0b02ef588eb4ceb22408c168c505963e97b3f (patch)
treed6ddd6775ea2db8fa5d63f00df0c242d26459b2a /chrome
parenta2b29cf00c95ede914797263bb3914dc52dd8621 (diff)
downloadchromium_src-ebd0b02ef588eb4ceb22408c168c505963e97b3f.zip
chromium_src-ebd0b02ef588eb4ceb22408c168c505963e97b3f.tar.gz
chromium_src-ebd0b02ef588eb4ceb22408c168c505963e97b3f.tar.bz2
Fix broken PrefService::preference_set() returning not all registered preferences.
This CL allows somebody to ask the PrefService for the effective preference values. BUG=70809 TEST=prefs.PrefsTest.testUnderTheHoodPref and prefs.PrefsTest.testHomepagePrefs of chrome/test/functional/prefs.py will work again. Review URL: http://codereview.chromium.org/6353015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc9
-rw-r--r--chrome/browser/prefs/pref_service.cc11
-rw-r--r--chrome/browser/prefs/pref_service.h19
-rw-r--r--chrome/browser/prefs/value_map_pref_store.cc16
-rw-r--r--chrome/browser/prefs/value_map_pref_store.h12
-rw-r--r--chrome/test/functional/PYAUTO_TESTS3
6 files changed, 49 insertions, 21 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 0f4bdc5..088a23a 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -2786,13 +2786,8 @@ void TestingAutomationProvider::PerformActionOnSearchEngine(
void TestingAutomationProvider::GetPrefsInfo(Browser* browser,
DictionaryValue* args,
IPC::Message* reply_message) {
- const PrefService::PreferenceSet& prefs =
- profile_->GetPrefs()->preference_set();
- DictionaryValue* items = new DictionaryValue;
- for (PrefService::PreferenceSet::const_iterator it = prefs.begin();
- it != prefs.end(); ++it) {
- items->Set((*it)->name(), (*it)->GetValue()->DeepCopy());
- }
+ DictionaryValue* items = profile_->GetPrefs()->GetPreferenceValues();
+
scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
return_value->Set("prefs", items); // return_value owns items.
AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index 2ab04f8..9447875 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -356,6 +356,17 @@ bool PrefService::HasPrefPath(const char* path) const {
return pref && !pref->IsDefaultValue();
}
+DictionaryValue* PrefService::GetPreferenceValues() const {
+ DCHECK(CalledOnValidThread());
+ DictionaryValue* out = new DictionaryValue;
+ DefaultPrefStore::const_iterator i = default_store_->begin();
+ for (; i != default_store_->end(); ++i) {
+ const Value* value = FindPreference(i->first.c_str())->GetValue();
+ out->Set(i->first, value->DeepCopy());
+ }
+ return out;
+}
+
const PrefService::Preference* PrefService::FindPreference(
const char* pref_name) const {
DCHECK(CalledOnValidThread());
diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h
index 24b08d2..d05a1da 100644
--- a/chrome/browser/prefs/pref_service.h
+++ b/chrome/browser/prefs/pref_service.h
@@ -211,14 +211,9 @@ class PrefService : public base::NonThreadSafe {
// this checks if a value exists for the path.
bool HasPrefPath(const char* path) const;
- class PreferencePathComparator {
- public:
- bool operator() (Preference* lhs, Preference* rhs) const {
- return lhs->name() < rhs->name();
- }
- };
- typedef std::set<Preference*, PreferencePathComparator> PreferenceSet;
- const PreferenceSet& preference_set() const { return prefs_; }
+ // Returns a dictionary with effective preference values. The ownership
+ // is passed to the caller.
+ DictionaryValue* GetPreferenceValues() const;
// A helper method to quickly look up a preference. Returns NULL if the
// preference is not registered.
@@ -248,6 +243,14 @@ class PrefService : public base::NonThreadSafe {
scoped_ptr<PrefNotifierImpl> pref_notifier_;
private:
+ class PreferencePathComparator {
+ public:
+ bool operator() (Preference* lhs, Preference* rhs) const {
+ return lhs->name() < rhs->name();
+ }
+ };
+ typedef std::set<Preference*, PreferencePathComparator> PreferenceSet;
+
friend class PrefServiceMockBuilder;
// Registration of pref change observers must be done using the
diff --git a/chrome/browser/prefs/value_map_pref_store.cc b/chrome/browser/prefs/value_map_pref_store.cc
index 705c958..58c4016 100644
--- a/chrome/browser/prefs/value_map_pref_store.cc
+++ b/chrome/browser/prefs/value_map_pref_store.cc
@@ -39,3 +39,19 @@ void ValueMapPrefStore::RemoveValue(const std::string& key) {
void ValueMapPrefStore::NotifyInitializationCompleted() {
FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted());
}
+
+ValueMapPrefStore::iterator ValueMapPrefStore::begin() {
+ return prefs_.begin();
+}
+
+ValueMapPrefStore::iterator ValueMapPrefStore::end() {
+ return prefs_.end();
+}
+
+ValueMapPrefStore::const_iterator ValueMapPrefStore::begin() const {
+ return prefs_.begin();
+}
+
+ValueMapPrefStore::const_iterator ValueMapPrefStore::end() const {
+ return prefs_.end();
+}
diff --git a/chrome/browser/prefs/value_map_pref_store.h b/chrome/browser/prefs/value_map_pref_store.h
index 20bf2902..a8b66c4 100644
--- a/chrome/browser/prefs/value_map_pref_store.h
+++ b/chrome/browser/prefs/value_map_pref_store.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -6,8 +6,6 @@
#define CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_
#pragma once
-#include <map>
-
#include "base/basictypes.h"
#include "base/observer_list.h"
#include "chrome/browser/prefs/pref_value_map.h"
@@ -17,6 +15,9 @@
// storing the preference values.
class ValueMapPrefStore : public PrefStore {
public:
+ typedef std::map<std::string, Value*>::iterator iterator;
+ typedef std::map<std::string, Value*>::const_iterator const_iterator;
+
ValueMapPrefStore();
virtual ~ValueMapPrefStore();
@@ -25,6 +26,11 @@ class ValueMapPrefStore : public PrefStore {
virtual void AddObserver(PrefStore::Observer* observer);
virtual void RemoveObserver(PrefStore::Observer* observer);
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+
protected:
// Store a |value| for |key| in the store. Also generates an notification if
// the value changed. Assumes ownership of |value|, which must be non-NULL.
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS
index 8341d3b..d12868e 100644
--- a/chrome/test/functional/PYAUTO_TESTS
+++ b/chrome/test/functional/PYAUTO_TESTS
@@ -67,9 +67,6 @@
'popups',
'-popups', # Flaky. crbug.com/70659
'prefs',
- # Some pref tests broken by r72489. crbug.com/70809
- '-prefs.PrefsTest.testUnderTheHoodPref',
- '-prefs.PrefsTest.testHomepagePrefs',
'search_engines',
# crbug.com/67628
'-search_engines.SearchEnginesTest.testTabToSearch',