Chromium Code Reviews| 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/extensions/extension_pref_store.h" | |
| 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 8 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 8 #include "chrome/browser/prefs/command_line_pref_store.h" | 9 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 10 #include "chrome/browser/prefs/default_pref_store.h" | |
| 9 #include "chrome/browser/prefs/pref_notifier.h" | 11 #include "chrome/browser/prefs/pref_notifier.h" |
| 10 #include "chrome/browser/prefs/pref_value_store.h" | 12 #include "chrome/browser/prefs/pref_value_store.h" |
| 11 #include "chrome/browser/prefs/testing_pref_store.h" | 13 #include "chrome/browser/prefs/testing_pref_store.h" |
| 12 | 14 |
| 13 // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify | 15 // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify |
| 14 // which they want, and expand usage of this class to more unit tests. | 16 // which they want, and expand usage of this class to more unit tests. |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
This comment is outdated, just remove it. The solu
battre
2011/01/05 20:23:08
Done.
| |
| 15 TestingPrefService::TestingPrefService() | 17 TestingPrefServiceBase::TestingPrefServiceBase( |
| 16 : PrefService( | 18 TestingPrefStore* managed_platform_prefs, |
| 17 managed_platform_prefs_ = new TestingPrefStore(), | 19 TestingPrefStore* device_management_prefs, |
| 18 device_management_prefs_ = new TestingPrefStore(), | 20 ExtensionPrefStore* extension_prefs, |
| 19 NULL, | 21 TestingPrefStore* user_prefs) |
| 20 NULL, | 22 : PrefService(managed_platform_prefs, |
| 21 user_prefs_ = new TestingPrefStore(), | 23 device_management_prefs, |
| 22 NULL) { | 24 extension_prefs, |
| 25 NULL, | |
| 26 user_prefs, | |
| 27 NULL, | |
| 28 new DefaultPrefStore(), | |
| 29 true), | |
| 30 managed_platform_prefs_(managed_platform_prefs), | |
| 31 device_management_prefs_(device_management_prefs), | |
| 32 extension_prefs_(extension_prefs), | |
| 33 user_prefs_(user_prefs) { | |
| 23 } | 34 } |
| 24 | 35 |
| 25 const Value* TestingPrefService::GetManagedPref(const char* path) const { | 36 TestingPrefServiceBase::~TestingPrefServiceBase() { |
| 37 } | |
| 38 | |
| 39 const Value* TestingPrefServiceBase::GetManagedPref(const char* path) const { | |
| 26 return GetPref(managed_platform_prefs_, path); | 40 return GetPref(managed_platform_prefs_, path); |
| 27 } | 41 } |
| 28 | 42 |
| 29 void TestingPrefService::SetManagedPref(const char* path, Value* value) { | 43 void TestingPrefServiceBase::SetManagedPref(const char* path, Value* value) { |
| 30 SetPref(managed_platform_prefs_, path, value); | 44 SetPref(managed_platform_prefs_, path, value); |
| 31 } | 45 } |
| 32 | 46 |
| 33 void TestingPrefService::RemoveManagedPref(const char* path) { | 47 void TestingPrefServiceBase::RemoveManagedPref(const char* path) { |
| 34 RemovePref(managed_platform_prefs_, path); | 48 RemovePref(managed_platform_prefs_, path); |
| 35 } | 49 } |
| 36 | 50 |
| 37 const Value* TestingPrefService::GetUserPref(const char* path) const { | 51 const Value* TestingPrefServiceBase::GetUserPref(const char* path) const { |
| 38 return GetPref(user_prefs_, path); | 52 return GetPref(user_prefs_, path); |
| 39 } | 53 } |
| 40 | 54 |
| 41 void TestingPrefService::SetUserPref(const char* path, Value* value) { | 55 void TestingPrefServiceBase::SetUserPref(const char* path, Value* value) { |
| 42 SetPref(user_prefs_, path, value); | 56 SetPref(user_prefs_, path, value); |
| 43 } | 57 } |
| 44 | 58 |
| 45 void TestingPrefService::RemoveUserPref(const char* path) { | 59 void TestingPrefServiceBase::RemoveUserPref(const char* path) { |
| 46 RemovePref(user_prefs_, path); | 60 RemovePref(user_prefs_, path); |
| 47 } | 61 } |
| 48 | 62 |
| 49 const Value* TestingPrefService::GetPref(TestingPrefStore* pref_store, | 63 const Value* TestingPrefServiceBase::GetPref(TestingPrefStore* pref_store, |
| 50 const char* path) const { | 64 const char* path) const { |
| 51 Value* res; | 65 Value* res; |
| 52 return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; | 66 return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; |
| 53 } | 67 } |
| 54 | 68 |
| 55 void TestingPrefService::SetPref(TestingPrefStore* pref_store, | 69 void TestingPrefServiceBase::SetPref(TestingPrefStore* pref_store, |
| 56 const char* path, | 70 const char* path, |
| 57 Value* value) { | 71 Value* value) { |
| 58 pref_store->SetValue(path, value); | 72 pref_store->SetValue(path, value); |
| 59 } | 73 } |
| 60 | 74 |
| 61 void TestingPrefService::RemovePref(TestingPrefStore* pref_store, | 75 void TestingPrefServiceBase::RemovePref(TestingPrefStore* pref_store, |
| 62 const char* path) { | 76 const char* path) { |
| 63 pref_store->RemoveValue(path); | 77 pref_store->RemoveValue(path); |
| 64 } | 78 } |
| 79 | |
| 80 ExtensionPrefStore* TestingPrefServiceBase::GetExtensionPrefs() { | |
| 81 return extension_prefs_.get(); | |
| 82 } | |
| 83 | |
| 84 TestingPrefService::TestingPrefService() | |
| 85 : TestingPrefServiceBase(new TestingPrefStore(), | |
| 86 new TestingPrefStore(), | |
| 87 new ExtensionPrefStore(false), | |
| 88 new TestingPrefStore()) { | |
| 89 } | |
| 90 | |
| 91 TestingPrefService::~TestingPrefService() { | |
| 92 } | |
| OLD | NEW |