| 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/dummy_pref_store.h" |
| 9 #include "chrome/browser/prefs/pref_value_store.h" | 9 #include "chrome/browser/prefs/pref_value_store.h" |
| 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 11 | 11 |
| 12 TestingPrefService::TestingPrefValueStore::TestingPrefValueStore( | 12 TestingPrefService::TestingPrefValueStore::TestingPrefValueStore( |
| 13 PrefStore* managed_prefs, | 13 PrefStore* managed_platform_prefs, |
| 14 PrefStore* device_management_prefs, |
| 14 PrefStore* extension_prefs, | 15 PrefStore* extension_prefs, |
| 15 PrefStore* command_line_prefs, | 16 PrefStore* command_line_prefs, |
| 16 PrefStore* user_prefs, | 17 PrefStore* user_prefs, |
| 17 PrefStore* recommended_prefs, | 18 PrefStore* recommended_prefs, |
| 18 PrefStore* default_prefs) | 19 PrefStore* default_prefs) |
| 19 : PrefValueStore(managed_prefs, extension_prefs, command_line_prefs, | 20 : PrefValueStore(managed_platform_prefs, device_management_prefs, |
| 21 extension_prefs, command_line_prefs, |
| 20 user_prefs, recommended_prefs, default_prefs) { | 22 user_prefs, recommended_prefs, default_prefs) { |
| 21 } | 23 } |
| 22 | 24 |
| 23 // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify | 25 // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify |
| 24 // which they want, and expand usage of this class to more unit tests. | 26 // which they want, and expand usage of this class to more unit tests. |
| 25 TestingPrefService::TestingPrefService() | 27 TestingPrefService::TestingPrefService() |
| 26 : PrefService(new TestingPrefValueStore( | 28 : PrefService(new TestingPrefValueStore( |
| 27 managed_prefs_ = new DummyPrefStore(), | 29 managed_platform_prefs_ = new DummyPrefStore(), |
| 30 device_management_prefs_ = new DummyPrefStore(), |
| 28 NULL, | 31 NULL, |
| 29 NULL, | 32 NULL, |
| 30 user_prefs_ = new DummyPrefStore(), | 33 user_prefs_ = new DummyPrefStore(), |
| 31 NULL, | 34 NULL, |
| 32 default_prefs_ = new DummyPrefStore())) { | 35 default_prefs_ = new DummyPrefStore())) { |
| 33 } | 36 } |
| 34 | 37 |
| 35 TestingPrefService::TestingPrefService( | 38 TestingPrefService::TestingPrefService( |
| 36 policy::ConfigurationPolicyProvider* provider, | 39 policy::ConfigurationPolicyProvider* managed_platform_provider, |
| 40 policy::ConfigurationPolicyProvider* device_management_provider, |
| 37 CommandLine* command_line) | 41 CommandLine* command_line) |
| 38 : PrefService(new TestingPrefValueStore( | 42 : PrefService(new TestingPrefValueStore( |
| 39 managed_prefs_ = CreateManagedPrefStore(provider), | 43 managed_platform_prefs_ = CreatePolicyPrefStoreFromProvider( |
| 44 managed_platform_provider), |
| 45 device_management_prefs_ = |
| 46 CreatePolicyPrefStoreFromProvider(device_management_provider), |
| 40 NULL, | 47 NULL, |
| 41 CreateCommandLinePrefStore(command_line), | 48 CreateCommandLinePrefStore(command_line), |
| 42 user_prefs_ = new DummyPrefStore(), | 49 user_prefs_ = new DummyPrefStore(), |
| 43 NULL, | 50 NULL, |
| 44 default_prefs_ = new DummyPrefStore())) { | 51 default_prefs_ = new DummyPrefStore())) { |
| 45 } | 52 } |
| 46 | 53 |
| 47 PrefStore* TestingPrefService::CreateManagedPrefStore( | 54 PrefStore* TestingPrefService::CreatePolicyPrefStoreFromProvider( |
| 48 policy::ConfigurationPolicyProvider* provider) { | 55 policy::ConfigurationPolicyProvider* provider) { |
| 49 if (provider) | 56 if (provider) |
| 50 return new policy::ConfigurationPolicyPrefStore(provider); | 57 return new policy::ConfigurationPolicyPrefStore(provider); |
| 51 return new DummyPrefStore(); | 58 return new DummyPrefStore(); |
| 52 } | 59 } |
| 53 | 60 |
| 54 PrefStore* TestingPrefService::CreateCommandLinePrefStore( | 61 PrefStore* TestingPrefService::CreateCommandLinePrefStore( |
| 55 CommandLine* command_line) { | 62 CommandLine* command_line) { |
| 56 if (command_line) | 63 if (command_line) |
| 57 return new CommandLinePrefStore(command_line); | 64 return new CommandLinePrefStore(command_line); |
| 58 return new DummyPrefStore(); | 65 return new DummyPrefStore(); |
| 59 } | 66 } |
| 60 | 67 |
| 61 const Value* TestingPrefService::GetManagedPref(const char* path) { | 68 const Value* TestingPrefService::GetManagedPref(const char* path) { |
| 62 return GetPref(managed_prefs_, path); | 69 return GetPref(managed_platform_prefs_, path); |
| 63 } | 70 } |
| 64 | 71 |
| 65 void TestingPrefService::SetManagedPref(const char* path, Value* value) { | 72 void TestingPrefService::SetManagedPref(const char* path, Value* value) { |
| 66 SetPref(managed_prefs_, path, value); | 73 SetPref(managed_platform_prefs_, path, value); |
| 67 } | 74 } |
| 68 | 75 |
| 69 void TestingPrefService::RemoveManagedPref(const char* path) { | 76 void TestingPrefService::RemoveManagedPref(const char* path) { |
| 70 RemovePref(managed_prefs_, path); | 77 RemovePref(managed_platform_prefs_, path); |
| 71 } | 78 } |
| 72 | 79 |
| 73 void TestingPrefService::SetManagedPrefWithoutNotification(const char* path, | 80 void TestingPrefService::SetManagedPrefWithoutNotification(const char* path, |
| 74 Value* value) { | 81 Value* value) { |
| 75 managed_prefs_->prefs()->Set(path, value); | 82 managed_platform_prefs_->prefs()->Set(path, value); |
| 76 } | 83 } |
| 77 | 84 |
| 78 void TestingPrefService::RemoveManagedPrefWithoutNotification( | 85 void TestingPrefService::RemoveManagedPrefWithoutNotification( |
| 79 const char* path) { | 86 const char* path) { |
| 80 managed_prefs_->prefs()->Remove(path, NULL); | 87 managed_platform_prefs_->prefs()->Remove(path, NULL); |
| 81 } | 88 } |
| 82 | 89 |
| 83 const Value* TestingPrefService::GetUserPref(const char* path) { | 90 const Value* TestingPrefService::GetUserPref(const char* path) { |
| 84 return GetPref(user_prefs_, path); | 91 return GetPref(user_prefs_, path); |
| 85 } | 92 } |
| 86 | 93 |
| 87 void TestingPrefService::SetUserPref(const char* path, Value* value) { | 94 void TestingPrefService::SetUserPref(const char* path, Value* value) { |
| 88 SetPref(user_prefs_, path, value); | 95 SetPref(user_prefs_, path, value); |
| 89 } | 96 } |
| 90 | 97 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 Value* value) { | 110 Value* value) { |
| 104 pref_store->prefs()->Set(path, value); | 111 pref_store->prefs()->Set(path, value); |
| 105 pref_notifier()->FireObservers(path); | 112 pref_notifier()->FireObservers(path); |
| 106 } | 113 } |
| 107 | 114 |
| 108 void TestingPrefService::RemovePref(PrefStore* pref_store, | 115 void TestingPrefService::RemovePref(PrefStore* pref_store, |
| 109 const char* path) { | 116 const char* path) { |
| 110 pref_store->prefs()->Remove(path, NULL); | 117 pref_store->prefs()->Remove(path, NULL); |
| 111 pref_notifier()->FireObservers(path); | 118 pref_notifier()->FireObservers(path); |
| 112 } | 119 } |
| OLD | NEW |