1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker #include "components/prefs/testing_pref_service.h"
6*6777b538SAndroid Build Coastguard Worker
7*6777b538SAndroid Build Coastguard Worker #include <memory>
8*6777b538SAndroid Build Coastguard Worker
9*6777b538SAndroid Build Coastguard Worker #include "base/compiler_specific.h"
10*6777b538SAndroid Build Coastguard Worker #include "base/functional/bind.h"
11*6777b538SAndroid Build Coastguard Worker #include "components/prefs/default_pref_store.h"
12*6777b538SAndroid Build Coastguard Worker #include "components/prefs/pref_notifier_impl.h"
13*6777b538SAndroid Build Coastguard Worker #include "components/prefs/pref_registry_simple.h"
14*6777b538SAndroid Build Coastguard Worker #include "components/prefs/pref_value_store.h"
15*6777b538SAndroid Build Coastguard Worker #include "testing/gtest/include/gtest/gtest.h"
16*6777b538SAndroid Build Coastguard Worker
17*6777b538SAndroid Build Coastguard Worker template <>
TestingPrefServiceBase(scoped_refptr<TestingPrefStore> managed_prefs,scoped_refptr<TestingPrefStore> supervised_user_prefs,scoped_refptr<TestingPrefStore> extension_prefs,scoped_refptr<TestingPrefStore> standalone_browser_prefs,scoped_refptr<TestingPrefStore> user_prefs,scoped_refptr<TestingPrefStore> recommended_prefs,scoped_refptr<PrefRegistry> pref_registry,PrefNotifierImpl * pref_notifier)18*6777b538SAndroid Build Coastguard Worker TestingPrefServiceBase<PrefService, PrefRegistry>::TestingPrefServiceBase(
19*6777b538SAndroid Build Coastguard Worker scoped_refptr<TestingPrefStore> managed_prefs,
20*6777b538SAndroid Build Coastguard Worker scoped_refptr<TestingPrefStore> supervised_user_prefs,
21*6777b538SAndroid Build Coastguard Worker scoped_refptr<TestingPrefStore> extension_prefs,
22*6777b538SAndroid Build Coastguard Worker scoped_refptr<TestingPrefStore> standalone_browser_prefs,
23*6777b538SAndroid Build Coastguard Worker scoped_refptr<TestingPrefStore> user_prefs,
24*6777b538SAndroid Build Coastguard Worker scoped_refptr<TestingPrefStore> recommended_prefs,
25*6777b538SAndroid Build Coastguard Worker scoped_refptr<PrefRegistry> pref_registry,
26*6777b538SAndroid Build Coastguard Worker PrefNotifierImpl* pref_notifier)
27*6777b538SAndroid Build Coastguard Worker : PrefService(
28*6777b538SAndroid Build Coastguard Worker // Warning: `pref_notifier` is used for 2 arguments and the order of
29*6777b538SAndroid Build Coastguard Worker // computation isn't guaranteed. So making it a unique_ptr would cause
30*6777b538SAndroid Build Coastguard Worker // std::unique_ptr<>::get() after std::move().
31*6777b538SAndroid Build Coastguard Worker std::unique_ptr<PrefNotifierImpl>(pref_notifier),
32*6777b538SAndroid Build Coastguard Worker std::make_unique<PrefValueStore>(managed_prefs.get(),
33*6777b538SAndroid Build Coastguard Worker supervised_user_prefs.get(),
34*6777b538SAndroid Build Coastguard Worker extension_prefs.get(),
35*6777b538SAndroid Build Coastguard Worker standalone_browser_prefs.get(),
36*6777b538SAndroid Build Coastguard Worker /*command_line_prefs=*/nullptr,
37*6777b538SAndroid Build Coastguard Worker user_prefs.get(),
38*6777b538SAndroid Build Coastguard Worker recommended_prefs.get(),
39*6777b538SAndroid Build Coastguard Worker pref_registry->defaults().get(),
40*6777b538SAndroid Build Coastguard Worker pref_notifier),
41*6777b538SAndroid Build Coastguard Worker user_prefs,
42*6777b538SAndroid Build Coastguard Worker standalone_browser_prefs,
43*6777b538SAndroid Build Coastguard Worker pref_registry,
44*6777b538SAndroid Build Coastguard Worker base::BindRepeating(
45*6777b538SAndroid Build Coastguard Worker &TestingPrefServiceBase<PrefService,
46*6777b538SAndroid Build Coastguard Worker PrefRegistry>::HandleReadError),
47*6777b538SAndroid Build Coastguard Worker false),
48*6777b538SAndroid Build Coastguard Worker managed_prefs_(managed_prefs),
49*6777b538SAndroid Build Coastguard Worker supervised_user_prefs_(supervised_user_prefs),
50*6777b538SAndroid Build Coastguard Worker extension_prefs_(extension_prefs),
51*6777b538SAndroid Build Coastguard Worker standalone_browser_prefs_(standalone_browser_prefs),
52*6777b538SAndroid Build Coastguard Worker user_prefs_(user_prefs),
53*6777b538SAndroid Build Coastguard Worker recommended_prefs_(recommended_prefs) {}
54*6777b538SAndroid Build Coastguard Worker
TestingPrefServiceSimple()55*6777b538SAndroid Build Coastguard Worker TestingPrefServiceSimple::TestingPrefServiceSimple()
56*6777b538SAndroid Build Coastguard Worker : TestingPrefServiceBase<PrefService, PrefRegistry>(
57*6777b538SAndroid Build Coastguard Worker /*managed_prefs=*/base::MakeRefCounted<TestingPrefStore>(),
58*6777b538SAndroid Build Coastguard Worker /*supervised_user_prefs=*/base::MakeRefCounted<TestingPrefStore>(),
59*6777b538SAndroid Build Coastguard Worker /*extension_prefs=*/base::MakeRefCounted<TestingPrefStore>(),
60*6777b538SAndroid Build Coastguard Worker /*standalone_browser_prefs=*/base::MakeRefCounted<TestingPrefStore>(),
61*6777b538SAndroid Build Coastguard Worker /*user_prefs=*/base::MakeRefCounted<TestingPrefStore>(),
62*6777b538SAndroid Build Coastguard Worker /*recommended_prefs=*/base::MakeRefCounted<TestingPrefStore>(),
63*6777b538SAndroid Build Coastguard Worker base::MakeRefCounted<PrefRegistrySimple>(),
64*6777b538SAndroid Build Coastguard Worker new PrefNotifierImpl()) {}
65*6777b538SAndroid Build Coastguard Worker
~TestingPrefServiceSimple()66*6777b538SAndroid Build Coastguard Worker TestingPrefServiceSimple::~TestingPrefServiceSimple() {
67*6777b538SAndroid Build Coastguard Worker }
68*6777b538SAndroid Build Coastguard Worker
registry()69*6777b538SAndroid Build Coastguard Worker PrefRegistrySimple* TestingPrefServiceSimple::registry() {
70*6777b538SAndroid Build Coastguard Worker return static_cast<PrefRegistrySimple*>(DeprecatedGetPrefRegistry());
71*6777b538SAndroid Build Coastguard Worker }
72