Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Side by Side Diff: components/sync_preferences/pref_service_syncable_factory.cc

Issue 2860683002: WIP: Pref service: use the incognito support from Chrome
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync_preferences/pref_service_syncable_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "components/sync_preferences/pref_service_syncable_factory.h" 5 #include "components/sync_preferences/pref_service_syncable_factory.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "components/pref_registry/pref_registry_syncable.h" 9 #include "components/pref_registry/pref_registry_syncable.h"
10 #include "components/prefs/default_pref_store.h" 10 #include "components/prefs/default_pref_store.h"
11 #include "components/prefs/overlay_user_pref_store.h"
11 #include "components/prefs/pref_notifier_impl.h" 12 #include "components/prefs/pref_notifier_impl.h"
12 #include "components/prefs/pref_value_store.h" 13 #include "components/prefs/pref_value_store.h"
13 #include "components/sync_preferences/pref_service_syncable.h" 14 #include "components/sync_preferences/pref_service_syncable.h"
15 #include "services/preferences/public/cpp/persistent_pref_store_client.h"
14 #include "services/preferences/public/cpp/pref_store_adapter.h" 16 #include "services/preferences/public/cpp/pref_store_adapter.h"
15 #include "services/preferences/public/interfaces/preferences.mojom.h" 17 #include "services/preferences/public/interfaces/preferences.mojom.h"
16 #include "services/service_manager/public/cpp/connector.h" 18 #include "services/service_manager/public/cpp/connector.h"
17 19
18 #if !defined(OS_IOS) 20 #if !defined(OS_IOS)
19 #include "components/policy/core/browser/browser_policy_connector.h" 21 #include "components/policy/core/browser/browser_policy_connector.h"
20 #include "components/policy/core/browser/configuration_policy_pref_store.h" 22 #include "components/policy/core/browser/configuration_policy_pref_store.h"
21 #include "components/policy/core/common/policy_service.h" // nogncheck 23 #include "components/policy/core/common/policy_service.h" // nogncheck
22 #include "components/policy/core/common/policy_types.h" // nogncheck 24 #include "components/policy/core/common/policy_types.h" // nogncheck
23 #endif 25 #endif
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 PrefValueStore::MANAGED_STORE); 89 PrefValueStore::MANAGED_STORE);
88 auto supervised = CreateRegisteredPrefStore( 90 auto supervised = CreateRegisteredPrefStore(
89 connector, supervised_user_prefs_, PrefValueStore::SUPERVISED_USER_STORE); 91 connector, supervised_user_prefs_, PrefValueStore::SUPERVISED_USER_STORE);
90 auto extension = CreateRegisteredPrefStore(connector, extension_prefs_, 92 auto extension = CreateRegisteredPrefStore(connector, extension_prefs_,
91 PrefValueStore::EXTENSION_STORE); 93 PrefValueStore::EXTENSION_STORE);
92 auto command_line = CreateRegisteredPrefStore( 94 auto command_line = CreateRegisteredPrefStore(
93 connector, command_line_prefs_, PrefValueStore::COMMAND_LINE_STORE); 95 connector, command_line_prefs_, PrefValueStore::COMMAND_LINE_STORE);
94 auto recommended = CreateRegisteredPrefStore( 96 auto recommended = CreateRegisteredPrefStore(
95 connector, recommended_prefs_, PrefValueStore::RECOMMENDED_STORE); 97 connector, recommended_prefs_, PrefValueStore::RECOMMENDED_STORE);
96 98
97 // TODO(sammc): Register Mojo user pref store once implemented.
98 std::unique_ptr<PrefServiceSyncable> pref_service(new PrefServiceSyncable( 99 std::unique_ptr<PrefServiceSyncable> pref_service(new PrefServiceSyncable(
99 pref_notifier, 100 pref_notifier,
100 new PrefValueStore(managed.get(), supervised.get(), extension.get(), 101 new PrefValueStore(managed.get(), supervised.get(), extension.get(),
101 command_line.get(), user_prefs_.get(), 102 command_line.get(), user_prefs_.get(),
102 recommended.get(), pref_registry->defaults().get(), 103 recommended.get(), pref_registry->defaults().get(),
103 pref_notifier), 104 pref_notifier),
104 user_prefs_.get(), pref_registry, pref_model_associator_client_, 105 user_prefs_.get(), pref_registry, pref_model_associator_client_,
105 read_error_callback_, async_)); 106 read_error_callback_, async_));
106 return pref_service; 107 return pref_service;
107 } 108 }
108 109
110 namespace {
111 void InitIncognitoService(service_manager::Connector* incognito_connector,
112 service_manager::Connector* user_connector) {
113 prefs::mojom::PrefStoreConnectorPtr connector;
114 user_connector->BindInterface(prefs::mojom::kServiceName, &connector);
115 auto config = prefs::mojom::PersistentPrefStoreConfiguration::New();
116 config->set_incognito_configuration(
117 prefs::mojom::IncognitoPersistentPrefStoreConfiguration::New(
118 std::move(connector)));
119 prefs::mojom::PrefServiceControlPtr control;
120 incognito_connector->BindInterface(prefs::mojom::kServiceName, &control);
121 control->Init(std::move(config));
122 }
123 } // namespace
124
125 std::unique_ptr<PrefServiceSyncable>
126 PrefServiceSyncableFactory::CreateIncognitoSyncable(
127 user_prefs::PrefRegistrySyncable* pref_registry,
128 PrefStore* incognito_extension_pref_store,
129 const std::vector<const char*>& overlay_pref_names,
130 std::set<PrefValueStore::PrefStoreType> already_connected_types,
131 service_manager::Connector* incognito_connector,
132 service_manager::Connector* user_connector) {
133 TRACE_EVENT0("browser",
134 "PrefServiceSyncableFactory::CreateIncognitoSyncable");
135
136 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
137
138 scoped_refptr<user_prefs::PrefRegistrySyncable> forked_registry =
139 static_cast<user_prefs::PrefRegistrySyncable*>(pref_registry)
140 ->ForkForIncognito();
141 scoped_refptr<PersistentPrefStore> user_prefs;
142 scoped_refptr<PrefStore> otr_prefs;
143 if (incognito_connector) {
144 // Init
145 InitIncognitoService(incognito_connector, user_connector);
146
147 // Connect
148 prefs::mojom::PrefStoreConnectorPtr pref_connector;
149 incognito_connector->BindInterface(prefs::mojom::kServiceName,
150 &pref_connector);
151 std::vector<PrefValueStore::PrefStoreType> in_process_types(
152 already_connected_types.begin(), already_connected_types.end());
153 user_prefs = make_scoped_refptr(new prefs::PersistentPrefStoreClient(
154 std::move(pref_connector), forked_registry,
155 std::move(in_process_types)));
156 // When using the pref service the user prefs from the underlying profile is
157 // treated differently; instead of wrapping the underlying user prefs we
158 // just slot them in as another read-only store with lower priority.
159 otr_prefs = CreateRegisteredPrefStore(incognito_connector, user_prefs_,
160 PrefValueStore::INCOGNITO_STORE);
161 } else {
162 OverlayUserPrefStore* incognito_pref_store =
163 new OverlayUserPrefStore(user_prefs_.get());
164 for (const char* overlay_pref_name : overlay_pref_names)
165 incognito_pref_store->RegisterOverlayPref(overlay_pref_name);
166 user_prefs = incognito_pref_store;
167 }
168
169 // Expose all read-only stores through the prefs service.
170 auto managed = CreateRegisteredPrefStore(incognito_connector, managed_prefs_,
171 PrefValueStore::MANAGED_STORE);
172 auto supervised =
173 CreateRegisteredPrefStore(incognito_connector, supervised_user_prefs_,
174 PrefValueStore::SUPERVISED_USER_STORE);
175 auto command_line =
176 CreateRegisteredPrefStore(incognito_connector, command_line_prefs_,
177 PrefValueStore::COMMAND_LINE_STORE);
178 auto recommended =
179 CreateRegisteredPrefStore(incognito_connector, recommended_prefs_,
180 PrefValueStore::RECOMMENDED_STORE);
181
182 std::unique_ptr<PrefServiceSyncable> pref_service(new PrefServiceSyncable(
183 pref_notifier,
184 new PrefValueStore(
185 managed.get(), supervised.get(),
186 CreateRegisteredPrefStore(incognito_connector,
187 incognito_extension_pref_store,
188 PrefValueStore::EXTENSION_STORE)
189 .get(),
190 command_line.get(), user_prefs.get(), recommended.get(),
191 forked_registry->defaults().get(), pref_notifier, otr_prefs.get()),
192 user_prefs.get(), forked_registry.get(), pref_model_associator_client_,
193 read_error_callback_, false));
194 return pref_service;
195 }
196
109 } // namespace sync_preferences 197 } // namespace sync_preferences
OLDNEW
« no previous file with comments | « components/sync_preferences/pref_service_syncable_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698