| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 14 matching lines...) Expand all Loading... |
| 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 SyncableService, |
| 33 public base::NonThreadSafe { | 33 public base::NonThreadSafe { |
| 34 public: | 34 public: |
| 35 explicit PrefModelAssociator(PrefService* pref_service); | 35 PrefModelAssociator(); |
| 36 virtual ~PrefModelAssociator(); | 36 virtual ~PrefModelAssociator(); |
| 37 | 37 |
| 38 // SyncableService implementation. | 38 // SyncableService implementation. |
| 39 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 39 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; |
| 40 virtual SyncError ProcessSyncChanges( | 40 virtual SyncError ProcessSyncChanges( |
| 41 const tracked_objects::Location& from_here, | 41 const tracked_objects::Location& from_here, |
| 42 const SyncChangeList& change_list) OVERRIDE; | 42 const SyncChangeList& change_list) OVERRIDE; |
| 43 virtual SyncError MergeDataAndStartSyncing( | 43 virtual SyncError MergeDataAndStartSyncing( |
| 44 syncable::ModelType type, | 44 syncable::ModelType type, |
| 45 const SyncDataList& initial_sync_data, | 45 const SyncDataList& initial_sync_data, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 // begins). | 57 // begins). |
| 58 virtual void RegisterPref(const char* name); | 58 virtual void RegisterPref(const char* name); |
| 59 | 59 |
| 60 // Returns true if the specified preference is registered for syncing. | 60 // Returns true if the specified preference is registered for syncing. |
| 61 virtual bool IsPrefRegistered(const char* name); | 61 virtual bool IsPrefRegistered(const char* name); |
| 62 | 62 |
| 63 // Process a local preference change. This can trigger new SyncChanges being | 63 // Process a local preference change. This can trigger new SyncChanges being |
| 64 // sent to the syncer. | 64 // sent to the syncer. |
| 65 virtual void ProcessPrefChange(const std::string& name); | 65 virtual void ProcessPrefChange(const std::string& name); |
| 66 | 66 |
| 67 void SetPrefService(PrefService* pref_service); |
| 68 |
| 67 // Merges the value of local_pref into the supplied server_value and returns | 69 // Merges the value of local_pref into the supplied server_value and returns |
| 68 // the result (caller takes ownership). If there is a conflict, the server | 70 // the result (caller takes ownership). If there is a conflict, the server |
| 69 // value always takes precedence. Note that only certain preferences will | 71 // value always takes precedence. Note that only certain preferences will |
| 70 // actually be merged, all others will return a copy of the server value. See | 72 // actually be merged, all others will return a copy of the server value. See |
| 71 // the method's implementation for details. | 73 // the method's implementation for details. |
| 72 static base::Value* MergePreference( | 74 static base::Value* MergePreference( |
| 73 const PrefService::Preference& local_pref, | 75 const PrefService::Preference& local_pref, |
| 74 const base::Value& server_value); | 76 const base::Value& server_value); |
| 75 | 77 |
| 76 // Fills |sync_data| with a sync representation of the preference data | 78 // Fills |sync_data| with a sync representation of the preference data |
| 77 // provided. | 79 // provided. |
| 78 static bool CreatePrefSyncData(const std::string& name, | 80 static bool CreatePrefSyncData(const std::string& name, |
| 79 const base::Value& value, | 81 const base::Value& value, |
| 80 SyncData* sync_data); | 82 SyncData* sync_data); |
| 81 | 83 |
| 82 // Extract preference value and name from sync specifics. | 84 // Extract preference value and name from sync specifics. |
| 83 base::Value* ReadPreferenceSpecifics( | 85 base::Value* ReadPreferenceSpecifics( |
| 84 const sync_pb::PreferenceSpecifics& specifics, | 86 const sync_pb::PreferenceSpecifics& specifics, |
| 85 std::string* name); | 87 std::string* name); |
| 86 | 88 |
| 87 protected: | 89 protected: |
| 88 friend class ProfileSyncServicePreferenceTest; | 90 friend class ProfileSyncServicePreferenceTest; |
| 89 | 91 |
| 90 typedef std::map<std::string, SyncData> SyncDataMap; | 92 typedef std::map<std::string, SyncData> SyncDataMap; |
| 91 | 93 |
| 92 // For testing. | |
| 93 PrefModelAssociator(); | |
| 94 | |
| 95 // Create an association for a given preference. If |sync_pref| is valid, | 94 // Create an association for a given preference. If |sync_pref| is valid, |
| 96 // signifying that sync has data for this preference, we reconcile their data | 95 // signifying that sync has data for this preference, we reconcile their data |
| 97 // with ours and append a new UPDATE SyncChange to |sync_changes|. If | 96 // with ours and append a new UPDATE SyncChange to |sync_changes|. If |
| 98 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with | 97 // sync_pref is not set, we append an ADD SyncChange to |sync_changes| with |
| 99 // the current preference data. | 98 // the current preference data. |
| 100 // Note: We do not modify the sync data for preferences that are either | 99 // Note: We do not modify the sync data for preferences that are either |
| 101 // controlled by policy (are not user modifiable) or have their default value | 100 // controlled by policy (are not user modifiable) or have their default value |
| 102 // (are not user controlled). | 101 // (are not user controlled). |
| 103 void InitPrefAndAssociate(const SyncData& sync_pref, | 102 void InitPrefAndAssociate(const SyncData& sync_pref, |
| 104 const std::string& pref_name, | 103 const std::string& pref_name, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // The PrefService we are syncing to. | 136 // The PrefService we are syncing to. |
| 138 PrefService* pref_service_; | 137 PrefService* pref_service_; |
| 139 | 138 |
| 140 // Sync's SyncChange handler. We push all our changes through this. | 139 // Sync's SyncChange handler. We push all our changes through this. |
| 141 SyncChangeProcessor* sync_processor_; | 140 SyncChangeProcessor* sync_processor_; |
| 142 | 141 |
| 143 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); | 142 DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); |
| 144 }; | 143 }; |
| 145 | 144 |
| 146 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ | 145 #endif // CHROME_BROWSER_PREFS_PREF_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |