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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class Value; | 25 class Value; |
26 } | 26 } |
27 | 27 |
28 // Contains all preference sync related logic. | 28 // Contains all preference sync related logic. |
29 // TODO(sync): Merge this into PrefService once we separate the profile | 29 // TODO(sync): Merge this into PrefService once we separate the profile |
30 // PrefService from the local state PrefService. | 30 // PrefService from the local state PrefService. |
31 class PrefModelAssociator | 31 class PrefModelAssociator |
32 : public SyncableService, | 32 : public csync::SyncableService, |
33 public base::NonThreadSafe { | 33 public base::NonThreadSafe { |
34 public: | 34 public: |
35 PrefModelAssociator(); | 35 PrefModelAssociator(); |
36 virtual ~PrefModelAssociator(); | 36 virtual ~PrefModelAssociator(); |
37 | 37 |
38 // SyncableService implementation. | 38 // csync::SyncableService implementation. |
39 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 39 virtual csync::SyncDataList GetAllSyncData( |
40 virtual SyncError ProcessSyncChanges( | 40 syncable::ModelType type) const OVERRIDE; |
| 41 virtual csync::SyncError ProcessSyncChanges( |
41 const tracked_objects::Location& from_here, | 42 const tracked_objects::Location& from_here, |
42 const SyncChangeList& change_list) OVERRIDE; | 43 const csync::SyncChangeList& change_list) OVERRIDE; |
43 virtual SyncError MergeDataAndStartSyncing( | 44 virtual csync::SyncError MergeDataAndStartSyncing( |
44 syncable::ModelType type, | 45 syncable::ModelType type, |
45 const SyncDataList& initial_sync_data, | 46 const csync::SyncDataList& initial_sync_data, |
46 scoped_ptr<SyncChangeProcessor> sync_processor, | 47 scoped_ptr<csync::SyncChangeProcessor> sync_processor, |
47 scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; | 48 scoped_ptr<csync::SyncErrorFactory> sync_error_factory) OVERRIDE; |
48 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | 49 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; |
49 | 50 |
50 // Returns the list of preference names that are registered as syncable, and | 51 // Returns the list of preference names that are registered as syncable, and |
51 // hence should be monitored for changes. | 52 // hence should be monitored for changes. |
52 std::set<std::string> registered_preferences() const; | 53 std::set<std::string> registered_preferences() const; |
53 | 54 |
54 // Register a preference with the specified name for syncing. We do not care | 55 // Register a preference with the specified name for syncing. We do not care |
55 // about the type at registration time, but when changes arrive from the | 56 // about the type at registration time, but when changes arrive from the |
56 // syncer, we check if they can be applied and if not drop them. | 57 // syncer, we check if they can be applied and if not drop them. |
57 // Note: This should only be called at profile startup time (before sync | 58 // Note: This should only be called at profile startup time (before sync |
(...skipping 19 matching lines...) Expand all Loading... |
77 // actually be merged, all others will return a copy of the server value. See | 78 // actually be merged, all others will return a copy of the server value. See |
78 // the method's implementation for details. | 79 // the method's implementation for details. |
79 static base::Value* MergePreference( | 80 static base::Value* MergePreference( |
80 const PrefService::Preference& local_pref, | 81 const PrefService::Preference& local_pref, |
81 const base::Value& server_value); | 82 const base::Value& server_value); |
82 | 83 |
83 // Fills |sync_data| with a sync representation of the preference data | 84 // Fills |sync_data| with a sync representation of the preference data |
84 // provided. | 85 // provided. |
85 static bool CreatePrefSyncData(const std::string& name, | 86 static bool CreatePrefSyncData(const std::string& name, |
86 const base::Value& value, | 87 const base::Value& value, |
87 SyncData* sync_data); | 88 csync::SyncData* sync_data); |
88 | 89 |
89 // Extract preference value and name from sync specifics. | 90 // Extract preference value and name from sync specifics. |
90 base::Value* ReadPreferenceSpecifics( | 91 base::Value* ReadPreferenceSpecifics( |
91 const sync_pb::PreferenceSpecifics& specifics, | 92 const sync_pb::PreferenceSpecifics& specifics, |
92 std::string* name); | 93 std::string* name); |
93 | 94 |
94 protected: | 95 protected: |
95 friend class ProfileSyncServicePreferenceTest; | 96 friend class ProfileSyncServicePreferenceTest; |
96 | 97 |
97 typedef std::map<std::string, SyncData> SyncDataMap; | 98 typedef std::map<std::string, csync::SyncData> SyncDataMap; |
98 | 99 |
99 // Create an association for a given preference. If |sync_pref| is valid, | 100 // Create an association for a given preference. If |sync_pref| is valid, |
100 // signifying that sync has data for this preference, we reconcile their data | 101 // signifying that sync has data for this preference, we reconcile their data |
101 // with ours and append a new UPDATE SyncChange to |sync_changes|. If | 102 // with ours and append a new UPDATE SyncChange to |sync_changes|. If |
102 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with | 103 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with |
103 // the current preference data. | 104 // the current preference data. |
104 // Note: We do not modify the sync data for preferences that are either | 105 // Note: We do not modify the sync data for preferences that are either |
105 // controlled by policy (are not user modifiable) or have their default value | 106 // controlled by policy (are not user modifiable) or have their default value |
106 // (are not user controlled). | 107 // (are not user controlled). |
107 void InitPrefAndAssociate(const SyncData& sync_pref, | 108 void InitPrefAndAssociate(const csync::SyncData& sync_pref, |
108 const std::string& pref_name, | 109 const std::string& pref_name, |
109 SyncChangeList* sync_changes); | 110 csync::SyncChangeList* sync_changes); |
110 | 111 |
111 static base::Value* MergeListValues( | 112 static base::Value* MergeListValues( |
112 const base::Value& from_value, const base::Value& to_value); | 113 const base::Value& from_value, const base::Value& to_value); |
113 static base::Value* MergeDictionaryValues(const base::Value& from_value, | 114 static base::Value* MergeDictionaryValues(const base::Value& from_value, |
114 const base::Value& to_value); | 115 const base::Value& to_value); |
115 | 116 |
116 // Do we have an active association between the preferences and sync models? | 117 // Do we have an active association between the preferences and sync models? |
117 // Set when start syncing, reset in StopSyncing. While this is not set, we | 118 // Set when start syncing, reset in StopSyncing. While this is not set, we |
118 // ignore any local preference changes (when we start syncing we will look | 119 // ignore any local preference changes (when we start syncing we will look |
119 // up the most recent values anyways). | 120 // up the most recent values anyways). |
(...skipping 14 matching lines...) Expand all Loading... |
134 // policy controlled). | 135 // policy controlled). |
135 // Note: this set never decreases, only grows to eventually match | 136 // Note: this set never decreases, only grows to eventually match |
136 // registered_preferences_ as more preferences are synced. It determines | 137 // registered_preferences_ as more preferences are synced. It determines |
137 // whether a preference change should update an existing sync node or create | 138 // whether a preference change should update an existing sync node or create |
138 // a new sync node. | 139 // a new sync node. |
139 PreferenceSet synced_preferences_; | 140 PreferenceSet synced_preferences_; |
140 | 141 |
141 // The PrefService we are syncing to. | 142 // The PrefService we are syncing to. |
142 PrefService* pref_service_; | 143 PrefService* pref_service_; |
143 | 144 |
144 // Sync's SyncChange handler. We push all our changes through this. | 145 // Sync's csync::SyncChange handler. We push all our changes through this. |
145 scoped_ptr<SyncChangeProcessor> sync_processor_; | 146 scoped_ptr<csync::SyncChangeProcessor> sync_processor_; |
146 | 147 |
147 // Sync's error handler. We use this to create sync errors. | 148 // Sync's error handler. We use this to create sync errors. |
148 scoped_ptr<SyncErrorFactory> sync_error_factory_; | 149 scoped_ptr<csync::SyncErrorFactory> sync_error_factory_; |
149 | 150 |
150 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); | 151 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); |
151 }; | 152 }; |
152 | 153 |
153 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ | 154 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ |
OLD | NEW |