pref_service_syncable_factory.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "components/sync_preferences/pref_service_syncable_factory.h"
  5. #include <memory>
  6. #include "base/trace_event/trace_event.h"
  7. #include "build/build_config.h"
  8. #include "components/policy/core/browser/browser_policy_connector.h"
  9. #include "components/policy/core/browser/configuration_policy_pref_store.h"
  10. #include "components/policy/core/common/policy_service.h"
  11. #include "components/policy/core/common/policy_types.h"
  12. #include "components/pref_registry/pref_registry_syncable.h"
  13. #include "components/prefs/default_pref_store.h"
  14. #include "components/prefs/pref_notifier_impl.h"
  15. #include "components/prefs/pref_value_store.h"
  16. #include "components/sync_preferences/pref_service_syncable.h"
  17. namespace sync_preferences {
  18. PrefServiceSyncableFactory::PrefServiceSyncableFactory() = default;
  19. PrefServiceSyncableFactory::~PrefServiceSyncableFactory() = default;
  20. void PrefServiceSyncableFactory::SetManagedPolicies(
  21. policy::PolicyService* service,
  22. policy::BrowserPolicyConnector* connector) {
  23. set_managed_prefs(new policy::ConfigurationPolicyPrefStore(
  24. connector, service, connector->GetHandlerList(),
  25. policy::POLICY_LEVEL_MANDATORY));
  26. }
  27. void PrefServiceSyncableFactory::SetRecommendedPolicies(
  28. policy::PolicyService* service,
  29. policy::BrowserPolicyConnector* connector) {
  30. set_recommended_prefs(new policy::ConfigurationPolicyPrefStore(
  31. connector, service, connector->GetHandlerList(),
  32. policy::POLICY_LEVEL_RECOMMENDED));
  33. }
  34. void PrefServiceSyncableFactory::SetPrefModelAssociatorClient(
  35. PrefModelAssociatorClient* pref_model_associator_client) {
  36. pref_model_associator_client_ = pref_model_associator_client;
  37. }
  38. std::unique_ptr<PrefServiceSyncable> PrefServiceSyncableFactory::CreateSyncable(
  39. scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry) {
  40. TRACE_EVENT0("browser", "PrefServiceSyncableFactory::CreateSyncable");
  41. auto pref_notifier = std::make_unique<PrefNotifierImpl>();
  42. auto pref_value_store = std::make_unique<PrefValueStore>(
  43. managed_prefs_.get(), supervised_user_prefs_.get(),
  44. extension_prefs_.get(), standalone_browser_prefs_.get(),
  45. command_line_prefs_.get(), user_prefs_.get(), recommended_prefs_.get(),
  46. pref_registry->defaults().get(), pref_notifier.get(),
  47. /*delegate=*/nullptr);
  48. return std::make_unique<PrefServiceSyncable>(
  49. std::move(pref_notifier), std::move(pref_value_store), user_prefs_.get(),
  50. standalone_browser_prefs_.get(), std::move(pref_registry),
  51. pref_model_associator_client_, read_error_callback_, async_);
  52. }
  53. } // namespace sync_preferences