[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 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 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 7 | #include "chrome/browser/policy/configuration_policy_pref_store.h" |
[email protected] | ce1850e9 | 2010-10-15 08:40:58 | [diff] [blame] | 8 | #include "chrome/browser/prefs/command_line_pref_store.h" |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 9 | #include "chrome/browser/prefs/default_pref_store.h" |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 10 | #include "chrome/browser/prefs/pref_notifier.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 11 | #include "chrome/browser/prefs/pref_value_store.h" |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 12 | #include "chrome/browser/prefs/testing_pref_store.h" |
[email protected] | fa26b3d5 | 2010-08-06 08:51:50 | [diff] [blame] | 13 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 14 | TestingPrefServiceBase::TestingPrefServiceBase( |
| 15 | TestingPrefStore* managed_platform_prefs, |
| 16 | TestingPrefStore* device_management_prefs, |
| 17 | TestingPrefStore* user_prefs) |
| 18 | : PrefService(managed_platform_prefs, |
| 19 | device_management_prefs, |
| 20 | NULL, |
| 21 | NULL, |
| 22 | user_prefs, |
| 23 | NULL, |
| 24 | new DefaultPrefStore()), |
| 25 | managed_platform_prefs_(managed_platform_prefs), |
| 26 | device_management_prefs_(device_management_prefs), |
| 27 | user_prefs_(user_prefs) { |
[email protected] | ce1850e9 | 2010-10-15 08:40:58 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 30 | TestingPrefServiceBase::~TestingPrefServiceBase() { |
| 31 | } |
| 32 | |
| 33 | const Value* TestingPrefServiceBase::GetManagedPref(const char* path) const { |
[email protected] | be1c6e92 | 2010-11-17 12:49:17 | [diff] [blame] | 34 | return GetPref(managed_platform_prefs_, path); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 37 | void TestingPrefServiceBase::SetManagedPref(const char* path, Value* value) { |
[email protected] | be1c6e92 | 2010-11-17 12:49:17 | [diff] [blame] | 38 | SetPref(managed_platform_prefs_, path, value); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 39 | } |
| 40 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 41 | void TestingPrefServiceBase::RemoveManagedPref(const char* path) { |
[email protected] | be1c6e92 | 2010-11-17 12:49:17 | [diff] [blame] | 42 | RemovePref(managed_platform_prefs_, path); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 43 | } |
| 44 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 45 | const Value* TestingPrefServiceBase::GetUserPref(const char* path) const { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 46 | return GetPref(user_prefs_, path); |
| 47 | } |
| 48 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 49 | void TestingPrefServiceBase::SetUserPref(const char* path, Value* value) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 50 | SetPref(user_prefs_, path, value); |
| 51 | } |
| 52 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 53 | void TestingPrefServiceBase::RemoveUserPref(const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 54 | RemovePref(user_prefs_, path); |
| 55 | } |
| 56 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 57 | const Value* TestingPrefServiceBase::GetPref(TestingPrefStore* pref_store, |
| 58 | const char* path) const { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 59 | Value* res; |
| 60 | return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 61 | } |
| 62 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 63 | void TestingPrefServiceBase::SetPref(TestingPrefStore* pref_store, |
| 64 | const char* path, |
| 65 | Value* value) { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 66 | pref_store->SetValue(path, value); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 67 | } |
| 68 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 69 | void TestingPrefServiceBase::RemovePref(TestingPrefStore* pref_store, |
| 70 | const char* path) { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 71 | pref_store->RemoveValue(path); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 72 | } |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame^] | 73 | |
| 74 | TestingPrefService::TestingPrefService() |
| 75 | : TestingPrefServiceBase(new TestingPrefStore(), |
| 76 | new TestingPrefStore(), |
| 77 | new TestingPrefStore()) { |
| 78 | } |
| 79 | |
| 80 | TestingPrefService::~TestingPrefService() { |
| 81 | } |