blob: 81d04e8d077cd2577588346d5e9b6012bf5f95d2 [file] [log] [blame]
[email protected]74379bc52010-07-21 13:54:081// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/test/testing_pref_service.h"
6
7#include "chrome/browser/dummy_pref_store.h"
8#include "chrome/browser/pref_value_store.h"
9
[email protected]fa26b3d52010-08-06 08:51:5010TestingPrefService::TestingPrefValueStore::TestingPrefValueStore(
11 PrefStore* managed_prefs,
12 PrefStore* extension_prefs,
13 PrefStore* command_line_prefs,
14 PrefStore* user_prefs,
15 PrefStore* recommended_prefs)
16 : PrefValueStore(managed_prefs, extension_prefs, command_line_prefs,
17 user_prefs, recommended_prefs) {
18}
19
20// TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify
21// which they want, and expand usage of this class to more unit tests.
[email protected]74379bc52010-07-21 13:54:0822TestingPrefService::TestingPrefService()
[email protected]fa26b3d52010-08-06 08:51:5023 : PrefService(new TestingPrefValueStore(
[email protected]74379bc52010-07-21 13:54:0824 managed_prefs_ = new DummyPrefStore(),
25 NULL,
26 NULL,
27 user_prefs_ = new DummyPrefStore(),
28 NULL)) {
29}
30
[email protected]57ecc4b2010-08-11 03:02:5131const Value* TestingPrefService::GetManagedPref(const char* path) {
[email protected]74379bc52010-07-21 13:54:0832 return GetPref(managed_prefs_, path);
33}
34
[email protected]57ecc4b2010-08-11 03:02:5135void TestingPrefService::SetManagedPref(const char* path, Value* value) {
[email protected]74379bc52010-07-21 13:54:0836 SetPref(managed_prefs_, path, value);
37}
38
[email protected]57ecc4b2010-08-11 03:02:5139void TestingPrefService::RemoveManagedPref(const char* path) {
[email protected]74379bc52010-07-21 13:54:0840 RemovePref(managed_prefs_, path);
41}
42
[email protected]57ecc4b2010-08-11 03:02:5143const Value* TestingPrefService::GetUserPref(const char* path) {
[email protected]74379bc52010-07-21 13:54:0844 return GetPref(user_prefs_, path);
45}
46
[email protected]57ecc4b2010-08-11 03:02:5147void TestingPrefService::SetUserPref(const char* path, Value* value) {
[email protected]74379bc52010-07-21 13:54:0848 SetPref(user_prefs_, path, value);
49}
50
[email protected]57ecc4b2010-08-11 03:02:5151void TestingPrefService::RemoveUserPref(const char* path) {
[email protected]74379bc52010-07-21 13:54:0852 RemovePref(user_prefs_, path);
53}
54
55const Value* TestingPrefService::GetPref(PrefStore* pref_store,
[email protected]57ecc4b2010-08-11 03:02:5156 const char* path) {
[email protected]74379bc52010-07-21 13:54:0857 Value* result;
58 return pref_store->prefs()->Get(path, &result) ? result : NULL;
59}
60
61void TestingPrefService::SetPref(PrefStore* pref_store,
[email protected]57ecc4b2010-08-11 03:02:5162 const char* path,
[email protected]74379bc52010-07-21 13:54:0863 Value* value) {
64 pref_store->prefs()->Set(path, value);
65 FireObservers(path);
66}
67
68void TestingPrefService::RemovePref(PrefStore* pref_store,
[email protected]57ecc4b2010-08-11 03:02:5169 const char* path) {
[email protected]74379bc52010-07-21 13:54:0870 pref_store->prefs()->Remove(path, NULL);
71 FireObservers(path);
72}