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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 89 |
88 // TODO(lipalani) Bug 64111. Returns whether a node with the | 90 // TODO(lipalani) Bug 64111. Returns whether a node with the |
89 // given permanent tag was found and update | 91 // given permanent tag was found and update |
90 // |sync_id| with that node's id. No current use. To Implement | 92 // |sync_id| with that node's id. No current use. To Implement |
91 // only for completeness. | 93 // only for completeness. |
92 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); | 94 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); |
93 | 95 |
94 // Returns sync service instance. | 96 // Returns sync service instance. |
95 ProfileSyncService* sync_service() { return sync_service_; } | 97 ProfileSyncService* sync_service() { return sync_service_; } |
96 | 98 |
| 99 static bool OverwriteProfileWithServerData( |
| 100 AutoFillProfile* merge_into, |
| 101 const sync_pb::AutofillProfileSpecifics& specifics); |
| 102 |
97 protected: | 103 protected: |
98 AutofillProfileModelAssociator(); | 104 AutofillProfileModelAssociator(); |
99 bool TraverseAndAssociateChromeAutoFillProfiles( | 105 bool TraverseAndAssociateChromeAutoFillProfiles( |
100 sync_api::WriteTransaction* write_trans, | 106 sync_api::WriteTransaction* write_trans, |
101 const sync_api::ReadNode& autofill_root, | 107 const sync_api::ReadNode& autofill_root, |
102 const std::vector<AutoFillProfile*>& all_profiles_from_db, | 108 const std::vector<AutoFillProfile*>& all_profiles_from_db, |
103 std::set<std::string>* current_profiles, | 109 std::set<std::string>* current_profiles, |
104 std::vector<AutoFillProfile*>* updated_profiles, | 110 std::vector<AutoFillProfile*>* updated_profiles, |
105 std::vector<AutoFillProfile*>* new_profiles, | 111 std::vector<AutoFillProfile*>* new_profiles, |
106 std::vector<std::string>* profiles_to_delete); | 112 std::vector<std::string>* profiles_to_delete); |
(...skipping 16 matching lines...) Expand all Loading... |
123 std::set<std::string>* current_profiles, | 129 std::set<std::string>* current_profiles, |
124 std::vector<std::string>* profiles_to_delete); | 130 std::vector<std::string>* profiles_to_delete); |
125 | 131 |
126 // Once the above traversals are complete, we traverse the sync model to | 132 // Once the above traversals are complete, we traverse the sync model to |
127 // associate all remaining nodes. | 133 // associate all remaining nodes. |
128 bool TraverseAndAssociateAllSyncNodes( | 134 bool TraverseAndAssociateAllSyncNodes( |
129 sync_api::WriteTransaction* write_trans, | 135 sync_api::WriteTransaction* write_trans, |
130 const sync_api::ReadNode& autofill_root, | 136 const sync_api::ReadNode& autofill_root, |
131 DataBundle* bundle); | 137 DataBundle* bundle); |
132 | 138 |
133 static bool OverwriteProfileWithServerData( | |
134 AutoFillProfile* merge_into, | |
135 const sync_pb::AutofillProfileSpecifics& specifics); | |
136 | |
137 private: | 139 private: |
138 typedef std::map<std::string, int64> AutofillToSyncIdMap; | 140 typedef std::map<std::string, int64> AutofillToSyncIdMap; |
139 typedef std::map<int64, std::string> SyncIdToAutofillMap; | 141 typedef std::map<int64, std::string> SyncIdToAutofillMap; |
140 | 142 |
141 // A convenience wrapper of a bunch of state we pass around while associating | 143 // A convenience wrapper of a bunch of state we pass around while associating |
142 // models, and send to the WebDatabase for persistence. | 144 // models, and send to the WebDatabase for persistence. |
143 // struct DataBundle; | 145 // struct DataBundle; |
144 | 146 |
145 // Helper to query WebDatabase for the current autofill state. | 147 // Helper to query WebDatabase for the current autofill state. |
146 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); | 148 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); |
147 | 149 |
148 static bool MergeField(FormGroup* f, | 150 static bool MergeField(FormGroup* f, |
149 AutoFillFieldType t, | 151 AutoFillFieldType t, |
150 const std::string& specifics_field); | 152 const std::string& specifics_field); |
151 | 153 |
152 // Helper to persist any changes that occured during model association to | 154 // Helper to persist any changes that occured during model association to |
153 // the WebDatabase. | 155 // the WebDatabase. |
154 bool SaveChangesToWebData(const DataBundle& bundle); | 156 bool SaveChangesToWebData(const DataBundle& bundle); |
155 | 157 |
156 // Called at various points in model association to determine if the | 158 // Called at various points in model association to determine if the |
157 // user requested an abort. | 159 // user requested an abort. |
158 bool IsAbortPending(); | 160 bool IsAbortPending(); |
159 | 161 |
160 int64 FindSyncNodeWithProfile(sync_api::WriteTransaction* trans, | 162 int64 FindSyncNodeWithProfile(sync_api::WriteTransaction* trans, |
161 const sync_api::BaseNode& autofill_root, | 163 const sync_api::BaseNode& autofill_root, |
162 const AutoFillProfile& profile); | 164 const AutoFillProfile& profile); |
163 | 165 |
| 166 bool MigrationLoggingEnabled(); |
| 167 |
164 ProfileSyncService* sync_service_; | 168 ProfileSyncService* sync_service_; |
165 WebDatabase* web_database_; | 169 WebDatabase* web_database_; |
166 PersonalDataManager* personal_data_; | 170 PersonalDataManager* personal_data_; |
167 int64 autofill_node_id_; | 171 int64 autofill_node_id_; |
168 | 172 |
169 AutofillToSyncIdMap id_map_; | 173 AutofillToSyncIdMap id_map_; |
170 SyncIdToAutofillMap id_map_inverse_; | 174 SyncIdToAutofillMap id_map_inverse_; |
171 | 175 |
172 // Abort association pending flag and lock. If this is set to true | 176 // Abort association pending flag and lock. If this is set to true |
173 // (via the AbortAssociation method), return from the | 177 // (via the AbortAssociation method), return from the |
174 // AssociateModels method as soon as possible. | 178 // AssociateModels method as soon as possible. |
175 Lock abort_association_pending_lock_; | 179 Lock abort_association_pending_lock_; |
176 bool abort_association_pending_; | 180 bool abort_association_pending_; |
177 | 181 |
| 182 int number_of_profiles_created_; |
| 183 |
178 DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelAssociator); | 184 DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelAssociator); |
179 }; | 185 }; |
180 | 186 |
181 struct AutofillProfileModelAssociator::DataBundle { | 187 struct AutofillProfileModelAssociator::DataBundle { |
182 std::set<std::string> current_profiles; | 188 std::set<std::string> current_profiles; |
183 std::vector<std::string> profiles_to_delete; | 189 std::vector<std::string> profiles_to_delete; |
184 std::vector<AutoFillProfile*> updated_profiles; | 190 std::vector<AutoFillProfile*> updated_profiles; |
185 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. | 191 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. |
186 ~DataBundle() { STLDeleteElements(&new_profiles); } | 192 ~DataBundle() { STLDeleteElements(&new_profiles); } |
187 }; | 193 }; |
188 | 194 |
189 } // namespace browser_sync | 195 } // namespace browser_sync |
190 | 196 |
191 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 197 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
| 198 |
OLD | NEW |