| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/testing_pref_service.h" | 5 #include "chrome/test/testing_pref_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 8 #include "chrome/browser/prefs/command_line_pref_store.h" | 8 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 9 #include "chrome/browser/prefs/default_pref_store.h" |
| 9 #include "chrome/browser/prefs/pref_notifier.h" | 10 #include "chrome/browser/prefs/pref_notifier.h" |
| 10 #include "chrome/browser/prefs/pref_value_store.h" | 11 #include "chrome/browser/prefs/pref_value_store.h" |
| 11 #include "chrome/browser/prefs/testing_pref_store.h" | 12 #include "chrome/browser/prefs/testing_pref_store.h" |
| 12 | 13 |
| 13 // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify | 14 TestingPrefServiceBase::TestingPrefServiceBase( |
| 14 // which they want, and expand usage of this class to more unit tests. | 15 TestingPrefStore* managed_platform_prefs, |
| 15 TestingPrefService::TestingPrefService() | 16 TestingPrefStore* device_management_prefs, |
| 16 : PrefService( | 17 TestingPrefStore* user_prefs) |
| 17 managed_platform_prefs_ = new TestingPrefStore(), | 18 : PrefService(managed_platform_prefs, |
| 18 device_management_prefs_ = new TestingPrefStore(), | 19 device_management_prefs, |
| 19 NULL, | 20 NULL, |
| 20 NULL, | 21 NULL, |
| 21 user_prefs_ = new TestingPrefStore(), | 22 user_prefs, |
| 22 NULL) { | 23 NULL, |
| 24 new DefaultPrefStore()), |
| 25 managed_platform_prefs_(managed_platform_prefs), |
| 26 device_management_prefs_(device_management_prefs), |
| 27 user_prefs_(user_prefs) { |
| 23 } | 28 } |
| 24 | 29 |
| 25 const Value* TestingPrefService::GetManagedPref(const char* path) const { | 30 TestingPrefServiceBase::~TestingPrefServiceBase() { |
| 31 } |
| 32 |
| 33 const Value* TestingPrefServiceBase::GetManagedPref(const char* path) const { |
| 26 return GetPref(managed_platform_prefs_, path); | 34 return GetPref(managed_platform_prefs_, path); |
| 27 } | 35 } |
| 28 | 36 |
| 29 void TestingPrefService::SetManagedPref(const char* path, Value* value) { | 37 void TestingPrefServiceBase::SetManagedPref(const char* path, Value* value) { |
| 30 SetPref(managed_platform_prefs_, path, value); | 38 SetPref(managed_platform_prefs_, path, value); |
| 31 } | 39 } |
| 32 | 40 |
| 33 void TestingPrefService::RemoveManagedPref(const char* path) { | 41 void TestingPrefServiceBase::RemoveManagedPref(const char* path) { |
| 34 RemovePref(managed_platform_prefs_, path); | 42 RemovePref(managed_platform_prefs_, path); |
| 35 } | 43 } |
| 36 | 44 |
| 37 const Value* TestingPrefService::GetUserPref(const char* path) const { | 45 const Value* TestingPrefServiceBase::GetUserPref(const char* path) const { |
| 38 return GetPref(user_prefs_, path); | 46 return GetPref(user_prefs_, path); |
| 39 } | 47 } |
| 40 | 48 |
| 41 void TestingPrefService::SetUserPref(const char* path, Value* value) { | 49 void TestingPrefServiceBase::SetUserPref(const char* path, Value* value) { |
| 42 SetPref(user_prefs_, path, value); | 50 SetPref(user_prefs_, path, value); |
| 43 } | 51 } |
| 44 | 52 |
| 45 void TestingPrefService::RemoveUserPref(const char* path) { | 53 void TestingPrefServiceBase::RemoveUserPref(const char* path) { |
| 46 RemovePref(user_prefs_, path); | 54 RemovePref(user_prefs_, path); |
| 47 } | 55 } |
| 48 | 56 |
| 49 const Value* TestingPrefService::GetPref(TestingPrefStore* pref_store, | 57 const Value* TestingPrefServiceBase::GetPref(TestingPrefStore* pref_store, |
| 50 const char* path) const { | 58 const char* path) const { |
| 51 Value* res; | 59 Value* res; |
| 52 return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; | 60 return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; |
| 53 } | 61 } |
| 54 | 62 |
| 55 void TestingPrefService::SetPref(TestingPrefStore* pref_store, | 63 void TestingPrefServiceBase::SetPref(TestingPrefStore* pref_store, |
| 56 const char* path, | 64 const char* path, |
| 57 Value* value) { | 65 Value* value) { |
| 58 pref_store->SetValue(path, value); | 66 pref_store->SetValue(path, value); |
| 59 } | 67 } |
| 60 | 68 |
| 61 void TestingPrefService::RemovePref(TestingPrefStore* pref_store, | 69 void TestingPrefServiceBase::RemovePref(TestingPrefStore* pref_store, |
| 62 const char* path) { | 70 const char* path) { |
| 63 pref_store->RemoveValue(path); | 71 pref_store->RemoveValue(path); |
| 64 } | 72 } |
| 73 |
| 74 TestingPrefService::TestingPrefService() |
| 75 : TestingPrefServiceBase(new TestingPrefStore(), |
| 76 new TestingPrefStore(), |
| 77 new TestingPrefStore()) { |
| 78 } |
| 79 |
| 80 TestingPrefService::~TestingPrefService() { |
| 81 } |
| OLD | NEW |