Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / components / sync_preferences / pref_service_syncable_factory.cc
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/sync_preferences/pref_service_syncable_factory.h"
6
7 #include <memory>
8
9 #include "base/trace_event/trace_event.h"
10 #include "build/build_config.h"
11 #include "components/policy/core/browser/browser_policy_connector.h"
12 #include "components/policy/core/browser/configuration_policy_pref_store.h"
13 #include "components/policy/core/common/policy_service.h"
14 #include "components/policy/core/common/policy_types.h"
15 #include "components/pref_registry/pref_registry_syncable.h"
16 #include "components/prefs/default_pref_store.h"
17 #include "components/prefs/pref_notifier_impl.h"
18 #include "components/prefs/pref_value_store.h"
19 #include "components/sync_preferences/pref_service_syncable.h"
20
21 namespace sync_preferences {
22
23 PrefServiceSyncableFactory::PrefServiceSyncableFactory() = default;
24
25 PrefServiceSyncableFactory::~PrefServiceSyncableFactory() = default;
26
27 void PrefServiceSyncableFactory::SetManagedPolicies(
28     policy::PolicyService* service,
29     policy::BrowserPolicyConnector* connector) {
30   set_managed_prefs(new policy::ConfigurationPolicyPrefStore(
31       connector, service, connector->GetHandlerList(),
32       policy::POLICY_LEVEL_MANDATORY));
33 }
34
35 void PrefServiceSyncableFactory::SetRecommendedPolicies(
36     policy::PolicyService* service,
37     policy::BrowserPolicyConnector* connector) {
38   set_recommended_prefs(new policy::ConfigurationPolicyPrefStore(
39       connector, service, connector->GetHandlerList(),
40       policy::POLICY_LEVEL_RECOMMENDED));
41 }
42
43 void PrefServiceSyncableFactory::SetPrefModelAssociatorClient(
44     PrefModelAssociatorClient* pref_model_associator_client) {
45   pref_model_associator_client_ = pref_model_associator_client;
46 }
47
48 std::unique_ptr<PrefServiceSyncable> PrefServiceSyncableFactory::CreateSyncable(
49     scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry) {
50   TRACE_EVENT0("browser", "PrefServiceSyncableFactory::CreateSyncable");
51   auto pref_notifier = std::make_unique<PrefNotifierImpl>();
52   auto pref_value_store = std::make_unique<PrefValueStore>(
53       managed_prefs_.get(), supervised_user_prefs_.get(),
54       extension_prefs_.get(), standalone_browser_prefs_.get(),
55       command_line_prefs_.get(), user_prefs_.get(), recommended_prefs_.get(),
56       pref_registry->defaults().get(), pref_notifier.get());
57   return std::make_unique<PrefServiceSyncable>(
58       std::move(pref_notifier), std::move(pref_value_store), user_prefs_.get(),
59       standalone_browser_prefs_.get(), std::move(pref_registry),
60       pref_model_associator_client_, read_error_callback_, async_);
61 }
62
63 }  // namespace sync_preferences