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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/gtest_prod_util.h" | |
16 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
17 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
18 #include "chrome/browser/prefs/synced_pref_observer.h" | 17 #include "chrome/browser/prefs/synced_pref_observer.h" |
19 #include "sync/api/sync_data.h" | 18 #include "sync/api/sync_data.h" |
20 #include "sync/api/syncable_service.h" | 19 #include "sync/api/syncable_service.h" |
21 | 20 |
22 class PrefRegistrySyncable; | 21 class PrefRegistrySyncable; |
23 class PrefServiceSyncable; | 22 class PrefServiceSyncable; |
24 | 23 |
25 namespace sync_pb { | 24 namespace sync_pb { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 protected: | 109 protected: |
111 friend class PrefServiceSyncableTest; | 110 friend class PrefServiceSyncableTest; |
112 | 111 |
113 typedef std::map<std::string, syncer::SyncData> SyncDataMap; | 112 typedef std::map<std::string, syncer::SyncData> SyncDataMap; |
114 | 113 |
115 // Create an association for a given preference. If |sync_pref| is valid, | 114 // Create an association for a given preference. If |sync_pref| is valid, |
116 // signifying that sync has data for this preference, we reconcile their data | 115 // signifying that sync has data for this preference, we reconcile their data |
117 // with ours and append a new UPDATE SyncChange to |sync_changes|. If | 116 // with ours and append a new UPDATE SyncChange to |sync_changes|. If |
118 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with | 117 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with |
119 // the current preference data. | 118 // the current preference data. |
120 // |migrated_preference_list| points to a vector that may be updated with a | |
121 // string containing the old name of the preference described by |pref_name|. | |
122 // Note: We do not modify the sync data for preferences that are either | 119 // Note: We do not modify the sync data for preferences that are either |
123 // controlled by policy (are not user modifiable) or have their default value | 120 // controlled by policy (are not user modifiable) or have their default value |
124 // (are not user controlled). | 121 // (are not user controlled). |
125 void InitPrefAndAssociate(const syncer::SyncData& sync_pref, | 122 void InitPrefAndAssociate(const syncer::SyncData& sync_pref, |
126 const std::string& pref_name, | 123 const std::string& pref_name, |
127 syncer::SyncChangeList* sync_changes, | 124 syncer::SyncChangeList* sync_changes); |
128 SyncDataMap* migrated_preference_list); | |
129 | 125 |
130 static base::Value* MergeListValues( | 126 static base::Value* MergeListValues( |
131 const base::Value& from_value, const base::Value& to_value); | 127 const base::Value& from_value, const base::Value& to_value); |
132 static base::Value* MergeDictionaryValues(const base::Value& from_value, | 128 static base::Value* MergeDictionaryValues(const base::Value& from_value, |
133 const base::Value& to_value); | 129 const base::Value& to_value); |
134 | 130 |
135 // Returns whether a given preference name is a new name of a migrated | |
136 // preference. Exposed here for testing. | |
137 static bool IsMigratedPreference(const char* preference_name); | |
138 static bool IsOldMigratedPreference(const char* old_preference_name); | |
139 | |
140 // Do we have an active association between the preferences and sync models? | 131 // Do we have an active association between the preferences and sync models? |
141 // Set when start syncing, reset in StopSyncing. While this is not set, we | 132 // Set when start syncing, reset in StopSyncing. While this is not set, we |
142 // ignore any local preference changes (when we start syncing we will look | 133 // ignore any local preference changes (when we start syncing we will look |
143 // up the most recent values anyways). | 134 // up the most recent values anyways). |
144 bool models_associated_; | 135 bool models_associated_; |
145 | 136 |
146 // Whether we're currently processing changes from the syncer. While this is | 137 // Whether we're currently processing changes from the syncer. While this is |
147 // true, we ignore any local preference changes, since we triggered them. | 138 // true, we ignore any local preference changes, since we triggered them. |
148 bool processing_syncer_changes_; | 139 bool processing_syncer_changes_; |
149 | 140 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 SyncedPrefObserverMap; | 175 SyncedPrefObserverMap; |
185 | 176 |
186 void NotifySyncedPrefObservers(const std::string& path, bool from_sync) const; | 177 void NotifySyncedPrefObservers(const std::string& path, bool from_sync) const; |
187 | 178 |
188 SyncedPrefObserverMap synced_pref_observers_; | 179 SyncedPrefObserverMap synced_pref_observers_; |
189 | 180 |
190 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); | 181 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); |
191 }; | 182 }; |
192 | 183 |
193 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ | 184 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ |
OLD | NEW |