Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / components / sync_preferences / pref_service_syncable.h
1 // Copyright 2012 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 #ifndef COMPONENTS_SYNC_PREFERENCES_PREF_SERVICE_SYNCABLE_H_
6 #define COMPONENTS_SYNC_PREFERENCES_PREF_SERVICE_SYNCABLE_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "base/callback_forward.h"
15 #include "base/observer_list.h"
16 #include "build/chromeos_buildflags.h"
17 #include "components/pref_registry/pref_registry_syncable.h"
18 #include "components/prefs/pref_service.h"
19 #include "components/sync_preferences/pref_model_associator.h"
20
21 class PrefValueStore;
22
23 namespace syncer {
24 class SyncableService;
25 }
26
27 namespace sync_preferences {
28
29 class PrefModelAssociatorClient;
30 class PrefServiceSyncableObserver;
31 class SyncedPrefObserver;
32
33 // A PrefService that can be synced. Users are forced to declare
34 // whether preferences are syncable or not when registering them to
35 // this PrefService.
36 class PrefServiceSyncable : public PrefService {
37  public:
38   // You may wish to use PrefServiceFactory or one of its subclasses
39   // for simplified construction.
40   PrefServiceSyncable(
41       std::unique_ptr<PrefNotifierImpl> pref_notifier,
42       std::unique_ptr<PrefValueStore> pref_value_store,
43       scoped_refptr<PersistentPrefStore> user_prefs,
44       scoped_refptr<PersistentPrefStore> standalone_browser_prefs,
45       scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry,
46       const PrefModelAssociatorClient* pref_model_associator_client,
47       base::RepeatingCallback<void(PersistentPrefStore::PrefReadError)>
48           read_error_callback,
49       bool async);
50
51   PrefServiceSyncable(const PrefServiceSyncable&) = delete;
52   PrefServiceSyncable& operator=(const PrefServiceSyncable&) = delete;
53
54   ~PrefServiceSyncable() override;
55
56   // Creates an incognito copy of the pref service that shares most pref stores
57   // but uses a fresh non-persistent overlay for the user pref store and an
58   // individual extension pref store (to cache the effective extension prefs for
59   // incognito windows). |persistent_pref_names| is a list of preference names
60   // whose changes will be persisted by the returned incognito pref service.
61   std::unique_ptr<PrefServiceSyncable> CreateIncognitoPrefService(
62       PrefStore* incognito_extension_pref_store,
63       const std::vector<const char*>& persistent_pref_names);
64
65   // Returns true if preferences state has synchronized with the remote
66   // preferences. If true is returned it can be assumed the local preferences
67   // has applied changes from the remote preferences. The two may not be
68   // identical if a change is in flight (from either side).
69   //
70   // TODO(albertb): Given that we now support priority preferences, callers of
71   // this method are likely better off making the preferences they care about
72   // into priority preferences and calling IsPrioritySyncing().
73   bool IsSyncing();
74
75   // Returns true if priority preferences state has synchronized with the remote
76   // priority preferences.
77   bool IsPrioritySyncing();
78
79 #if BUILDFLAG(IS_CHROMEOS_ASH)
80   // As above, but for OS preferences.
81   bool AreOsPrefsSyncing();
82
83   // As above, but for OS priority preferences.
84   bool AreOsPriorityPrefsSyncing();
85 #endif
86
87   void AddObserver(PrefServiceSyncableObserver* observer);
88   void RemoveObserver(PrefServiceSyncableObserver* observer);
89
90   syncer::SyncableService* GetSyncableService(const syncer::ModelType& type);
91
92   // Do not call this after having derived an incognito or per tab pref service.
93   void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) override;
94
95   void AddSyncedPrefObserver(const std::string& name,
96                              SyncedPrefObserver* observer);
97   void RemoveSyncedPrefObserver(const std::string& name,
98                                 SyncedPrefObserver* observer);
99
100  private:
101   friend class PrefModelAssociator;
102
103   void AddRegisteredSyncablePreference(const std::string& path, uint32_t flags);
104
105   // Invoked internally when the syncing state changes for a type of pref.
106   void OnIsSyncingChanged();
107
108   // Process a local preference change. This can trigger new SyncChanges being
109   // sent to the syncer.
110   void ProcessPrefChange(const std::string& name);
111
112   // Whether CreateIncognitoPrefService() has been called to create a
113   // "forked" PrefService.
114   bool pref_service_forked_;
115
116   PrefModelAssociator pref_sync_associator_;
117   PrefModelAssociator priority_pref_sync_associator_;
118
119 #if BUILDFLAG(IS_CHROMEOS_ASH)
120   // Associators for Chrome OS system preferences.
121   PrefModelAssociator os_pref_sync_associator_;
122   PrefModelAssociator os_priority_pref_sync_associator_;
123 #endif
124
125   const scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
126
127   base::ObserverList<PrefServiceSyncableObserver>::Unchecked observer_list_;
128 };
129
130 }  // namespace sync_preferences
131
132 #endif  // COMPONENTS_SYNC_PREFERENCES_PREF_SERVICE_SYNCABLE_H_