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_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 class ProfileSyncService; | 25 class ProfileSyncService; |
26 class WebDatabase; | 26 class WebDatabase; |
27 | 27 |
28 namespace sync_api { | 28 namespace sync_api { |
29 class WriteTransaction; | 29 class WriteTransaction; |
30 } | 30 } |
31 | 31 |
32 namespace browser_sync { | 32 namespace browser_sync { |
33 | 33 |
| 34 extern const char kAutofillProfileTag[]; |
| 35 |
34 class AutofillChangeProcessor; | 36 class AutofillChangeProcessor; |
35 class UnrecoverableErrorHandler; | 37 class UnrecoverableErrorHandler; |
36 | 38 |
37 // Contains all model association related logic: | 39 // Contains all model association related logic: |
38 // * Algorithm to associate autofill model and sync model. | 40 // * Algorithm to associate autofill model and sync model. |
39 // We do not check if we have local data before this run; we always | 41 // We do not check if we have local data before this run; we always |
40 // merge and sync. | 42 // merge and sync. |
41 class AutofillProfileModelAssociator | 43 class AutofillProfileModelAssociator |
42 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 44 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
43 public: | 45 public: |
(...skipping 18 matching lines...) Expand all Loading... |
62 // Clears all associations. | 64 // Clears all associations. |
63 virtual bool DisassociateModels(); | 65 virtual bool DisassociateModels(); |
64 | 66 |
65 // [TODO] The has_nodes out param is true if the sync model has nodes other | 67 // [TODO] The has_nodes out param is true if the sync model has nodes other |
66 // than the permanent tagged nodes. | 68 // than the permanent tagged nodes. |
67 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); | 69 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); |
68 | 70 |
69 // See ModelAssociator interface. | 71 // See ModelAssociator interface. |
70 virtual void AbortAssociation(); | 72 virtual void AbortAssociation(); |
71 | 73 |
72 // [TODO]Not implemented. Does not seemt to be necessary. | 74 virtual const std::string* GetChromeNodeFromSyncId(int64 sync_id); |
73 virtual const std::string* GetChromeNodeFromSyncId( | |
74 int64 sync_id) { | |
75 return NULL; | |
76 } | |
77 | 75 |
78 // [TODO]Not implemented. Does not seem to be necessary. | 76 // [TODO]Not implemented. |
79 virtual bool InitSyncNodeFromChromeId(std::string node_id, | 77 virtual bool InitSyncNodeFromChromeId(std::string node_id, |
80 sync_api::BaseNode* sync_node) { | 78 sync_api::BaseNode* sync_node) { |
81 return false; | 79 return false; |
82 } | 80 } |
83 | 81 |
84 // Returns the sync id for the given autofill name, or sync_api::kInvalidId | 82 // Returns the sync id for the given autofill name, or sync_api::kInvalidId |
85 // if the autofill name is not associated to any sync id. | 83 // if the autofill name is not associated to any sync id. |
86 virtual int64 GetSyncIdFromChromeId(std::string node_id); | 84 virtual int64 GetSyncIdFromChromeId(std::string node_id); |
87 | 85 |
88 // Associates the given autofill name with the given sync id. | 86 // Associates the given autofill name with the given sync id. |
89 virtual void Associate(const std::string* node, int64 sync_id); | 87 virtual void Associate(const std::string* node, int64 sync_id); |
90 | 88 |
91 // Remove the association that corresponds to the given sync id. | 89 // Remove the association that corresponds to the given sync id. |
92 virtual void Disassociate(int64 sync_id); | 90 virtual void Disassociate(int64 sync_id); |
93 | 91 |
94 // [TODO] Returns whether a node with the | 92 // [TODO] Returns whether a node with the |
95 // given permanent tag was found and update | 93 // given permanent tag was found and update |
96 // |sync_id| with that node's id. No current use. To Implement | 94 // |sync_id| with that node's id. No current use. To Implement |
97 // only for completeness. | 95 // only for completeness. |
98 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { | 96 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); |
99 return false; | |
100 } | |
101 | 97 |
102 // Returns sync service instance. | 98 // Returns sync service instance. |
103 ProfileSyncService* sync_service() { return sync_service_; } | 99 ProfileSyncService* sync_service() { return sync_service_; } |
104 | 100 |
| 101 static bool OverwriteProfileWithServerData( |
| 102 AutoFillProfile* merge_into, |
| 103 const sync_pb::AutofillProfileSpecifics& specifics); |
| 104 |
105 protected: | 105 protected: |
106 AutofillProfileModelAssociator() {} | 106 AutofillProfileModelAssociator() {} |
107 virtual sync_api::ReadNode* GetReadNode(sync_api::WriteTransaction *trans); | |
108 bool TraverseAndAssociateChromeAutoFillProfiles( | 107 bool TraverseAndAssociateChromeAutoFillProfiles( |
109 sync_api::WriteTransaction* write_trans, | 108 sync_api::WriteTransaction* write_trans, |
110 const sync_api::ReadNode& autofill_root, | 109 const sync_api::ReadNode& autofill_root, |
111 const std::vector<AutoFillProfile*>& all_profiles_from_db, | 110 const std::vector<AutoFillProfile*>& all_profiles_from_db, |
112 std::set<std::string>* current_profiles, | 111 std::set<std::string>* current_profiles, |
113 std::vector<AutoFillProfile*>* updated_profiles, | 112 std::vector<AutoFillProfile*>* updated_profiles, |
114 std::vector<AutoFillProfile*>* new_profiles, | 113 std::vector<AutoFillProfile*>* new_profiles, |
115 std::vector<std::string>* profiles_to_delete); | 114 std::vector<std::string>* profiles_to_delete); |
116 | 115 |
117 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response | 116 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response |
(...skipping 14 matching lines...) Expand all Loading... |
132 std::set<std::string>* current_profiles, | 131 std::set<std::string>* current_profiles, |
133 std::vector<std::string>* profiles_to_delete); | 132 std::vector<std::string>* profiles_to_delete); |
134 | 133 |
135 // Once the above traversals are complete, we traverse the sync model to | 134 // Once the above traversals are complete, we traverse the sync model to |
136 // associate all remaining nodes. | 135 // associate all remaining nodes. |
137 bool TraverseAndAssociateAllSyncNodes( | 136 bool TraverseAndAssociateAllSyncNodes( |
138 sync_api::WriteTransaction* write_trans, | 137 sync_api::WriteTransaction* write_trans, |
139 const sync_api::ReadNode& autofill_root, | 138 const sync_api::ReadNode& autofill_root, |
140 DataBundle* bundle); | 139 DataBundle* bundle); |
141 | 140 |
142 static bool OverwriteProfileWithServerData( | |
143 AutoFillProfile* merge_into, | |
144 const sync_pb::AutofillProfileSpecifics& specifics); | |
145 | |
146 private: | 141 private: |
147 typedef std::map<std::string, int64> AutofillToSyncIdMap; | 142 typedef std::map<std::string, int64> AutofillToSyncIdMap; |
148 typedef std::map<int64, std::string> SyncIdToAutofillMap; | 143 typedef std::map<int64, std::string> SyncIdToAutofillMap; |
149 | 144 |
150 // A convenience wrapper of a bunch of state we pass around while associating | 145 // A convenience wrapper of a bunch of state we pass around while associating |
151 // models, and send to the WebDatabase for persistence. | 146 // models, and send to the WebDatabase for persistence. |
152 // struct DataBundle; | 147 // struct DataBundle; |
153 | 148 |
154 // Helper to query WebDatabase for the current autofill state. | 149 // Helper to query WebDatabase for the current autofill state. |
155 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); | 150 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 std::set<std::string> current_profiles; | 186 std::set<std::string> current_profiles; |
192 std::vector<std::string> profiles_to_delete; | 187 std::vector<std::string> profiles_to_delete; |
193 std::vector<AutoFillProfile*> updated_profiles; | 188 std::vector<AutoFillProfile*> updated_profiles; |
194 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. | 189 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. |
195 ~DataBundle() { STLDeleteElements(&new_profiles); } | 190 ~DataBundle() { STLDeleteElements(&new_profiles); } |
196 }; | 191 }; |
197 | 192 |
198 } // namespace browser_sync | 193 } // namespace browser_sync |
199 | 194 |
200 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 195 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
OLD | NEW |