| 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/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/tracked.h" | 11 #include "base/tracked.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/autofill_profile_model_associator.h" | 16 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" |
| 17 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | 17 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" |
| 18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/webdata/autofill_change.h" | 19 #include "chrome/browser/webdata/autofill_change.h" |
| 20 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
| 21 #include "chrome/browser/webdata/web_database.h" | 21 #include "chrome/browser/webdata/web_database.h" |
| 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/guid.h" | 23 #include "chrome/common/guid.h" |
| 23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
| 24 | 25 |
| 25 namespace browser_sync { | 26 namespace browser_sync { |
| 26 | 27 |
| 27 struct AutofillChangeProcessor::AutofillChangeRecord { | 28 struct AutofillChangeProcessor::AutofillChangeRecord { |
| 28 sync_api::SyncManager::ChangeRecord::Action action_; | 29 sync_api::SyncManager::ChangeRecord::Action action_; |
| 29 int64 id_; | 30 int64 id_; |
| 30 sync_pb::AutofillSpecifics autofill_; | 31 sync_pb::AutofillSpecifics autofill_; |
| 31 AutofillChangeRecord(sync_api::SyncManager::ChangeRecord::Action action, | 32 AutofillChangeRecord(sync_api::SyncManager::ChangeRecord::Action action, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 71 |
| 71 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); | 72 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); |
| 72 sync_api::ReadNode autofill_root(&trans); | 73 sync_api::ReadNode autofill_root(&trans); |
| 73 if (!autofill_root.InitByTagLookup(kAutofillTag)) { | 74 if (!autofill_root.InitByTagLookup(kAutofillTag)) { |
| 74 error_handler()->OnUnrecoverableError(FROM_HERE, | 75 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 75 "Server did not create the top-level autofill node. " | 76 "Server did not create the top-level autofill node. " |
| 76 "We might be running against an out-of-date server."); | 77 "We might be running against an out-of-date server."); |
| 77 return; | 78 return; |
| 78 } | 79 } |
| 79 | 80 |
| 80 DCHECK(type.value == NotificationType::AUTOFILL_ENTRIES_CHANGED); | 81 DCHECK(type.value == chrome::AUTOFILL_ENTRIES_CHANGED); |
| 81 | 82 |
| 82 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); | 83 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); |
| 83 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); | 84 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void AutofillChangeProcessor::PostOptimisticRefreshTask() { | 87 void AutofillChangeProcessor::PostOptimisticRefreshTask() { |
| 87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 88 new DoOptimisticRefreshForAutofill( | 89 new DoOptimisticRefreshForAutofill( |
| 89 personal_data_)); | 90 personal_data_)); |
| 90 } | 91 } |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 413 } |
| 413 | 414 |
| 414 void AutofillChangeProcessor::StopImpl() { | 415 void AutofillChangeProcessor::StopImpl() { |
| 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 416 observing_ = false; | 417 observing_ = false; |
| 417 } | 418 } |
| 418 | 419 |
| 419 | 420 |
| 420 void AutofillChangeProcessor::StartObserving() { | 421 void AutofillChangeProcessor::StartObserving() { |
| 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 422 notification_registrar_.Add(this, NotificationType::AUTOFILL_ENTRIES_CHANGED, | 423 notification_registrar_.Add(this, chrome::AUTOFILL_ENTRIES_CHANGED, |
| 423 NotificationService::AllSources()); | 424 NotificationService::AllSources()); |
| 424 } | 425 } |
| 425 | 426 |
| 426 void AutofillChangeProcessor::StopObserving() { | 427 void AutofillChangeProcessor::StopObserving() { |
| 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 428 notification_registrar_.RemoveAll(); | 429 notification_registrar_.RemoveAll(); |
| 429 } | 430 } |
| 430 | 431 |
| 431 // static | 432 // static |
| 432 void AutofillChangeProcessor::WriteAutofillEntry( | 433 void AutofillChangeProcessor::WriteAutofillEntry( |
| 433 const AutofillEntry& entry, | 434 const AutofillEntry& entry, |
| 434 sync_api::WriteNode* node) { | 435 sync_api::WriteNode* node) { |
| 435 sync_pb::AutofillSpecifics autofill; | 436 sync_pb::AutofillSpecifics autofill; |
| 436 autofill.set_name(UTF16ToUTF8(entry.key().name())); | 437 autofill.set_name(UTF16ToUTF8(entry.key().name())); |
| 437 autofill.set_value(UTF16ToUTF8(entry.key().value())); | 438 autofill.set_value(UTF16ToUTF8(entry.key().value())); |
| 438 const std::vector<base::Time>& ts(entry.timestamps()); | 439 const std::vector<base::Time>& ts(entry.timestamps()); |
| 439 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 440 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
| 440 timestamp != ts.end(); ++timestamp) { | 441 timestamp != ts.end(); ++timestamp) { |
| 441 autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 442 autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
| 442 } | 443 } |
| 443 node->SetAutofillSpecifics(autofill); | 444 node->SetAutofillSpecifics(autofill); |
| 444 } | 445 } |
| 445 | 446 |
| 446 } // namespace browser_sync | 447 } // namespace browser_sync |
| OLD | NEW |