| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_SYNC_GLUE_PREFERENCE_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_PREFERENCE_MODEL_ASSOCIATOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_PREFERENCE_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_PREFERENCE_MODEL_ASSOCIATOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "chrome/browser/pref_service.h" | 15 #include "chrome/browser/pref_service.h" |
| 16 #include "chrome/browser/sync/glue/model_associator.h" | 16 #include "chrome/browser/sync/glue/model_associator.h" |
| 17 #include "chrome/browser/sync/unrecoverable_error_handler.h" | 17 #include "chrome/browser/sync/unrecoverable_error_handler.h" |
| 18 | 18 |
| 19 class ProfileSyncService; | 19 class ProfileSyncService; |
| 20 class Value; | 20 class Value; |
| 21 | 21 |
| 22 namespace sync_api { | 22 namespace sync_api { |
| 23 class WriteNode; | 23 class WriteNode; |
| 24 class WriteTransaction; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace browser_sync { | 27 namespace browser_sync { |
| 27 | 28 |
| 28 class PreferenceChangeProcessor; | 29 class PreferenceChangeProcessor; |
| 29 | 30 |
| 30 static const char kPreferencesTag[] = "google_chrome_preferences"; | 31 static const char kPreferencesTag[] = "google_chrome_preferences"; |
| 31 | 32 |
| 32 // Contains all model association related logic: | 33 // Contains all model association related logic: |
| 33 // * Algorithm to associate preferences model and sync model. | 34 // * Algorithm to associate preferences model and sync model. |
| 34 class PreferenceModelAssociator | 35 class PreferenceModelAssociator |
| 35 : public PerDataTypeAssociatorInterface<PrefService::Preference, | 36 : public PerDataTypeAssociatorInterface<PrefService::Preference, |
| 36 std::string> { | 37 std::string> { |
| 37 public: | 38 public: |
| 38 static syncable::ModelType model_type() { return syncable::PREFERENCES; } | 39 static syncable::ModelType model_type() { return syncable::PREFERENCES; } |
| 39 explicit PreferenceModelAssociator(ProfileSyncService* sync_service); | 40 explicit PreferenceModelAssociator(ProfileSyncService* sync_service); |
| 40 virtual ~PreferenceModelAssociator(); | 41 virtual ~PreferenceModelAssociator(); |
| 41 | 42 |
| 42 // Returns the list of preference names that should be monitored for | 43 // Returns the list of preference names that should be monitored for |
| 43 // changes. Only preferences that are registered will be in this | 44 // changes. Only preferences that are registered will be in this |
| 44 // list. | 45 // list. |
| 45 const std::set<std::string>& synced_preferences() { | 46 const std::set<std::string>& synced_preferences() { |
| 46 return synced_preferences_; | 47 return synced_preferences_; |
| 47 } | 48 } |
| 48 | 49 |
| 50 // Create an association for a given preference. A sync node is created if |
| 51 // necessary and the value is read from or written to the node as appropriate. |
| 52 bool InitPrefNodeAndAssociate(sync_api::WriteTransaction* trans, |
| 53 const sync_api::BaseNode& root, |
| 54 const PrefService::Preference* pref); |
| 55 |
| 49 // PerDataTypeAssociatorInterface implementation. | 56 // PerDataTypeAssociatorInterface implementation. |
| 50 // | 57 // |
| 51 // Iterates through the sync model looking for matched pairs of items. | 58 // Iterates through the sync model looking for matched pairs of items. |
| 52 virtual bool AssociateModels(); | 59 virtual bool AssociateModels(); |
| 53 | 60 |
| 54 // Clears all associations. | 61 // Clears all associations. |
| 55 virtual bool DisassociateModels(); | 62 virtual bool DisassociateModels(); |
| 56 | 63 |
| 57 // Returns whether the sync model has nodes other than the permanent tagged | 64 // Returns whether the sync model has nodes other than the permanent tagged |
| 58 // nodes. | 65 // nodes. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 133 |
| 127 PreferenceNameToSyncIdMap id_map_; | 134 PreferenceNameToSyncIdMap id_map_; |
| 128 SyncIdToPreferenceNameMap id_map_inverse_; | 135 SyncIdToPreferenceNameMap id_map_inverse_; |
| 129 | 136 |
| 130 DISALLOW_COPY_AND_ASSIGN(PreferenceModelAssociator); | 137 DISALLOW_COPY_AND_ASSIGN(PreferenceModelAssociator); |
| 131 }; | 138 }; |
| 132 | 139 |
| 133 } // namespace browser_sync | 140 } // namespace browser_sync |
| 134 | 141 |
| 135 #endif // CHROME_BROWSER_SYNC_GLUE_PREFERENCE_MODEL_ASSOCIATOR_H_ | 142 #endif // CHROME_BROWSER_SYNC_GLUE_PREFERENCE_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |