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