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/policy/configuration_policy_pref_store.h" |
7 #include "chrome/browser/prefs/command_line_pref_store.h" | 8 #include "chrome/browser/prefs/command_line_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_notifier.h" |
10 #include "chrome/browser/prefs/pref_value_store.h" | 10 #include "chrome/browser/prefs/pref_value_store.h" |
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 11 #include "chrome/browser/prefs/testing_pref_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( | 16 : PrefService( |
17 managed_platform_prefs_ = new TestingPrefStore(), | 17 managed_platform_prefs_ = new TestingPrefStore(), |
18 device_management_prefs_ = new TestingPrefStore(), | 18 device_management_prefs_ = new TestingPrefStore(), |
19 NULL, | 19 NULL, |
20 NULL, | 20 NULL, |
21 user_prefs_ = new TestingPrefStore(), | 21 user_prefs_ = new TestingPrefStore(), |
22 NULL, | 22 NULL, |
23 NULL) { | 23 NULL) { |
24 } | 24 } |
25 | 25 |
26 TestingPrefService::TestingPrefService( | 26 const Value* TestingPrefService::GetManagedPref(const char* path) const { |
27 policy::ConfigurationPolicyProvider* managed_platform_provider, | |
28 policy::ConfigurationPolicyProvider* device_management_provider, | |
29 CommandLine* command_line) | |
30 : PrefService( | |
31 managed_platform_prefs_ = CreatePolicyPrefStoreFromProvider( | |
32 managed_platform_provider), | |
33 device_management_prefs_ = | |
34 CreatePolicyPrefStoreFromProvider(device_management_provider), | |
35 NULL, | |
36 CreateCommandLinePrefStore(command_line), | |
37 user_prefs_ = new TestingPrefStore(), | |
38 NULL, | |
39 NULL) { | |
40 } | |
41 | |
42 PrefStore* TestingPrefService::CreatePolicyPrefStoreFromProvider( | |
43 policy::ConfigurationPolicyProvider* provider) { | |
44 if (provider) | |
45 return new policy::ConfigurationPolicyPrefStore(provider); | |
46 return new TestingPrefStore(); | |
47 } | |
48 | |
49 PrefStore* TestingPrefService::CreateCommandLinePrefStore( | |
50 CommandLine* command_line) { | |
51 if (command_line) | |
52 return new CommandLinePrefStore(command_line); | |
53 return new TestingPrefStore(); | |
54 } | |
55 | |
56 const Value* TestingPrefService::GetManagedPref(const char* path) { | |
57 return GetPref(managed_platform_prefs_, path); | 27 return GetPref(managed_platform_prefs_, path); |
58 } | 28 } |
59 | 29 |
60 void TestingPrefService::SetManagedPref(const char* path, Value* value) { | 30 void TestingPrefService::SetManagedPref(const char* path, Value* value) { |
61 SetPref(managed_platform_prefs_, path, value); | 31 SetPref(managed_platform_prefs_, path, value); |
62 } | 32 } |
63 | 33 |
64 void TestingPrefService::RemoveManagedPref(const char* path) { | 34 void TestingPrefService::RemoveManagedPref(const char* path) { |
65 RemovePref(managed_platform_prefs_, path); | 35 RemovePref(managed_platform_prefs_, path); |
66 } | 36 } |
67 | 37 |
68 void TestingPrefService::SetManagedPrefWithoutNotification(const char* path, | 38 const Value* TestingPrefService::GetUserPref(const char* path) const { |
69 Value* value) { | |
70 managed_platform_prefs_->prefs()->Set(path, value); | |
71 } | |
72 | |
73 void TestingPrefService::RemoveManagedPrefWithoutNotification( | |
74 const char* path) { | |
75 managed_platform_prefs_->prefs()->Remove(path, NULL); | |
76 } | |
77 | |
78 const Value* TestingPrefService::GetUserPref(const char* path) { | |
79 return GetPref(user_prefs_, path); | 39 return GetPref(user_prefs_, path); |
80 } | 40 } |
81 | 41 |
82 void TestingPrefService::SetUserPref(const char* path, Value* value) { | 42 void TestingPrefService::SetUserPref(const char* path, Value* value) { |
83 SetPref(user_prefs_, path, value); | 43 SetPref(user_prefs_, path, value); |
84 } | 44 } |
85 | 45 |
86 void TestingPrefService::RemoveUserPref(const char* path) { | 46 void TestingPrefService::RemoveUserPref(const char* path) { |
87 RemovePref(user_prefs_, path); | 47 RemovePref(user_prefs_, path); |
88 } | 48 } |
89 | 49 |
90 const Value* TestingPrefService::GetPref(PrefStore* pref_store, | 50 const Value* TestingPrefService::GetPref(TestingPrefStore* pref_store, |
91 const char* path) { | 51 const char* path) const { |
92 Value* result; | 52 Value* res; |
93 return pref_store->prefs()->Get(path, &result) ? result : NULL; | 53 return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; |
94 } | 54 } |
95 | 55 |
96 void TestingPrefService::SetPref(PrefStore* pref_store, | 56 void TestingPrefService::SetPref(TestingPrefStore* pref_store, |
97 const char* path, | 57 const char* path, |
98 Value* value) { | 58 Value* value) { |
99 pref_store->prefs()->Set(path, value); | 59 pref_store->SetValue(path, value); |
100 pref_notifier()->OnPreferenceChanged(path); | |
101 } | 60 } |
102 | 61 |
103 void TestingPrefService::RemovePref(PrefStore* pref_store, | 62 void TestingPrefService::RemovePref(TestingPrefStore* pref_store, |
104 const char* path) { | 63 const char* path) { |
105 pref_store->prefs()->Remove(path, NULL); | 64 pref_store->RemoveValue(path); |
106 pref_notifier()->OnPreferenceChanged(path); | |
107 } | 65 } |
OLD | NEW |