OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/prefs/command_line_pref_store.h" | 7 #include "chrome/browser/prefs/command_line_pref_store.h" |
8 #include "chrome/browser/prefs/dummy_pref_store.h" | 8 #include "chrome/browser/prefs/testing_pref_store.h" |
| 9 #include "chrome/browser/prefs/pref_notifier.h" |
9 #include "chrome/browser/prefs/pref_value_store.h" | 10 #include "chrome/browser/prefs/pref_value_store.h" |
10 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
11 #include "chrome/test/testing_pref_value_store.h" | |
12 | 12 |
13 // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify | 13 // 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. | 14 // which they want, and expand usage of this class to more unit tests. |
15 TestingPrefService::TestingPrefService() | 15 TestingPrefService::TestingPrefService() |
16 : PrefService(new TestingPrefValueStore( | 16 : PrefService( |
17 managed_platform_prefs_ = new DummyPrefStore(), | 17 managed_platform_prefs_ = new TestingPrefStore(), |
18 device_management_prefs_ = new DummyPrefStore(), | 18 device_management_prefs_ = new TestingPrefStore(), |
19 NULL, | 19 NULL, |
20 NULL, | 20 NULL, |
21 user_prefs_ = new DummyPrefStore(), | 21 user_prefs_ = new TestingPrefStore(), |
22 NULL, | 22 NULL, |
23 default_prefs_ = new DummyPrefStore())) { | 23 NULL) { |
24 } | 24 } |
25 | 25 |
26 TestingPrefService::TestingPrefService( | 26 TestingPrefService::TestingPrefService( |
27 policy::ConfigurationPolicyProvider* managed_platform_provider, | 27 policy::ConfigurationPolicyProvider* managed_platform_provider, |
28 policy::ConfigurationPolicyProvider* device_management_provider, | 28 policy::ConfigurationPolicyProvider* device_management_provider, |
29 CommandLine* command_line) | 29 CommandLine* command_line) |
30 : PrefService(new TestingPrefValueStore( | 30 : PrefService( |
31 managed_platform_prefs_ = CreatePolicyPrefStoreFromProvider( | 31 managed_platform_prefs_ = CreatePolicyPrefStoreFromProvider( |
32 managed_platform_provider), | 32 managed_platform_provider), |
33 device_management_prefs_ = | 33 device_management_prefs_ = |
34 CreatePolicyPrefStoreFromProvider(device_management_provider), | 34 CreatePolicyPrefStoreFromProvider(device_management_provider), |
35 NULL, | 35 NULL, |
36 CreateCommandLinePrefStore(command_line), | 36 CreateCommandLinePrefStore(command_line), |
37 user_prefs_ = new DummyPrefStore(), | 37 user_prefs_ = new TestingPrefStore(), |
38 NULL, | 38 NULL, |
39 default_prefs_ = new DummyPrefStore())) { | 39 NULL) { |
40 } | 40 } |
41 | 41 |
42 PrefStore* TestingPrefService::CreatePolicyPrefStoreFromProvider( | 42 PrefStore* TestingPrefService::CreatePolicyPrefStoreFromProvider( |
43 policy::ConfigurationPolicyProvider* provider) { | 43 policy::ConfigurationPolicyProvider* provider) { |
44 if (provider) | 44 if (provider) |
45 return new policy::ConfigurationPolicyPrefStore(provider); | 45 return new policy::ConfigurationPolicyPrefStore(provider); |
46 return new DummyPrefStore(); | 46 return new TestingPrefStore(); |
47 } | 47 } |
48 | 48 |
49 PrefStore* TestingPrefService::CreateCommandLinePrefStore( | 49 PrefStore* TestingPrefService::CreateCommandLinePrefStore( |
50 CommandLine* command_line) { | 50 CommandLine* command_line) { |
51 if (command_line) | 51 if (command_line) |
52 return new CommandLinePrefStore(command_line); | 52 return new CommandLinePrefStore(command_line); |
53 return new DummyPrefStore(); | 53 return new TestingPrefStore(); |
54 } | 54 } |
55 | 55 |
56 const Value* TestingPrefService::GetManagedPref(const char* path) { | 56 const Value* TestingPrefService::GetManagedPref(const char* path) { |
57 return GetPref(managed_platform_prefs_, path); | 57 return GetPref(managed_platform_prefs_, path); |
58 } | 58 } |
59 | 59 |
60 void TestingPrefService::SetManagedPref(const char* path, Value* value) { | 60 void TestingPrefService::SetManagedPref(const char* path, Value* value) { |
61 SetPref(managed_platform_prefs_, path, value); | 61 SetPref(managed_platform_prefs_, path, value); |
62 } | 62 } |
63 | 63 |
(...skipping 26 matching lines...) Expand all Loading... |
90 const Value* TestingPrefService::GetPref(PrefStore* pref_store, | 90 const Value* TestingPrefService::GetPref(PrefStore* pref_store, |
91 const char* path) { | 91 const char* path) { |
92 Value* result; | 92 Value* result; |
93 return pref_store->prefs()->Get(path, &result) ? result : NULL; | 93 return pref_store->prefs()->Get(path, &result) ? result : NULL; |
94 } | 94 } |
95 | 95 |
96 void TestingPrefService::SetPref(PrefStore* pref_store, | 96 void TestingPrefService::SetPref(PrefStore* pref_store, |
97 const char* path, | 97 const char* path, |
98 Value* value) { | 98 Value* value) { |
99 pref_store->prefs()->Set(path, value); | 99 pref_store->prefs()->Set(path, value); |
100 pref_notifier()->FireObservers(path); | 100 pref_notifier()->OnPreferenceChanged(path); |
101 } | 101 } |
102 | 102 |
103 void TestingPrefService::RemovePref(PrefStore* pref_store, | 103 void TestingPrefService::RemovePref(PrefStore* pref_store, |
104 const char* path) { | 104 const char* path) { |
105 pref_store->prefs()->Remove(path, NULL); | 105 pref_store->prefs()->Remove(path, NULL); |
106 pref_notifier()->FireObservers(path); | 106 pref_notifier()->OnPreferenceChanged(path); |
107 } | 107 } |
OLD | NEW |