Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / components / sync_preferences / pref_service_syncable_factory.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
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/pref_registry/pref_registry_syncable.h"
12 #include "components/prefs/default_pref_store.h"
13 #include "components/prefs/pref_notifier_impl.h"
14 #include "components/prefs/pref_value_store.h"
15 #include "components/sync_preferences/pref_service_syncable.h"
16
17 #if !defined(OS_IOS)
18 #include "components/policy/core/browser/browser_policy_connector.h"
19 #include "components/policy/core/browser/configuration_policy_pref_store.h"
20 #include "components/policy/core/common/policy_service.h"  // nogncheck
21 #include "components/policy/core/common/policy_types.h"    // nogncheck
22 #endif
23
24 namespace sync_preferences {
25
26 PrefServiceSyncableFactory::PrefServiceSyncableFactory() {}
27
28 PrefServiceSyncableFactory::~PrefServiceSyncableFactory() {}
29
30 void PrefServiceSyncableFactory::SetManagedPolicies(
31     policy::PolicyService* service,
32     policy::BrowserPolicyConnector* connector) {
33 #if !defined(OS_IOS)
34   set_managed_prefs(new policy::ConfigurationPolicyPrefStore(
35       connector, service, connector->GetHandlerList(),
36       policy::POLICY_LEVEL_MANDATORY));
37 #else
38   NOTREACHED();
39 #endif
40 }
41
42 void PrefServiceSyncableFactory::SetRecommendedPolicies(
43     policy::PolicyService* service,
44     policy::BrowserPolicyConnector* connector) {
45 #if !defined(OS_IOS)
46   set_recommended_prefs(new policy::ConfigurationPolicyPrefStore(
47       connector, service, connector->GetHandlerList(),
48       policy::POLICY_LEVEL_RECOMMENDED));
49 #else
50   NOTREACHED();
51 #endif
52 }
53
54 void PrefServiceSyncableFactory::SetPrefModelAssociatorClient(
55     PrefModelAssociatorClient* pref_model_associator_client) {
56   pref_model_associator_client_ = pref_model_associator_client;
57 }
58
59 std::unique_ptr<PrefServiceSyncable> PrefServiceSyncableFactory::CreateSyncable(
60     scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry,
61     std::unique_ptr<PrefValueStore::Delegate> delegate) {
62   TRACE_EVENT0("browser", "PrefServiceSyncableFactory::CreateSyncable");
63   auto pref_notifier = std::make_unique<PrefNotifierImpl>();
64   auto pref_value_store = std::make_unique<PrefValueStore>(
65       managed_prefs_.get(), supervised_user_prefs_.get(),
66       extension_prefs_.get(), command_line_prefs_.get(), user_prefs_.get(),
67       recommended_prefs_.get(), pref_registry->defaults().get(),
68       pref_notifier.get(), std::move(delegate));
69   return std::make_unique<PrefServiceSyncable>(
70       std::move(pref_notifier), std::move(pref_value_store), user_prefs_.get(),
71       std::move(pref_registry), pref_model_associator_client_,
72       read_error_callback_, async_);
73 }
74
75 }  // namespace sync_preferences