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 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | 5 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" |
| 9 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" |
8 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
9 #include "chrome/browser/webdata/web_database.h" | 11 #include "chrome/browser/webdata/web_database.h" |
10 | 12 |
11 using sync_api::ReadNode; | 13 using sync_api::ReadNode; |
12 namespace browser_sync { | 14 namespace browser_sync { |
13 | 15 |
14 const char kAutofillProfileTag[] = "google_chrome_autofill_profile"; | 16 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; |
15 | 17 |
16 AutofillProfileModelAssociator::AutofillProfileModelAssociator( | 18 AutofillProfileModelAssociator::AutofillProfileModelAssociator( |
17 ProfileSyncService* sync_service, | 19 ProfileSyncService* sync_service, |
18 WebDatabase* web_database, | 20 WebDatabase* web_database, |
19 PersonalDataManager* personal_data) | 21 PersonalDataManager* personal_data) |
20 : sync_service_(sync_service), | 22 : sync_service_(sync_service), |
21 web_database_(web_database), | 23 web_database_(web_database), |
22 personal_data_(personal_data), | 24 personal_data_(personal_data), |
23 autofill_node_id_(sync_api::kInvalidId), | 25 autofill_node_id_(sync_api::kInvalidId), |
24 abort_association_pending_(false) { | 26 abort_association_pending_(false), |
| 27 number_of_profiles_created_(0) { |
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
26 DCHECK(sync_service_); | 29 DCHECK(sync_service_); |
27 DCHECK(web_database_); | 30 DCHECK(web_database_); |
28 DCHECK(personal_data_); | 31 DCHECK(personal_data_); |
29 } | 32 } |
30 | 33 |
31 AutofillProfileModelAssociator::~AutofillProfileModelAssociator() { | 34 AutofillProfileModelAssociator::~AutofillProfileModelAssociator() { |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
33 } | 36 } |
34 | 37 |
35 AutofillProfileModelAssociator::AutofillProfileModelAssociator() {} | 38 AutofillProfileModelAssociator::AutofillProfileModelAssociator() {} |
36 | 39 |
37 bool AutofillProfileModelAssociator::TraverseAndAssociateChromeAutoFillProfiles( | 40 bool AutofillProfileModelAssociator::TraverseAndAssociateChromeAutoFillProfiles( |
38 sync_api::WriteTransaction* write_trans, | 41 sync_api::WriteTransaction* write_trans, |
39 const sync_api::ReadNode& autofill_root, | 42 const sync_api::ReadNode& autofill_root, |
40 const std::vector<AutoFillProfile*>& all_profiles_from_db, | 43 const std::vector<AutoFillProfile*>& all_profiles_from_db, |
41 std::set<std::string>* current_profiles, | 44 std::set<std::string>* current_profiles, |
42 std::vector<AutoFillProfile*>* updated_profiles, | 45 std::vector<AutoFillProfile*>* updated_profiles, |
43 std::vector<AutoFillProfile*>* new_profiles, | 46 std::vector<AutoFillProfile*>* new_profiles, |
44 std::vector<std::string>* profiles_to_delete) { | 47 std::vector<std::string>* profiles_to_delete) { |
45 | 48 |
| 49 if (MigrationLoggingEnabled()) { |
| 50 VLOG(1) << "[AUTOFILL MIGRATION]" |
| 51 << "Printing profiles from web db"; |
| 52 |
| 53 for (std::vector<AutoFillProfile*>::const_iterator ix = |
| 54 all_profiles_from_db.begin(); ix != all_profiles_from_db.end(); ++ix) { |
| 55 AutoFillProfile* p = *ix; |
| 56 VLOG(1) << "[AUTOFILL MIGRATION] " |
| 57 << p->GetFieldText(AutoFillType(NAME_FIRST)) |
| 58 << p->GetFieldText(AutoFillType(NAME_LAST)) |
| 59 << p->guid(); |
| 60 } |
| 61 } |
| 62 |
| 63 if (MigrationLoggingEnabled()) { |
| 64 VLOG(1) << "[AUTOFILL MIGRATION]" |
| 65 << "Looking for the above data in sync db.."; |
| 66 } |
46 // Alias the all_profiles_from_db so we fit in 80 characters | 67 // Alias the all_profiles_from_db so we fit in 80 characters |
47 const std::vector<AutoFillProfile*>& profiles(all_profiles_from_db); | 68 const std::vector<AutoFillProfile*>& profiles(all_profiles_from_db); |
48 for (std::vector<AutoFillProfile*>::const_iterator ix = profiles.begin(); | 69 for (std::vector<AutoFillProfile*>::const_iterator ix = profiles.begin(); |
49 ix != profiles.end(); | 70 ix != profiles.end(); |
50 ++ix) { | 71 ++ix) { |
51 std::string guid((*ix)->guid()); | 72 std::string guid((*ix)->guid()); |
52 | 73 |
53 ReadNode node(write_trans); | 74 ReadNode node(write_trans); |
54 if (node.InitByClientTagLookup(syncable::AUTOFILL_PROFILE, guid)) { | 75 if (node.InitByClientTagLookup(syncable::AUTOFILL_PROFILE, guid)) { |
| 76 if (MigrationLoggingEnabled()) { |
| 77 VLOG(1) << "[AUTOFILL MIGRATION]" |
| 78 << " Found in sync db: " |
| 79 << (*ix)->GetFieldText(AutoFillType(NAME_FIRST)) |
| 80 << (*ix)->GetFieldText(AutoFillType(NAME_LAST)) |
| 81 << (*ix)->guid() |
| 82 << " so associating"; |
| 83 } |
55 const sync_pb::AutofillProfileSpecifics& autofill( | 84 const sync_pb::AutofillProfileSpecifics& autofill( |
56 node.GetAutofillProfileSpecifics()); | 85 node.GetAutofillProfileSpecifics()); |
57 if (OverwriteProfileWithServerData(*ix, autofill)) { | 86 if (OverwriteProfileWithServerData(*ix, autofill)) { |
58 updated_profiles->push_back(*ix); | 87 updated_profiles->push_back(*ix); |
59 } | 88 } |
60 Associate(&guid, node.GetId()); | 89 Associate(&guid, node.GetId()); |
61 current_profiles->insert(guid); | 90 current_profiles->insert(guid); |
62 } else { | 91 } else { |
63 MakeNewAutofillProfileSyncNodeIfNeeded(write_trans, | 92 MakeNewAutofillProfileSyncNodeIfNeeded(write_trans, |
64 autofill_root, | 93 autofill_root, |
65 (**ix), | 94 (**ix), |
66 new_profiles, | 95 new_profiles, |
67 current_profiles, | 96 current_profiles, |
68 profiles_to_delete); | 97 profiles_to_delete); |
69 } | 98 } |
70 } | 99 } |
71 | |
72 return true; | 100 return true; |
73 } | 101 } |
74 | 102 |
| 103 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode( |
| 104 const std::string& tag, |
| 105 int64* sync_id) { |
| 106 sync_api::ReadTransaction trans( |
| 107 sync_service_->backend()->GetUserShareHandle()); |
| 108 sync_api::ReadNode sync_node(&trans); |
| 109 if (!sync_node.InitByTagLookup(tag.c_str())) |
| 110 return false; |
| 111 *sync_id = sync_node.GetId(); |
| 112 return true; |
| 113 } |
| 114 |
75 bool AutofillProfileModelAssociator::LoadAutofillData( | 115 bool AutofillProfileModelAssociator::LoadAutofillData( |
76 std::vector<AutoFillProfile*>* profiles) { | 116 std::vector<AutoFillProfile*>* profiles) { |
77 if (IsAbortPending()) | 117 if (IsAbortPending()) |
78 return false; | 118 return false; |
79 | 119 |
80 if (!web_database_->GetAutoFillProfiles(profiles)) | 120 if (!web_database_->GetAutoFillProfiles(profiles)) |
81 return false; | 121 return false; |
82 | 122 |
83 return true; | 123 return true; |
84 } | 124 } |
85 | 125 |
86 bool AutofillProfileModelAssociator::AssociateModels() { | 126 bool AutofillProfileModelAssociator::AssociateModels() { |
87 VLOG(1) << "Associating Autofill Models"; | 127 VLOG(1) << "Associating Autofill Models"; |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
89 { | 129 { |
90 AutoLock lock(abort_association_pending_lock_); | 130 AutoLock lock(abort_association_pending_lock_); |
91 abort_association_pending_ = false; | 131 abort_association_pending_ = false; |
92 } | 132 } |
93 | 133 |
94 ScopedVector<AutoFillProfile> profiles; | 134 ScopedVector<AutoFillProfile> profiles; |
95 | 135 |
96 if (!LoadAutofillData(&profiles.get())) { | 136 if (!LoadAutofillData(&profiles.get())) { |
97 LOG(ERROR) << "Could not get the autofill data from WebDatabase."; | 137 LOG(ERROR) << "Could not get the autofill data from WebDatabase."; |
98 return false; | 138 return false; |
99 } | 139 } |
100 | 140 |
| 141 if (MigrationLoggingEnabled()) { |
| 142 VLOG(1) << "[AUTOFILL MIGRATION]" |
| 143 << " Now associating to the new autofill profile model associator" |
| 144 << " root node"; |
| 145 } |
101 DataBundle bundle; | 146 DataBundle bundle; |
102 { | 147 { |
103 // The write transaction lock is held inside this block. | 148 // The write transaction lock is held inside this block. |
104 // We do all the web db operations outside this block. | 149 // We do all the web db operations outside this block. |
105 sync_api::WriteTransaction trans( | 150 sync_api::WriteTransaction trans( |
106 sync_service_->backend()->GetUserShareHandle()); | 151 sync_service_->backend()->GetUserShareHandle()); |
107 | 152 |
108 sync_api::ReadNode autofill_root(&trans); | 153 sync_api::ReadNode autofill_root(&trans); |
109 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { | 154 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { |
110 LOG(ERROR) << "Server did not create the top-level autofill node. We " | 155 LOG(ERROR) << "Server did not create the top-level autofill node. We " |
111 << "might be running against an out-of-date server."; | 156 << "might be running against an out-of-date server."; |
112 return false; | 157 return false; |
113 } | 158 } |
114 | 159 |
115 if (!TraverseAndAssociateChromeAutoFillProfiles(&trans, autofill_root, | 160 if (!TraverseAndAssociateChromeAutoFillProfiles(&trans, autofill_root, |
116 profiles.get(), &bundle.current_profiles, | 161 profiles.get(), &bundle.current_profiles, |
117 &bundle.updated_profiles, | 162 &bundle.updated_profiles, |
118 &bundle.new_profiles, | 163 &bundle.new_profiles, |
119 &bundle.profiles_to_delete) || | 164 &bundle.profiles_to_delete) || |
120 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { | 165 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { |
121 return false; | 166 return false; |
122 } | 167 } |
123 } | 168 } |
124 | 169 |
125 if (!SaveChangesToWebData(bundle)) { | 170 if (!SaveChangesToWebData(bundle)) { |
126 LOG(ERROR) << "Failed to update autofill entries."; | 171 LOG(ERROR) << "Failed to update autofill entries."; |
127 return false; | 172 return false; |
128 } | 173 } |
129 | 174 |
130 // TODO(lipalani) Bug 64111- split out the OptimisticRefreshTask | 175 if (sync_service_->backend()->GetAutofillMigrationState() != |
131 // into its own class | 176 syncable::MIGRATED) { |
132 // from autofill_model_associator | 177 syncable::AutofillMigrationDebugInfo debug_info; |
133 // Will be done as part of the autofill_model_associator work. | 178 debug_info.autofill_profile_added_during_migration = |
134 // BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 179 number_of_profiles_created_; |
135 // new DoOptimisticRefreshTask(personal_data_)); | 180 sync_service_->backend()->SetAutofillMigrationDebugInfo( |
| 181 syncable::AutofillMigrationDebugInfo::PROFILES_ADDED, |
| 182 debug_info); |
| 183 sync_service()->backend()->SetAutofillMigrationState( |
| 184 syncable::MIGRATED); |
| 185 } |
| 186 |
| 187 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 188 new DoOptimisticRefreshForAutofill(personal_data_)); |
136 return true; | 189 return true; |
137 } | 190 } |
138 | 191 |
139 bool AutofillProfileModelAssociator::DisassociateModels() { | 192 bool AutofillProfileModelAssociator::DisassociateModels() { |
140 id_map_.clear(); | 193 id_map_.clear(); |
141 id_map_inverse_.clear(); | 194 id_map_inverse_.clear(); |
142 return true; | 195 return true; |
143 } | 196 } |
144 | 197 |
145 // Helper to compare the local value and cloud value of a field, merge into | 198 // Helper to compare the local value and cloud value of a field, merge into |
146 // the local value if they differ, and return whether the merge happened. | 199 // the local value if they differ, and return whether the merge happened. |
147 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, | 200 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, |
148 AutoFillFieldType t, | 201 AutoFillFieldType t, |
149 const std::string& specifics_field) { | 202 const std::string& specifics_field) { |
150 if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field) | 203 if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field) |
151 return false; | 204 return false; |
152 f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field)); | 205 f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field)); |
153 return true; | 206 return true; |
154 } | 207 } |
155 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( | 208 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( |
156 bool *has_nodes) { | 209 bool *has_nodes) { |
157 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); | 210 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); |
158 sync_api::ReadTransaction trans( | 211 sync_api::ReadTransaction trans( |
159 sync_service_->backend()->GetUserShareHandle()); | 212 sync_service_->backend()->GetUserShareHandle()); |
160 | 213 |
161 sync_api::ReadNode node(&trans); | 214 sync_api::ReadNode node(&trans); |
162 | 215 |
163 if (!node.InitByClientTagLookup( | 216 if (!node.InitByTagLookup(kAutofillProfileTag)) { |
164 syncable::AUTOFILL_PROFILE, | |
165 kAutofillProfileTag)) { | |
166 LOG(ERROR) << "Sever did not create a top level node" | 217 LOG(ERROR) << "Sever did not create a top level node" |
167 << "Out of data server or autofill type not enabled"; | 218 << "Out of data server or autofill type not enabled"; |
168 return false; | 219 return false; |
169 } | 220 } |
170 | 221 |
171 *has_nodes = sync_api::kInvalidId != node.GetFirstChildId(); | 222 *has_nodes = sync_api::kInvalidId != node.GetFirstChildId(); |
172 return true; | 223 return true; |
173 } | 224 } |
174 // static | 225 // static |
175 bool AutofillProfileModelAssociator::OverwriteProfileWithServerData( | 226 bool AutofillProfileModelAssociator::OverwriteProfileWithServerData( |
(...skipping 22 matching lines...) Expand all Loading... |
198 | 249 |
199 | 250 |
200 int64 AutofillProfileModelAssociator::FindSyncNodeWithProfile( | 251 int64 AutofillProfileModelAssociator::FindSyncNodeWithProfile( |
201 sync_api::WriteTransaction* trans, | 252 sync_api::WriteTransaction* trans, |
202 const sync_api::BaseNode& autofill_root, | 253 const sync_api::BaseNode& autofill_root, |
203 const AutoFillProfile& profile_from_db) { | 254 const AutoFillProfile& profile_from_db) { |
204 int64 sync_child_id = autofill_root.GetFirstChildId(); | 255 int64 sync_child_id = autofill_root.GetFirstChildId(); |
205 while (sync_child_id != sync_api::kInvalidId) { | 256 while (sync_child_id != sync_api::kInvalidId) { |
206 ReadNode read_node(trans); | 257 ReadNode read_node(trans); |
207 AutoFillProfile p; | 258 AutoFillProfile p; |
208 if (read_node.InitByIdLookup(sync_child_id)) { | 259 if (!read_node.InitByIdLookup(sync_child_id)) { |
209 LOG(ERROR) << "unable to find the id given by getfirst child " << | 260 LOG(ERROR) << "unable to find the id given by getfirst child " << |
210 sync_child_id; | 261 sync_child_id; |
211 return sync_api::kInvalidId; | 262 return sync_api::kInvalidId; |
212 } | 263 } |
213 const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 264 const sync_pb::AutofillProfileSpecifics& autofill_specifics( |
214 read_node.GetAutofillProfileSpecifics()); | 265 read_node.GetAutofillProfileSpecifics()); |
215 OverwriteProfileWithServerData(&p, autofill_specifics); | 266 OverwriteProfileWithServerData(&p, autofill_specifics); |
216 if (p.Compare(profile_from_db) == 0) { | 267 if (p.Compare(profile_from_db) == 0) { |
217 return sync_child_id; | 268 return sync_child_id; |
218 } | 269 } |
(...skipping 21 matching lines...) Expand all Loading... |
240 return false; | 291 return false; |
241 } | 292 } |
242 const sync_pb::AutofillProfileSpecifics& autofill_specifics( | 293 const sync_pb::AutofillProfileSpecifics& autofill_specifics( |
243 read_node.GetAutofillProfileSpecifics()); | 294 read_node.GetAutofillProfileSpecifics()); |
244 AutoFillProfile* p = new AutoFillProfile(autofill_specifics.guid()); | 295 AutoFillProfile* p = new AutoFillProfile(autofill_specifics.guid()); |
245 OverwriteProfileWithServerData(p, autofill_specifics); | 296 OverwriteProfileWithServerData(p, autofill_specifics); |
246 new_profiles->push_back(p); | 297 new_profiles->push_back(p); |
247 std::string guid = autofill_specifics.guid(); | 298 std::string guid = autofill_specifics.guid(); |
248 Associate(&guid, sync_node_id); | 299 Associate(&guid, sync_node_id); |
249 current_profiles->insert(autofill_specifics.guid()); | 300 current_profiles->insert(autofill_specifics.guid()); |
| 301 if (MigrationLoggingEnabled()) { |
| 302 VLOG(1) << "[AUTOFILL MIGRATION]" |
| 303 << "Found in sync db but with a different guid: " |
| 304 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_FIRST))) |
| 305 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_LAST))) |
| 306 << "New guid " << autofill_specifics.guid() |
| 307 << " so associating"; |
| 308 } |
250 } else { | 309 } else { |
251 sync_api::WriteNode node(trans); | 310 sync_api::WriteNode node(trans); |
252 if (!node.InitUniqueByCreation( | 311 if (!node.InitUniqueByCreation( |
253 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { | 312 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { |
254 LOG(ERROR) << "Failed to create autofill sync node."; | 313 LOG(ERROR) << "Failed to create autofill sync node."; |
255 return false; | 314 return false; |
256 } | 315 } |
257 node.SetTitle(UTF8ToWide(profile.guid())); | 316 node.SetTitle(UTF8ToWide(profile.guid())); |
| 317 if (MigrationLoggingEnabled()) { |
| 318 VLOG(1) << "[AUTOFILL MIGRATION]" |
| 319 << "NOT Found in sync db " |
| 320 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_FIRST))) |
| 321 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(NAME_LAST))) |
| 322 << profile.guid() |
| 323 << " so creating a new sync node."; |
| 324 } |
| 325 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); |
| 326 current_profiles->insert(profile.guid()); |
| 327 number_of_profiles_created_++; |
258 | 328 |
259 // TODO(lipalani) -Bug 64111 This needs rewriting. This will be tackled | |
260 // when rewriting autofill change processor. | |
261 // AutofillChangeProcessor::WriteAutofillProfile(profile, &node); | |
262 } | 329 } |
263 return true; | 330 return true; |
264 } | 331 } |
265 | 332 |
266 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( | 333 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( |
267 sync_api::WriteTransaction* write_trans, | 334 sync_api::WriteTransaction* write_trans, |
268 const sync_api::ReadNode& autofill_root, | 335 const sync_api::ReadNode& autofill_root, |
269 DataBundle* bundle) { | 336 DataBundle* bundle) { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
271 | 338 |
| 339 if (MigrationLoggingEnabled()) { |
| 340 VLOG(1) << "[AUTOFILL MIGRATION] " |
| 341 << " Iterating over sync nodes of autofill profile root node"; |
| 342 } |
272 int64 sync_child_id = autofill_root.GetFirstChildId(); | 343 int64 sync_child_id = autofill_root.GetFirstChildId(); |
273 while (sync_child_id != sync_api::kInvalidId) { | 344 while (sync_child_id != sync_api::kInvalidId) { |
274 ReadNode sync_child(write_trans); | 345 ReadNode sync_child(write_trans); |
275 if (!sync_child.InitByIdLookup(sync_child_id)) { | 346 if (!sync_child.InitByIdLookup(sync_child_id)) { |
276 LOG(ERROR) << "Failed to fetch child node."; | 347 LOG(ERROR) << "Failed to fetch child node."; |
277 return false; | 348 return false; |
278 } | 349 } |
279 const sync_pb::AutofillProfileSpecifics& autofill( | 350 const sync_pb::AutofillProfileSpecifics& autofill( |
280 sync_child.GetAutofillProfileSpecifics()); | 351 sync_child.GetAutofillProfileSpecifics()); |
281 | 352 |
282 AddNativeProfileIfNeeded(autofill, bundle, sync_child); | 353 AddNativeProfileIfNeeded(autofill, bundle, sync_child); |
283 | 354 |
284 sync_child_id = sync_child.GetSuccessorId(); | 355 sync_child_id = sync_child.GetSuccessorId(); |
285 } | 356 } |
286 return true; | 357 return true; |
287 } | 358 } |
288 | 359 |
289 void AutofillProfileModelAssociator::AddNativeProfileIfNeeded( | 360 void AutofillProfileModelAssociator::AddNativeProfileIfNeeded( |
290 const sync_pb::AutofillProfileSpecifics& profile, | 361 const sync_pb::AutofillProfileSpecifics& profile, |
291 DataBundle* bundle, | 362 DataBundle* bundle, |
292 const sync_api::ReadNode& node) { | 363 const sync_api::ReadNode& node) { |
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
294 | 365 |
| 366 if (MigrationLoggingEnabled()) { |
| 367 VLOG(1) << "[AUTOFILL MIGRATION] " |
| 368 << "Trying to lookup " |
| 369 << profile.name_first() |
| 370 << " " |
| 371 << profile.name_last() |
| 372 << " in the web db"; |
| 373 } |
295 if (bundle->current_profiles.find(profile.guid()) == | 374 if (bundle->current_profiles.find(profile.guid()) == |
296 bundle->current_profiles.end()) { | 375 bundle->current_profiles.end()) { |
297 std::string guid(profile.guid()); | 376 std::string guid(profile.guid()); |
298 Associate(&guid, node.GetId()); | 377 Associate(&guid, node.GetId()); |
299 AutoFillProfile* p = new AutoFillProfile(profile.guid()); | 378 AutoFillProfile* p = new AutoFillProfile(profile.guid()); |
300 OverwriteProfileWithServerData(p, profile); | 379 OverwriteProfileWithServerData(p, profile); |
301 bundle->new_profiles.push_back(p); | 380 bundle->new_profiles.push_back(p); |
| 381 if (MigrationLoggingEnabled()) { |
| 382 VLOG(1) << "[AUTOFILL MIGRATION] " |
| 383 << " Did not find one so creating it on web db"; |
| 384 } |
| 385 } else { |
| 386 if (MigrationLoggingEnabled()) { |
| 387 VLOG(1) << "[AUTOFILL MIGRATION] " |
| 388 << " Found it on web db. Moving on "; |
| 389 } |
302 } | 390 } |
303 } | 391 } |
304 | 392 |
305 bool AutofillProfileModelAssociator::SaveChangesToWebData( | 393 bool AutofillProfileModelAssociator::SaveChangesToWebData( |
306 const DataBundle& bundle) { | 394 const DataBundle& bundle) { |
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
308 | 396 |
309 if (IsAbortPending()) | 397 if (IsAbortPending()) |
310 return false; | 398 return false; |
311 | 399 |
(...skipping 13 matching lines...) Expand all Loading... |
325 | 413 |
326 for (size_t i = 0; i< bundle.profiles_to_delete.size(); ++i) { | 414 for (size_t i = 0; i< bundle.profiles_to_delete.size(); ++i) { |
327 if (IsAbortPending()) | 415 if (IsAbortPending()) |
328 return false; | 416 return false; |
329 if (!web_database_->RemoveAutoFillProfile(bundle.profiles_to_delete[i])) | 417 if (!web_database_->RemoveAutoFillProfile(bundle.profiles_to_delete[i])) |
330 return false; | 418 return false; |
331 } | 419 } |
332 return true; | 420 return true; |
333 } | 421 } |
334 | 422 |
335 const std::string* AutofillProfileModelAssociator::GetChromeNodeFromSyncId( | |
336 int64 sync_id) { | |
337 return NULL; | |
338 } | |
339 | |
340 bool AutofillProfileModelAssociator::InitSyncNodeFromChromeId( | 423 bool AutofillProfileModelAssociator::InitSyncNodeFromChromeId( |
341 const std::string& node_id, | 424 const std::string& node_id, |
342 sync_api::BaseNode* sync_node) { | 425 sync_api::BaseNode* sync_node) { |
343 return false; | 426 return false; |
344 } | 427 } |
345 | 428 |
346 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode( | |
347 const std::string& tag, | |
348 int64* sync_id) { | |
349 return false; | |
350 } | |
351 | |
352 void AutofillProfileModelAssociator::Associate( | 429 void AutofillProfileModelAssociator::Associate( |
353 const std::string* autofill, | 430 const std::string* autofill, |
354 int64 sync_id) { | 431 int64 sync_id) { |
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
356 DCHECK_NE(sync_api::kInvalidId, sync_id); | 433 DCHECK_NE(sync_api::kInvalidId, sync_id); |
357 DCHECK(id_map_.find(*autofill) == id_map_.end()); | 434 DCHECK(id_map_.find(*autofill) == id_map_.end()); |
358 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); | 435 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); |
359 id_map_[*autofill] = sync_id; | 436 id_map_[*autofill] = sync_id; |
360 id_map_inverse_[sync_id] = *autofill; | 437 id_map_inverse_[sync_id] = *autofill; |
361 } | 438 } |
(...skipping 12 matching lines...) Expand all Loading... |
374 AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); | 451 AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); |
375 return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; | 452 return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; |
376 } | 453 } |
377 | 454 |
378 void AutofillProfileModelAssociator::AbortAssociation() { | 455 void AutofillProfileModelAssociator::AbortAssociation() { |
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
380 AutoLock lock(abort_association_pending_lock_); | 457 AutoLock lock(abort_association_pending_lock_); |
381 abort_association_pending_ = true; | 458 abort_association_pending_ = true; |
382 } | 459 } |
383 | 460 |
| 461 const std::string* AutofillProfileModelAssociator::GetChromeNodeFromSyncId( |
| 462 int64 sync_id) { |
| 463 SyncIdToAutofillMap::const_iterator iter = id_map_inverse_.find(sync_id); |
| 464 return iter == id_map_inverse_.end() ? NULL : &(iter->second); |
| 465 } |
| 466 |
384 bool AutofillProfileModelAssociator::IsAbortPending() { | 467 bool AutofillProfileModelAssociator::IsAbortPending() { |
385 AutoLock lock(abort_association_pending_lock_); | 468 AutoLock lock(abort_association_pending_lock_); |
386 return abort_association_pending_; | 469 return abort_association_pending_; |
387 } | 470 } |
388 | 471 |
| 472 bool AutofillProfileModelAssociator::MigrationLoggingEnabled() { |
| 473 // TODO(lipalani) enable logging via a command line flag. |
| 474 return false; |
| 475 } |
| 476 |
389 } // namespace browser_sync | 477 } // namespace browser_sync |
390 | 478 |
OLD | NEW |