pref_registry_syncable.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2012 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/pref_registry/pref_registry_syncable.h"
  5. #include "base/files/file_path.h"
  6. #include "base/strings/string_number_conversions.h"
  7. #include "base/values.h"
  8. #include "build/chromeos_buildflags.h"
  9. #include "components/prefs/default_pref_store.h"
  10. namespace user_prefs {
  11. namespace {
  12. constexpr uint32_t kSyncablePrefFlags =
  13. #if BUILDFLAG(IS_CHROMEOS_ASH)
  14. PrefRegistrySyncable::SYNCABLE_OS_PREF |
  15. PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF |
  16. #endif
  17. PrefRegistrySyncable::SYNCABLE_PREF |
  18. PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF;
  19. } // namespace
  20. PrefRegistrySyncable::PrefRegistrySyncable() = default;
  21. PrefRegistrySyncable::~PrefRegistrySyncable() = default;
  22. void PrefRegistrySyncable::SetSyncableRegistrationCallback(
  23. SyncableRegistrationCallback cb) {
  24. callback_ = std::move(cb);
  25. }
  26. void PrefRegistrySyncable::OnPrefRegistered(const std::string& path,
  27. uint32_t flags) {
  28. // Tests that |flags| does not contain both SYNCABLE_PREF and
  29. // SYNCABLE_PRIORITY_PREF flags at the same time.
  30. DCHECK(!(flags & PrefRegistrySyncable::SYNCABLE_PREF) ||
  31. !(flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF));
  32. #if BUILDFLAG(IS_CHROMEOS_ASH)
  33. // Ditto for the mutually exclusive OS pref flags.
  34. DCHECK(!(flags & PrefRegistrySyncable::SYNCABLE_OS_PREF) ||
  35. !(flags & PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF));
  36. #endif
  37. if (flags & kSyncablePrefFlags) {
  38. if (callback_)
  39. callback_.Run(path, flags);
  40. }
  41. }
  42. scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() {
  43. // TODO(joi): We can directly reuse the same PrefRegistry once
  44. // PrefService no longer registers for callbacks on registration and
  45. // unregistration.
  46. scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable());
  47. registry->defaults_ = defaults_;
  48. registry->registration_flags_ = registration_flags_;
  49. registry->foreign_pref_keys_ = foreign_pref_keys_;
  50. return registry;
  51. }
  52. } // namespace user_prefs