| 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 #include "chrome/browser/sync/glue/autofill_change_processor.h" | 5 #include "chrome/browser/sync/glue/autofill_change_processor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 sync_node.Remove(); | 189 sync_node.Remove(); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 void AutofillChangeProcessor::ApplyChangesFromSyncModel( | 193 void AutofillChangeProcessor::ApplyChangesFromSyncModel( |
| 194 const sync_api::BaseTransaction* trans, | 194 const sync_api::BaseTransaction* trans, |
| 195 const sync_api::ImmutableChangeRecordList& changes) { | 195 const sync_api::ImmutableChangeRecordList& changes) { |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 197 if (!running()) | 197 if (!running()) |
| 198 return; | 198 return; |
| 199 StopObserving(); | 199 ScopedStopObserving<AutofillChangeProcessor> stop_observing(this); |
| 200 | 200 |
| 201 sync_api::ReadNode autofill_root(trans); | 201 sync_api::ReadNode autofill_root(trans); |
| 202 if (!autofill_root.InitByTagLookup(kAutofillTag)) { | 202 if (!autofill_root.InitByTagLookup(kAutofillTag)) { |
| 203 error_handler()->OnUnrecoverableError(FROM_HERE, | 203 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 204 "Autofill root node lookup failed."); | 204 "Autofill root node lookup failed."); |
| 205 return; | 205 return; |
| 206 } | 206 } |
| 207 | 207 |
| 208 for (sync_api::ChangeRecordList::const_iterator it = | 208 for (sync_api::ChangeRecordList::const_iterator it = |
| 209 changes.Get().begin(); it != changes.Get().end(); ++it) { | 209 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 int64 sync_id = sync_node.GetId(); | 242 int64 sync_id = sync_node.GetId(); |
| 243 if (autofill.has_value()) { | 243 if (autofill.has_value()) { |
| 244 autofill_changes_.push_back(AutofillChangeRecord(it->action, | 244 autofill_changes_.push_back(AutofillChangeRecord(it->action, |
| 245 sync_id, autofill)); | 245 sync_id, autofill)); |
| 246 } else if (autofill.has_profile()) { | 246 } else if (autofill.has_profile()) { |
| 247 LOG(WARNING) << "Change for old-style autofill profile being dropped!"; | 247 LOG(WARNING) << "Change for old-style autofill profile being dropped!"; |
| 248 } else { | 248 } else { |
| 249 NOTREACHED() << "Autofill specifics has no data!"; | 249 NOTREACHED() << "Autofill specifics has no data!"; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | |
| 253 StartObserving(); | |
| 254 } | 252 } |
| 255 | 253 |
| 256 void AutofillChangeProcessor::CommitChangesFromSyncModel() { | 254 void AutofillChangeProcessor::CommitChangesFromSyncModel() { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 258 if (!running()) | 256 if (!running()) |
| 259 return; | 257 return; |
| 260 StopObserving(); | 258 ScopedStopObserving<AutofillChangeProcessor> stop_observing(this); |
| 261 | 259 |
| 262 std::vector<AutofillEntry> new_entries; | 260 std::vector<AutofillEntry> new_entries; |
| 263 for (unsigned int i = 0; i < autofill_changes_.size(); i++) { | 261 for (unsigned int i = 0; i < autofill_changes_.size(); i++) { |
| 264 // Handle deletions. | 262 // Handle deletions. |
| 265 if (sync_api::ChangeRecord::ACTION_DELETE == | 263 if (sync_api::ChangeRecord::ACTION_DELETE == |
| 266 autofill_changes_[i].action_) { | 264 autofill_changes_[i].action_) { |
| 267 if (autofill_changes_[i].autofill_.has_value()) { | 265 if (autofill_changes_[i].autofill_.has_value()) { |
| 268 ApplySyncAutofillEntryDelete(autofill_changes_[i].autofill_); | 266 ApplySyncAutofillEntryDelete(autofill_changes_[i].autofill_); |
| 269 } else if (autofill_changes_[i].autofill_.has_profile()) { | 267 } else if (autofill_changes_[i].autofill_.has_profile()) { |
| 270 ApplySyncAutofillProfileDelete(autofill_changes_[i].id_); | 268 ApplySyncAutofillProfileDelete(autofill_changes_[i].id_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 293 // Make changes | 291 // Make changes |
| 294 if (!web_database_->GetAutofillTable()->UpdateAutofillEntries(new_entries)) { | 292 if (!web_database_->GetAutofillTable()->UpdateAutofillEntries(new_entries)) { |
| 295 error_handler()->OnUnrecoverableError(FROM_HERE, | 293 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 296 "Could not update autofill entries."); | 294 "Could not update autofill entries."); |
| 297 return; | 295 return; |
| 298 } | 296 } |
| 299 | 297 |
| 300 WebDataService::NotifyOfMultipleAutofillChanges( | 298 WebDataService::NotifyOfMultipleAutofillChanges( |
| 301 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)); | 299 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)); |
| 302 | 300 |
| 303 StartObserving(); | |
| 304 } | 301 } |
| 305 | 302 |
| 306 void AutofillChangeProcessor::ApplySyncAutofillEntryDelete( | 303 void AutofillChangeProcessor::ApplySyncAutofillEntryDelete( |
| 307 const sync_pb::AutofillSpecifics& autofill) { | 304 const sync_pb::AutofillSpecifics& autofill) { |
| 308 if (!web_database_->GetAutofillTable()->RemoveFormElement( | 305 if (!web_database_->GetAutofillTable()->RemoveFormElement( |
| 309 UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) { | 306 UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) { |
| 310 error_handler()->OnUnrecoverableError(FROM_HERE, | 307 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 311 "Could not remove autofill node."); | 308 "Could not remove autofill node."); |
| 312 return; | 309 return; |
| 313 } | 310 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 autofill.set_value(UTF16ToUTF8(entry.key().value())); | 436 autofill.set_value(UTF16ToUTF8(entry.key().value())); |
| 440 const std::vector<base::Time>& ts(entry.timestamps()); | 437 const std::vector<base::Time>& ts(entry.timestamps()); |
| 441 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 438 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
| 442 timestamp != ts.end(); ++timestamp) { | 439 timestamp != ts.end(); ++timestamp) { |
| 443 autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 440 autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
| 444 } | 441 } |
| 445 node->SetAutofillSpecifics(autofill); | 442 node->SetAutofillSpecifics(autofill); |
| 446 } | 443 } |
| 447 | 444 |
| 448 } // namespace browser_sync | 445 } // namespace browser_sync |
| OLD | NEW |