[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 1 | // 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] | fa26b3d5 | 2010-08-06 08:51:50 | [diff] [blame] | 10 | TestingPrefService::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] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 22 | TestingPrefService::TestingPrefService() |
[email protected] | fa26b3d5 | 2010-08-06 08:51:50 | [diff] [blame] | 23 | : PrefService(new TestingPrefValueStore( |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 24 | managed_prefs_ = new DummyPrefStore(), |
| 25 | NULL, |
| 26 | NULL, |
| 27 | user_prefs_ = new DummyPrefStore(), |
| 28 | NULL)) { |
| 29 | } |
| 30 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 31 | const Value* TestingPrefService::GetManagedPref(const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 32 | return GetPref(managed_prefs_, path); |
| 33 | } |
| 34 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 35 | void TestingPrefService::SetManagedPref(const char* path, Value* value) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 36 | SetPref(managed_prefs_, path, value); |
| 37 | } |
| 38 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 39 | void TestingPrefService::RemoveManagedPref(const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 40 | RemovePref(managed_prefs_, path); |
| 41 | } |
| 42 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 43 | const Value* TestingPrefService::GetUserPref(const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 44 | return GetPref(user_prefs_, path); |
| 45 | } |
| 46 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 47 | void TestingPrefService::SetUserPref(const char* path, Value* value) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 48 | SetPref(user_prefs_, path, value); |
| 49 | } |
| 50 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 51 | void TestingPrefService::RemoveUserPref(const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 52 | RemovePref(user_prefs_, path); |
| 53 | } |
| 54 | |
| 55 | const Value* TestingPrefService::GetPref(PrefStore* pref_store, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 56 | const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 57 | Value* result; |
| 58 | return pref_store->prefs()->Get(path, &result) ? result : NULL; |
| 59 | } |
| 60 | |
| 61 | void TestingPrefService::SetPref(PrefStore* pref_store, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 62 | const char* path, |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 63 | Value* value) { |
| 64 | pref_store->prefs()->Set(path, value); |
| 65 | FireObservers(path); |
| 66 | } |
| 67 | |
| 68 | void TestingPrefService::RemovePref(PrefStore* pref_store, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame^] | 69 | const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 70 | pref_store->prefs()->Remove(path, NULL); |
| 71 | FireObservers(path); |
| 72 | } |