blob: 067b8b91274839b59a435c76820ad9110a03655b [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
31const Value* TestingPrefService::GetManagedPref(const wchar_t* path) {
32 return GetPref(managed_prefs_, path);
33}
34
35void TestingPrefService::SetManagedPref(const wchar_t* path, Value* value) {
36 SetPref(managed_prefs_, path, value);
37}
38
39void TestingPrefService::RemoveManagedPref(const wchar_t* path) {
40 RemovePref(managed_prefs_, path);
41}
42
43const Value* TestingPrefService::GetUserPref(const wchar_t* path) {
44 return GetPref(user_prefs_, path);
45}
46
47void TestingPrefService::SetUserPref(const wchar_t* path, Value* value) {
48 SetPref(user_prefs_, path, value);
49}
50
51void TestingPrefService::RemoveUserPref(const wchar_t* path) {
52 RemovePref(user_prefs_, path);
53}
54
55const Value* TestingPrefService::GetPref(PrefStore* pref_store,
56 const wchar_t* path) {
57 Value* result;
58 return pref_store->prefs()->Get(path, &result) ? result : NULL;
59}
60
61void TestingPrefService::SetPref(PrefStore* pref_store,
62 const wchar_t* path,
63 Value* value) {
64 pref_store->prefs()->Set(path, value);
65 FireObservers(path);
66}
67
68void TestingPrefService::RemovePref(PrefStore* pref_store,
69 const wchar_t* path) {
70 pref_store->prefs()->Remove(path, NULL);
71 FireObservers(path);
72}