diff options
author | zork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 21:31:25 +0000 |
---|---|---|
committer | zork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 21:31:25 +0000 |
commit | f515eece5f790dc20f51c32718642bd9fa9e7261 (patch) | |
tree | 79d3739e4d52f027bdabbdfa49ae7da83ed3e37f | |
parent | 0089e561bbbacde67df51ee7c9a6e3cf6c3cbfcf (diff) | |
download | chromium_src-f515eece5f790dc20f51c32718642bd9fa9e7261.zip chromium_src-f515eece5f790dc20f51c32718642bd9fa9e7261.tar.gz chromium_src-f515eece5f790dc20f51c32718642bd9fa9e7261.tar.bz2 |
Use a common call to WriteAutofill in AutofillModelAssociator, add a proper
update to the sync model on model association.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/661337
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40781 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | chrome/browser/sync/glue/autofill_change_processor.cc | 49 | ||||
-rwxr-xr-x | chrome/browser/sync/glue/autofill_change_processor.h | 10 | ||||
-rwxr-xr-x | chrome/browser/sync/glue/autofill_model_associator.cc | 26 |
3 files changed, 41 insertions, 44 deletions
diff --git a/chrome/browser/sync/glue/autofill_change_processor.cc b/chrome/browser/sync/glue/autofill_change_processor.cc index c96fd4a..2045351 100755 --- a/chrome/browser/sync/glue/autofill_change_processor.cc +++ b/chrome/browser/sync/glue/autofill_change_processor.cc @@ -83,12 +83,8 @@ void AutofillChangeProcessor::Observe(NotificationType type, sync_node.SetTitle(UTF16ToWide(change->key().name() + change->key().value())); - if (!WriteAutofill(&sync_node, change->key().name(), - change->key().value(), timestamps)) { - LOG(ERROR) << "Failed to update autofill node."; - error_handler()->OnUnrecoverableError(); - return; - } + WriteAutofill(&sync_node, change->key().name(), + change->key().value(), timestamps); model_associator_->Associate(&(change->key()), sync_node.GetId()); } @@ -122,12 +118,8 @@ void AutofillChangeProcessor::Observe(NotificationType type, return; } - if (!WriteAutofill(&sync_node, change->key().name(), - change->key().value(), timestamps)) { - LOG(ERROR) << "Failed to update autofill node."; - error_handler()->OnUnrecoverableError(); - return; - } + WriteAutofill(&sync_node, change->key().name(), + change->key().value(), timestamps); } break; @@ -213,23 +205,6 @@ void AutofillChangeProcessor::ApplyChangesFromSyncModel( StartObserving(); } -bool AutofillChangeProcessor::WriteAutofill( - sync_api::WriteNode* node, - const string16& name, - const string16& value, - std::vector<base::Time>& timestamps) { - sync_pb::AutofillSpecifics autofill; - autofill.set_name(UTF16ToUTF8(name)); - autofill.set_value(UTF16ToUTF8(value)); - for (std::vector<base::Time>::iterator timestamp = timestamps.begin(); - timestamp != timestamps.end(); ++timestamp) { - autofill.add_usage_timestamp(timestamp->ToInternalValue()); - } - node->SetAutofillSpecifics(autofill); - return true; -} - - void AutofillChangeProcessor::StartImpl(Profile* profile) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); observing_ = true; @@ -254,4 +229,20 @@ void AutofillChangeProcessor::StopObserving() { NotificationService::AllSources()); } +// static +void AutofillChangeProcessor::WriteAutofill( + sync_api::WriteNode* node, + const string16& name, + const string16& value, + const std::vector<base::Time>& timestamps) { + sync_pb::AutofillSpecifics autofill; + autofill.set_name(UTF16ToUTF8(name)); + autofill.set_value(UTF16ToUTF8(value)); + for (std::vector<base::Time>::const_iterator timestamp = timestamps.begin(); + timestamp != timestamps.end(); ++timestamp) { + autofill.add_usage_timestamp(timestamp->ToInternalValue()); + } + node->SetAutofillSpecifics(autofill); +} + } // namespace browser_sync diff --git a/chrome/browser/sync/glue/autofill_change_processor.h b/chrome/browser/sync/glue/autofill_change_processor.h index e482a90..827bcd9 100755 --- a/chrome/browser/sync/glue/autofill_change_processor.h +++ b/chrome/browser/sync/glue/autofill_change_processor.h @@ -42,16 +42,16 @@ class AutofillChangeProcessor : public ChangeProcessor, const sync_api::SyncManager::ChangeRecord* changes, int change_count); + static void WriteAutofill(sync_api::WriteNode* node, + const string16& name, + const string16& value, + const std::vector<base::Time>& timestamps); + protected: virtual void StartImpl(Profile* profile); virtual void StopImpl(); private: - bool WriteAutofill(sync_api::WriteNode* node, - const string16& name, - const string16& value, - std::vector<base::Time>& timestamps); - void StartObserving(); void StopObserving(); diff --git a/chrome/browser/sync/glue/autofill_model_associator.cc b/chrome/browser/sync/glue/autofill_model_associator.cc index c9a349b..e8236fa 100755 --- a/chrome/browser/sync/glue/autofill_model_associator.cc +++ b/chrome/browser/sync/glue/autofill_model_associator.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/profile.h" #include "chrome/browser/sync/engine/syncapi.h" +#include "chrome/browser/sync/glue/autofill_change_processor.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" #include "chrome/browser/webdata/web_database.h" @@ -76,6 +77,17 @@ bool AutofillModelAssociator::AssociateModels() { new_entries.push_back(AutofillEntry( AutofillKey(ix->key().name(), ix->key().value()), timestamps)); + + sync_api::WriteNode write_node(&trans); + if (!write_node.InitByClientTagLookup(syncable::AUTOFILL, tag)) { + LOG(ERROR) << "Failed to write autofill sync node."; + error_handler_->OnUnrecoverableError(); + return false; + } + AutofillChangeProcessor::WriteAutofill(&write_node, + ix->key().name(), + ix->key().value(), + timestamps); } Associate(&(ix->key()), node.GetId()); @@ -89,17 +101,11 @@ bool AutofillModelAssociator::AssociateModels() { node.SetTitle(UTF16ToWide(ix->key().name() + ix->key().value())); - sync_pb::AutofillSpecifics autofill; - autofill.set_name(UTF16ToUTF8(ix->key().name())); - autofill.set_value(UTF16ToUTF8(ix->key().value())); - - for (std::vector<base::Time>::const_iterator timestamp = - ix->timestamps().begin(); timestamp != ix->timestamps().end(); - ++timestamp) { - autofill.add_usage_timestamp(timestamp->ToInternalValue()); - } + AutofillChangeProcessor::WriteAutofill(&node, + ix->key().name(), + ix->key().value(), + ix->timestamps()); - node.SetAutofillSpecifics(autofill); Associate(&(ix->key()), node.GetId()); } |