| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/autofill/personal_data_manager.h" | 13 #include "chrome/browser/autofill/personal_data_manager.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sync/glue/autofill_model_associator.h" | 15 #include "chrome/browser/sync/glue/autofill_model_associator.h" |
| 16 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | |
| 17 #include "chrome/browser/sync/internal_api/change_record.h" | 16 #include "chrome/browser/sync/internal_api/change_record.h" |
| 18 #include "chrome/browser/sync/internal_api/read_node.h" | 17 #include "chrome/browser/sync/internal_api/read_node.h" |
| 19 #include "chrome/browser/sync/internal_api/write_node.h" | 18 #include "chrome/browser/sync/internal_api/write_node.h" |
| 20 #include "chrome/browser/sync/internal_api/write_transaction.h" | 19 #include "chrome/browser/sync/internal_api/write_transaction.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/browser/webdata/autofill_change.h" | 21 #include "chrome/browser/webdata/autofill_change.h" |
| 23 #include "chrome/browser/webdata/autofill_table.h" | 22 #include "chrome/browser/webdata/autofill_table.h" |
| 24 #include "chrome/browser/webdata/web_database.h" | 23 #include "chrome/browser/webdata/web_database.h" |
| 25 #include "chrome/browser/webdata/web_data_service.h" | 24 #include "chrome/browser/webdata/web_data_service.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/guid.h" | 26 #include "chrome/common/guid.h" |
| 28 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
| 29 | 28 |
| 30 namespace browser_sync { | 29 namespace browser_sync { |
| 31 | 30 |
| 32 struct AutofillChangeProcessor::AutofillChangeRecord { | 31 struct AutofillChangeProcessor::AutofillChangeRecord { |
| 33 sync_api::ChangeRecord::Action action_; | 32 sync_api::ChangeRecord::Action action_; |
| 34 int64 id_; | 33 int64 id_; |
| 35 sync_pb::AutofillSpecifics autofill_; | 34 sync_pb::AutofillSpecifics autofill_; |
| 36 AutofillChangeRecord(sync_api::ChangeRecord::Action action, | 35 AutofillChangeRecord(sync_api::ChangeRecord::Action action, |
| 37 int64 id, const sync_pb::AutofillSpecifics& autofill) | 36 int64 id, const sync_pb::AutofillSpecifics& autofill) |
| 38 : action_(action), | 37 : action_(action), |
| 39 id_(id), | 38 id_(id), |
| 40 autofill_(autofill) { } | 39 autofill_(autofill) { } |
| 41 }; | 40 }; |
| 42 | 41 |
| 43 AutofillChangeProcessor::AutofillChangeProcessor( | 42 AutofillChangeProcessor::AutofillChangeProcessor( |
| 44 AutofillModelAssociator* model_associator, | 43 AutofillModelAssociator* model_associator, |
| 45 WebDatabase* web_database, | 44 WebDatabase* web_database, |
| 46 PersonalDataManager* personal_data, | 45 Profile* profile, |
| 47 UnrecoverableErrorHandler* error_handler) | 46 UnrecoverableErrorHandler* error_handler) |
| 48 : ChangeProcessor(error_handler), | 47 : ChangeProcessor(error_handler), |
| 49 model_associator_(model_associator), | 48 model_associator_(model_associator), |
| 50 web_database_(web_database), | 49 web_database_(web_database), |
| 51 personal_data_(personal_data), | 50 profile_(profile), |
| 52 observing_(false) { | 51 observing_(false) { |
| 53 DCHECK(model_associator); | 52 DCHECK(model_associator); |
| 54 DCHECK(web_database); | 53 DCHECK(web_database); |
| 54 DCHECK(profile); |
| 55 DCHECK(error_handler); | 55 DCHECK(error_handler); |
| 56 DCHECK(personal_data); | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 58 StartObserving(); | 57 StartObserving(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 AutofillChangeProcessor::~AutofillChangeProcessor() {} | 60 AutofillChangeProcessor::~AutofillChangeProcessor() {} |
| 62 | 61 |
| 63 void AutofillChangeProcessor::Observe(int type, | 62 void AutofillChangeProcessor::Observe(int type, |
| 64 const NotificationSource& source, | 63 const NotificationSource& source, |
| 65 const NotificationDetails& details) { | 64 const NotificationDetails& details) { |
| 66 // Ensure this notification came from our web database. | 65 // Ensure this notification came from our web database. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 "We might be running against an out-of-date server."); | 80 "We might be running against an out-of-date server."); |
| 82 return; | 81 return; |
| 83 } | 82 } |
| 84 | 83 |
| 85 DCHECK(type == chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED); | 84 DCHECK(type == chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED); |
| 86 | 85 |
| 87 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); | 86 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); |
| 88 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); | 87 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); |
| 89 } | 88 } |
| 90 | 89 |
| 91 void AutofillChangeProcessor::PostOptimisticRefreshTask() { | |
| 92 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 93 new DoOptimisticRefreshForAutofill( | |
| 94 personal_data_)); | |
| 95 } | |
| 96 | |
| 97 void AutofillChangeProcessor::ObserveAutofillEntriesChanged( | 90 void AutofillChangeProcessor::ObserveAutofillEntriesChanged( |
| 98 AutofillChangeList* changes, sync_api::WriteTransaction* trans, | 91 AutofillChangeList* changes, sync_api::WriteTransaction* trans, |
| 99 const sync_api::ReadNode& autofill_root) { | 92 const sync_api::ReadNode& autofill_root) { |
| 100 for (AutofillChangeList::iterator change = changes->begin(); | 93 for (AutofillChangeList::iterator change = changes->begin(); |
| 101 change != changes->end(); ++change) { | 94 change != changes->end(); ++change) { |
| 102 switch (change->type()) { | 95 switch (change->type()) { |
| 103 case AutofillChange::ADD: | 96 case AutofillChange::ADD: |
| 104 { | 97 { |
| 105 sync_api::WriteNode sync_node(trans); | 98 sync_api::WriteNode sync_node(trans); |
| 106 std::string tag = | 99 std::string tag = |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 288 } |
| 296 autofill_changes_.clear(); | 289 autofill_changes_.clear(); |
| 297 | 290 |
| 298 // Make changes | 291 // Make changes |
| 299 if (!web_database_->GetAutofillTable()->UpdateAutofillEntries(new_entries)) { | 292 if (!web_database_->GetAutofillTable()->UpdateAutofillEntries(new_entries)) { |
| 300 error_handler()->OnUnrecoverableError(FROM_HERE, | 293 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 301 "Could not update autofill entries."); | 294 "Could not update autofill entries."); |
| 302 return; | 295 return; |
| 303 } | 296 } |
| 304 | 297 |
| 305 PostOptimisticRefreshTask(); | 298 WebDataService::NotifyOfMultipleAutofillChanges(profile_); |
| 306 | 299 |
| 307 StartObserving(); | 300 StartObserving(); |
| 308 } | 301 } |
| 309 | 302 |
| 310 void AutofillChangeProcessor::ApplySyncAutofillEntryDelete( | 303 void AutofillChangeProcessor::ApplySyncAutofillEntryDelete( |
| 311 const sync_pb::AutofillSpecifics& autofill) { | 304 const sync_pb::AutofillSpecifics& autofill) { |
| 312 if (!web_database_->GetAutofillTable()->RemoveFormElement( | 305 if (!web_database_->GetAutofillTable()->RemoveFormElement( |
| 313 UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) { | 306 UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) { |
| 314 error_handler()->OnUnrecoverableError(FROM_HERE, | 307 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 315 "Could not remove autofill node."); | 308 "Could not remove autofill node."); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 autofill.set_value(UTF16ToUTF8(entry.key().value())); | 436 autofill.set_value(UTF16ToUTF8(entry.key().value())); |
| 444 const std::vector<base::Time>& ts(entry.timestamps()); | 437 const std::vector<base::Time>& ts(entry.timestamps()); |
| 445 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 438 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
| 446 timestamp != ts.end(); ++timestamp) { | 439 timestamp != ts.end(); ++timestamp) { |
| 447 autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 440 autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
| 448 } | 441 } |
| 449 node->SetAutofillSpecifics(autofill); | 442 node->SetAutofillSpecifics(autofill); |
| 450 } | 443 } |
| 451 | 444 |
| 452 } // namespace browser_sync | 445 } // namespace browser_sync |
| OLD | NEW |