Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ |
| 6 #define CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ |
| 7 | 7 |
| 8 #include <list> | |
|
battre
2013/08/06 15:54:39
nit: not used.
Ken Rockot(use gerrit already)
2013/08/06 20:18:32
Done.
| |
| 8 #include <map> | 9 #include <map> |
| 9 #include <set> | 10 #include <set> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/containers/hash_tables.h" | |
| 16 #include "base/observer_list.h" | |
| 14 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "chrome/browser/prefs/synced_pref_observer.h" | |
| 15 #include "sync/api/sync_data.h" | 19 #include "sync/api/sync_data.h" |
| 16 #include "sync/api/syncable_service.h" | 20 #include "sync/api/syncable_service.h" |
| 17 | 21 |
| 18 class PrefRegistrySyncable; | 22 class PrefRegistrySyncable; |
| 19 class PrefServiceSyncable; | 23 class PrefServiceSyncable; |
| 20 | 24 |
| 21 namespace sync_pb { | 25 namespace sync_pb { |
| 22 class PreferenceSpecifics; | 26 class PreferenceSpecifics; |
| 23 } | 27 } |
| 24 | 28 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 94 |
| 91 // Extract preference value and name from sync specifics. | 95 // Extract preference value and name from sync specifics. |
| 92 base::Value* ReadPreferenceSpecifics( | 96 base::Value* ReadPreferenceSpecifics( |
| 93 const sync_pb::PreferenceSpecifics& specifics, | 97 const sync_pb::PreferenceSpecifics& specifics, |
| 94 std::string* name); | 98 std::string* name); |
| 95 | 99 |
| 96 // Returns true if the pref under the given name is pulled down from sync. | 100 // Returns true if the pref under the given name is pulled down from sync. |
| 97 // Note this does not refer to SYNCABLE_PREF. | 101 // Note this does not refer to SYNCABLE_PREF. |
| 98 bool IsPrefSynced(const std::string& name) const; | 102 bool IsPrefSynced(const std::string& name) const; |
| 99 | 103 |
| 104 // Adds a SyncedPrefObserver to watch for changes to a specific pref. | |
| 105 void AddSyncedPrefObserver(const std::string& name, | |
| 106 SyncedPrefObserver* observer); | |
| 107 | |
| 108 // Removes a SyncedPrefObserver from a pref's list of observers. | |
| 109 void RemoveSyncedPrefObserver(const std::string& name, | |
| 110 SyncedPrefObserver* observer); | |
| 111 | |
| 100 protected: | 112 protected: |
| 101 friend class ProfileSyncServicePreferenceTest; | 113 friend class ProfileSyncServicePreferenceTest; |
| 102 | 114 |
| 103 typedef std::map<std::string, syncer::SyncData> SyncDataMap; | 115 typedef std::map<std::string, syncer::SyncData> SyncDataMap; |
| 104 | 116 |
| 105 // Create an association for a given preference. If |sync_pref| is valid, | 117 // Create an association for a given preference. If |sync_pref| is valid, |
| 106 // signifying that sync has data for this preference, we reconcile their data | 118 // signifying that sync has data for this preference, we reconcile their data |
| 107 // with ours and append a new UPDATE SyncChange to |sync_changes|. If | 119 // with ours and append a new UPDATE SyncChange to |sync_changes|. If |
| 108 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with | 120 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with |
| 109 // the current preference data. | 121 // the current preference data. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // Sync's syncer::SyncChange handler. We push all our changes through this. | 162 // Sync's syncer::SyncChange handler. We push all our changes through this. |
| 151 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 163 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 152 | 164 |
| 153 // Sync's error handler. We use this to create sync errors. | 165 // Sync's error handler. We use this to create sync errors. |
| 154 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 166 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
| 155 | 167 |
| 156 // The datatype that this associator is responible for, either PREFERENCES or | 168 // The datatype that this associator is responible for, either PREFERENCES or |
| 157 // PRIORITY_PREFERENCES. | 169 // PRIORITY_PREFERENCES. |
| 158 syncer::ModelType type_; | 170 syncer::ModelType type_; |
| 159 | 171 |
| 172 private: | |
| 173 // Map prefs to lists of observers. Observers will receive notification when | |
| 174 // a pref changes, including the detail of whether or not the change came | |
| 175 // from sync. | |
| 176 typedef ObserverList<SyncedPrefObserver> SyncedPrefObserverList; | |
| 177 typedef base::hash_map<std::string, SyncedPrefObserverList*> | |
| 178 SyncedPrefObserverMap; | |
| 179 | |
| 180 void NotifySyncedPrefObservers(const std::string& path, bool from_sync); | |
|
battre
2013/08/06 15:54:39
can you make this function const?
Ken Rockot(use gerrit already)
2013/08/06 20:18:32
Done.
| |
| 181 | |
| 182 SyncedPrefObserverMap synced_pref_observers_; | |
| 183 | |
| 160 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); | 184 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); |
| 161 }; | 185 }; |
| 162 | 186 |
| 163 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ | 187 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |