diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 04:55:34 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 04:55:34 +0000 |
commit | 963e4de825d0d116f345f89a0fa9ef32f98e6a2e (patch) | |
tree | 80a00f158e307e682a70adeb91ae54eb5e8e2936 /chrome | |
parent | f8037742c8e716892f9bf0f854b3ebb5680b7076 (diff) | |
download | chromium_src-963e4de825d0d116f345f89a0fa9ef32f98e6a2e.zip chromium_src-963e4de825d0d116f345f89a0fa9ef32f98e6a2e.tar.gz chromium_src-963e4de825d0d116f345f89a0fa9ef32f98e6a2e.tar.bz2 |
Revert 43009 - This change isn't as bad as it looks, basically it's templating the AutofillModelAssociator code so we can use it for both formfill (what I'm calling autofillV1 in this patch), and "profiles". Since the diffs didn't line up so well from having to move some implementation to the .h (template), I'm breaking up the review here with just the formfill code rearranged and no autofill++ impl.
Review URL: http://codereview.chromium.org/1521002
TBR=tim@chromium.org
Review URL: http://codereview.chromium.org/1559005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43055 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
8 files changed, 205 insertions, 311 deletions
diff --git a/chrome/browser/sync/glue/abstract_autofill_model_associator.h b/chrome/browser/sync/glue/abstract_autofill_model_associator.h deleted file mode 100644 index 9098cfb..0000000 --- a/chrome/browser/sync/glue/abstract_autofill_model_associator.h +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_SYNC_GLUE_ABSTRACT_AUTOFILL_MODEL_ASSOCIATOR_H_ -#define CHROME_BROWSER_SYNC_GLUE_ABSTRACT_AUTOFILL_MODEL_ASSOCIATOR_H_ - -#include <vector> - -#include "base/utf_string_conversions.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/sync/engine/syncapi.h" -#include "chrome/browser/sync/glue/model_associator.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/protocol/autofill_specifics.pb.h" -#include "net/base/escape.h" - -class WebDatabase; - -namespace browser_sync { - -static const char kAutofillTag[] = "google_chrome_autofill"; - -// Contains all model association related logic: -// * Algorithm to associate autofill model and sync model. -// We do not check if we have local data before this run; we always -// merge and sync. -template <typename KeyType> -class AbstractAutofillModelAssociator - : public PerDataTypeAssociatorInterface<KeyType, KeyType> { - public: - AbstractAutofillModelAssociator(ProfileSyncService* sync_service, - WebDatabase* web_database, - UnrecoverableErrorHandler* error_handler) - : sync_service_(sync_service), - web_database_(web_database), - error_handler_(error_handler) { - DCHECK(sync_service_); - DCHECK(web_database_); - DCHECK(error_handler_); - } - virtual ~AbstractAutofillModelAssociator() {} - - // - // Iterates through the sync model looking for matched pairs of items. - virtual bool AssociateModels() = 0; - - // Clears all associations. - virtual bool DisassociateModels() { - id_map_.clear(); - id_map_inverse_.clear(); - return true; - } - - // The has_nodes out param is true if the sync model has nodes other - // than the permanent tagged nodes. - virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) { - DCHECK(has_nodes); - *has_nodes = false; - int64 autofill_sync_id; - if (!GetSyncIdForTaggedNode(kAutofillTag, &autofill_sync_id)) { - LOG(ERROR) << "Server did not create the top-level autofill node. We " - << "might be running against an out-of-date server."; - return false; - } - sync_api::ReadTransaction trans( - sync_service_->backend()->GetUserShareHandle()); - - sync_api::ReadNode autofill_node(&trans); - if (!autofill_node.InitByIdLookup(autofill_sync_id)) { - LOG(ERROR) << "Server did not create the top-level autofill node. We " - << "might be running against an out-of-date server."; - return false; - } - - // The sync model has user created nodes if the autofill folder has any - // children. - *has_nodes = sync_api::kInvalidId != autofill_node.GetFirstChildId(); - return true; - } - - // The has_nodes out param is true if the autofill model has any - // user-defined autofill entries. - virtual bool ChromeModelHasUserCreatedNodes(bool* has_nodes) { - DCHECK(has_nodes); - // Assume the autofill model always have user-created nodes. - *has_nodes = true; - return true; - } - - // Returns the sync id for the given autofill name, or sync_api::kInvalidId - // if the autofill name is not associated to any sync id. - virtual int64 GetSyncIdFromChromeId(KeyType autofill) { - typename AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); - return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; - } - - // Associates the given autofill name with the given sync id. - virtual void Associate(const KeyType* autofill, int64 sync_id) { - DCHECK_NE(sync_api::kInvalidId, sync_id); - DCHECK(id_map_.find(*autofill) == id_map_.end()); - DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); - id_map_[*autofill] = sync_id; - id_map_inverse_[sync_id] = *autofill; - } - - // Remove the association that corresponds to the given sync id. - virtual void Disassociate(int64 sync_id) { - typename SyncIdToAutofillMap::iterator iter = - id_map_inverse_.find(sync_id); - if (iter == id_map_inverse_.end()) - return; - CHECK(id_map_.erase(iter->second)); - id_map_inverse_.erase(iter); - } - - // Returns whether a node with the given permanent tag was found and update - // |sync_id| with that node's id. - virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { - sync_api::ReadTransaction trans( - sync_service_->backend()->GetUserShareHandle()); - sync_api::ReadNode sync_node(&trans); - if (!sync_node.InitByTagLookup(tag.c_str())) - return false; - *sync_id = sync_node.GetId(); - return true; - } - - // Not implemented. - virtual const KeyType* GetChromeNodeFromSyncId(int64 sync_id) { - return NULL; - } - - // Not implemented. - virtual bool InitSyncNodeFromChromeId(KeyType node_id, - sync_api::BaseNode* sync_node) { - return false; - } - - protected: - typedef std::map<KeyType, int64> AutofillToSyncIdMap; - typedef std::map<int64, KeyType> SyncIdToAutofillMap; - - ProfileSyncService* sync_service_; - WebDatabase* web_database_; - UnrecoverableErrorHandler* error_handler_; - - AutofillToSyncIdMap id_map_; - SyncIdToAutofillMap id_map_inverse_; - - private: - DISALLOW_COPY_AND_ASSIGN(AbstractAutofillModelAssociator); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_ABSTRACT_AUTOFILL_MODEL_ASSOCIATOR_H_ - diff --git a/chrome/browser/sync/glue/autofill_change_processor.cc b/chrome/browser/sync/glue/autofill_change_processor.cc index c414ec93..a8ffd9b 100644 --- a/chrome/browser/sync/glue/autofill_change_processor.cc +++ b/chrome/browser/sync/glue/autofill_change_processor.cc @@ -14,6 +14,7 @@ #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" #include "chrome/browser/webdata/autofill_change.h" +#include "chrome/browser/webdata/web_data_service.h" #include "chrome/browser/webdata/web_database.h" #include "chrome/common/notification_service.h" @@ -39,30 +40,19 @@ void AutofillChangeProcessor::Observe(NotificationType type, const NotificationDetails& details) { LOG(INFO) << "Observed autofill change."; DCHECK(running()); + DCHECK(NotificationType::AUTOFILL_ENTRIES_CHANGED == type); DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); if (!observing_) { return; } - switch (type.value) { - case NotificationType::AUTOFILL_ENTRIES_CHANGED: { - AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); - ObserveAutofillEntriesChanged(changes); - break; - } - default: - NOTREACHED() << "Invalid NotificationType."; - } -} + AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); -void AutofillChangeProcessor::ObserveAutofillEntriesChanged( - AutofillChangeList* changes) { sync_api::WriteTransaction trans(share_handle()); - for (AutofillChangeList::iterator c = changes->begin(); - c != changes->end(); ++c) { - AutofillChange& change = *c; - switch (change.type()) { + for (AutofillChangeList::iterator change = changes->begin(); + change != changes->end(); ++change) { + switch (change->type()) { case AutofillChange::ADD: { sync_api::ReadNode autofill_root(&trans); @@ -74,9 +64,9 @@ void AutofillChangeProcessor::ObserveAutofillEntriesChanged( } sync_api::WriteNode sync_node(&trans); - std::string tag = AutofillModelAssociator::ForFormfill::KeyToTag( - change.key().name(), change.key().value()); - + std::string tag = + AutofillModelAssociator::KeyToTag(change->key().name(), + change->key().value()); if (!sync_node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) { LOG(ERROR) << "Failed to create autofill sync node."; @@ -86,31 +76,30 @@ void AutofillChangeProcessor::ObserveAutofillEntriesChanged( std::vector<base::Time> timestamps; if (!web_database_->GetAutofillTimestamps( - change.key().name(), - change.key().value(), + change->key().name(), + change->key().value(), ×tamps)) { LOG(ERROR) << "Failed to get timestamps."; error_handler()->OnUnrecoverableError(); return; } - sync_node.SetTitle(UTF16ToWide(change.key().name() + - change.key().value())); + sync_node.SetTitle(UTF16ToWide(change->key().name() + + change->key().value())); - WriteAutofill(&sync_node, AutofillEntry(change.key(), timestamps)); - model_associator_->for_formfill()->Associate(&(change.key()), - sync_node.GetId()); + WriteAutofill(&sync_node, AutofillEntry(change->key(), timestamps)); + model_associator_->Associate(&(change->key()), sync_node.GetId()); } break; case AutofillChange::UPDATE: { sync_api::WriteNode sync_node(&trans); - int64 sync_id = model_associator_->for_formfill()-> - GetSyncIdFromChromeId(change.key()); + int64 sync_id = + model_associator_->GetSyncIdFromChromeId(change->key()); if (sync_api::kInvalidId == sync_id) { LOG(ERROR) << "Unexpected notification for: " << - change.key().name(); + change->key().name(); error_handler()->OnUnrecoverableError(); return; } else { @@ -123,46 +112,43 @@ void AutofillChangeProcessor::ObserveAutofillEntriesChanged( std::vector<base::Time> timestamps; if (!web_database_->GetAutofillTimestamps( - change.key().name(), - change.key().value(), + change->key().name(), + change->key().value(), ×tamps)) { LOG(ERROR) << "Failed to get timestamps."; error_handler()->OnUnrecoverableError(); return; } - WriteAutofill(&sync_node, AutofillEntry(change.key(), timestamps)); + WriteAutofill(&sync_node, AutofillEntry(change->key(), timestamps)); } break; case AutofillChange::REMOVE: - RemoveSyncNode(&change, model_associator_->for_formfill(), &trans); + { + sync_api::WriteNode sync_node(&trans); + int64 sync_id = + model_associator_->GetSyncIdFromChromeId(change->key()); + if (sync_api::kInvalidId == sync_id) { + LOG(ERROR) << "Unexpected notification for: " << + change->key().name(); + error_handler()->OnUnrecoverableError(); + return; + } else { + if (!sync_node.InitByIdLookup(sync_id)) { + LOG(ERROR) << "Autofill node lookup failed."; + error_handler()->OnUnrecoverableError(); + return; + } + model_associator_->Disassociate(sync_node.GetId()); + sync_node.Remove(); + } + } break; } } } -template <class AutofillChangeType, class AssociatorType> -void AutofillChangeProcessor::RemoveSyncNode(AutofillChangeType* change, - AssociatorType* associator, sync_api::WriteTransaction* trans) { - sync_api::WriteNode sync_node(trans); - int64 sync_id = - associator->GetSyncIdFromChromeId(change->key()); - if (sync_api::kInvalidId == sync_id) { - LOG(ERROR) << "Unexpected notification"; - error_handler()->OnUnrecoverableError(); - return; - } else { - if (!sync_node.InitByIdLookup(sync_id)) { - LOG(ERROR) << "Autofill node lookup failed."; - error_handler()->OnUnrecoverableError(); - return; - } - associator->Disassociate(sync_node.GetId()); - sync_node.Remove(); - } -} - void AutofillChangeProcessor::ApplyChangesFromSyncModel( const sync_api::BaseTransaction* trans, const sync_api::SyncManager::ChangeRecord* changes, @@ -243,7 +229,9 @@ void AutofillChangeProcessor::StartObserving() { void AutofillChangeProcessor::StopObserving() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); - notification_registrar_.RemoveAll(); + notification_registrar_.Remove(this, + NotificationType::AUTOFILL_ENTRIES_CHANGED, + NotificationService::AllSources()); } // static diff --git a/chrome/browser/sync/glue/autofill_change_processor.h b/chrome/browser/sync/glue/autofill_change_processor.h index 87a9446..ccd266d 100644 --- a/chrome/browser/sync/glue/autofill_change_processor.h +++ b/chrome/browser/sync/glue/autofill_change_processor.h @@ -9,13 +9,10 @@ #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/sync_backend_host.h" -#include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" -class AutofillCreditCardChange; class AutofillEntry; -class AutofillProfileChange; class WebDatabase; namespace browser_sync { @@ -59,13 +56,6 @@ class AutofillChangeProcessor : public ChangeProcessor, void StartObserving(); void StopObserving(); - void ObserveAutofillEntriesChanged(AutofillChangeList* changes); - - template <class AutofillChangeType, class AssociatorType> - void RemoveSyncNode(AutofillChangeType* change, - AssociatorType* associator, - sync_api::WriteTransaction* trans); - // The two models should be associated according to this ModelAssociator. AutofillModelAssociator* model_associator_; diff --git a/chrome/browser/sync/glue/autofill_model_associator.cc b/chrome/browser/sync/glue/autofill_model_associator.cc index fab7f87..06d3427 100644 --- a/chrome/browser/sync/glue/autofill_model_associator.cc +++ b/chrome/browser/sync/glue/autofill_model_associator.cc @@ -17,28 +17,22 @@ namespace browser_sync { -AutofillModelAssociator::ForFormfill::ForFormfill( - ProfileSyncService* sync_service, WebDatabase* web_database, - UnrecoverableErrorHandler* error_handler) - : AbstractAutofillModelAssociator<AutofillKey>(sync_service, web_database, - error_handler) { -} - -AutofillModelAssociator::ForProfiles::ForProfiles( - ProfileSyncService* sync_service, WebDatabase* web_database, - UnrecoverableErrorHandler* error_handler) - : AbstractAutofillModelAssociator<std::string>(sync_service, web_database, - error_handler) { -} +const char kAutofillTag[] = "google_chrome_autofill"; AutofillModelAssociator::AutofillModelAssociator( - ProfileSyncService* sync_service, WebDatabase* web_database, + ProfileSyncService* sync_service, + WebDatabase* web_database, UnrecoverableErrorHandler* error_handler) - : for_formfill_(sync_service, web_database, error_handler), - for_profiles_(sync_service, web_database, error_handler) { + : sync_service_(sync_service), + web_database_(web_database), + error_handler_(error_handler), + autofill_node_id_(sync_api::kInvalidId) { + DCHECK(sync_service_); + DCHECK(web_database_); + DCHECK(error_handler_); } -bool AutofillModelAssociator::ForFormfill::AssociateModels() { +bool AutofillModelAssociator::AssociateModels() { LOG(INFO) << "Associating Autofill Models"; DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); @@ -153,14 +147,86 @@ bool AutofillModelAssociator::ForFormfill::AssociateModels() { return true; } +bool AutofillModelAssociator::DisassociateModels() { + id_map_.clear(); + id_map_inverse_.clear(); + return true; +} + +bool AutofillModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { + DCHECK(has_nodes); + *has_nodes = false; + int64 autofill_sync_id; + if (!GetSyncIdForTaggedNode(kAutofillTag, &autofill_sync_id)) { + LOG(ERROR) << "Server did not create the top-level autofill node. We " + << "might be running against an out-of-date server."; + return false; + } + sync_api::ReadTransaction trans( + sync_service_->backend()->GetUserShareHandle()); + + sync_api::ReadNode autofill_node(&trans); + if (!autofill_node.InitByIdLookup(autofill_sync_id)) { + LOG(ERROR) << "Server did not create the top-level autofill node. We " + << "might be running against an out-of-date server."; + return false; + } + + // The sync model has user created nodes if the autofill folder has any + // children. + *has_nodes = sync_api::kInvalidId != autofill_node.GetFirstChildId(); + return true; +} + +bool AutofillModelAssociator::ChromeModelHasUserCreatedNodes(bool* has_nodes) { + DCHECK(has_nodes); + // Assume the autofill model always have user-created nodes. + *has_nodes = true; + return true; +} + +int64 AutofillModelAssociator::GetSyncIdFromChromeId( + const AutofillKey autofill) { + AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); + return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; +} + +void AutofillModelAssociator::Associate( + const AutofillKey* autofill, int64 sync_id) { + DCHECK_NE(sync_api::kInvalidId, sync_id); + DCHECK(id_map_.find(*autofill) == id_map_.end()); + DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); + id_map_[*autofill] = sync_id; + id_map_inverse_[sync_id] = *autofill; +} + +void AutofillModelAssociator::Disassociate(int64 sync_id) { + SyncIdToAutofillMap::iterator iter = id_map_inverse_.find(sync_id); + if (iter == id_map_inverse_.end()) + return; + CHECK(id_map_.erase(iter->second)); + id_map_inverse_.erase(iter); +} + +bool AutofillModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, + int64* sync_id) { + sync_api::ReadTransaction trans( + sync_service_->backend()->GetUserShareHandle()); + sync_api::ReadNode sync_node(&trans); + if (!sync_node.InitByTagLookup(tag.c_str())) + return false; + *sync_id = sync_node.GetId(); + return true; +} + // static -std::string AutofillModelAssociator::ForFormfill::KeyToTag( - const string16& name, const string16& value) { +std::string AutofillModelAssociator::KeyToTag(const string16& name, + const string16& value) { return EscapePath(UTF16ToUTF8(name)) + "|" + EscapePath(UTF16ToUTF8(value)); } // static -bool AutofillModelAssociator::ForFormfill::MergeTimestamps( +bool AutofillModelAssociator::MergeTimestamps( const sync_pb::AutofillSpecifics& autofill, const std::vector<base::Time>& timestamps, std::vector<base::Time>* new_timestamps) { @@ -186,31 +252,4 @@ bool AutofillModelAssociator::ForFormfill::MergeTimestamps( return different; } -bool AutofillModelAssociator::AssociateModels() { - return for_formfill_.AssociateModels() && - for_profiles_.AssociateModels(); -} - -bool AutofillModelAssociator::DisassociateModels() { - return for_formfill_.DisassociateModels() && - for_profiles_.DisassociateModels(); -} - -bool AutofillModelAssociator::SyncModelHasUserCreatedNodes( - bool* has_nodes) { - return for_formfill_.SyncModelHasUserCreatedNodes(has_nodes); -} - -bool AutofillModelAssociator::ChromeModelHasUserCreatedNodes( - bool* has_nodes) { - return for_formfill_.ChromeModelHasUserCreatedNodes(has_nodes) && - !(*has_nodes) ? - for_profiles_.ChromeModelHasUserCreatedNodes(has_nodes) : true; -} - -bool AutofillModelAssociator::ForProfiles::AssociateModels() { - // TODO(tim): Implement me! - return true; -} - } // namespace browser_sync diff --git a/chrome/browser/sync/glue/autofill_model_associator.h b/chrome/browser/sync/glue/autofill_model_associator.h index a6cc369..41a6387 100644 --- a/chrome/browser/sync/glue/autofill_model_associator.h +++ b/chrome/browser/sync/glue/autofill_model_associator.h @@ -13,7 +13,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/chrome_thread.h" -#include "chrome/browser/sync/glue/abstract_autofill_model_associator.h" +#include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" #include "chrome/browser/webdata/autofill_entry.h" @@ -25,47 +25,83 @@ namespace browser_sync { class AutofillChangeProcessor; class UnrecoverableErrorHandler; -class AutofillModelAssociator : public AssociatorInterface { - public: - class ForFormfill : public AbstractAutofillModelAssociator<AutofillKey> { - public: - ForFormfill(ProfileSyncService* sync_service, - WebDatabase* web_database, - UnrecoverableErrorHandler* error_handler); - // AbstractAutofillModelAssociator implementation. - virtual bool AssociateModels(); - - static std::string KeyToTag(const string16& name, const string16& value); - static bool MergeTimestamps(const sync_pb::AutofillSpecifics& autofill, - const std::vector<base::Time>& timestamps, - std::vector<base::Time>* new_timestamps); - }; - - class ForProfiles : public AbstractAutofillModelAssociator<std::string> { - public: - ForProfiles(ProfileSyncService* sync_service, - WebDatabase* web_database, - UnrecoverableErrorHandler* error_handler); - // AbstractAutofillModelAssociator implementation. - virtual bool AssociateModels(); - }; +extern const char kAutofillTag[]; +// Contains all model association related logic: +// * Algorithm to associate autofill model and sync model. +// We do not check if we have local data before this run; we always +// merge and sync. +class AutofillModelAssociator + : public PerDataTypeAssociatorInterface<AutofillKey, AutofillKey> { + public: + static syncable::ModelType model_type() { return syncable::AUTOFILL; } AutofillModelAssociator(ProfileSyncService* sync_service, WebDatabase* web_database, UnrecoverableErrorHandler* error_handler); + virtual ~AutofillModelAssociator() { } - // AssociatorInterface implementation. + // PerDataTypeAssociatorInterface implementation. + // + // Iterates through the sync model looking for matched pairs of items. virtual bool AssociateModels(); + + // Clears all associations. virtual bool DisassociateModels(); + + // The has_nodes out param is true if the sync model has nodes other + // than the permanent tagged nodes. virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); + + // The has_nodes out param is true if the autofill model has any + // user-defined autofill entries. virtual bool ChromeModelHasUserCreatedNodes(bool* has_nodes); - ForFormfill* for_formfill() { return &for_formfill_; } - ForProfiles* for_profiles() { return &for_profiles_; } + // Not implemented. + virtual const AutofillKey* GetChromeNodeFromSyncId(int64 sync_id) { + return NULL; + } + + // Not implemented. + virtual bool InitSyncNodeFromChromeId(AutofillKey node_id, + sync_api::BaseNode* sync_node) { + return false; + } + + // Returns the sync id for the given autofill name, or sync_api::kInvalidId + // if the autofill name is not associated to any sync id. + virtual int64 GetSyncIdFromChromeId(AutofillKey node_id); + + // Associates the given autofill name with the given sync id. + virtual void Associate(const AutofillKey* node, int64 sync_id); + + // Remove the association that corresponds to the given sync id. + virtual void Disassociate(int64 sync_id); + + // Returns whether a node with the given permanent tag was found and update + // |sync_id| with that node's id. + virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); + + static std::string KeyToTag(const string16& name, const string16& value); + static bool MergeTimestamps(const sync_pb::AutofillSpecifics& autofill, + const std::vector<base::Time>& timestamps, + std::vector<base::Time>* new_timestamps); + + protected: + // Returns sync service instance. + ProfileSyncService* sync_service() { return sync_service_; } private: - ForFormfill for_formfill_; - ForProfiles for_profiles_; + typedef std::map<AutofillKey, int64> AutofillToSyncIdMap; + typedef std::map<int64, AutofillKey> SyncIdToAutofillMap; + + ProfileSyncService* sync_service_; + WebDatabase* web_database_; + UnrecoverableErrorHandler* error_handler_; + int64 autofill_node_id_; + + AutofillToSyncIdMap id_map_; + SyncIdToAutofillMap id_map_inverse_; + DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); }; diff --git a/chrome/browser/sync/glue/autofill_model_associator_unittest.cc b/chrome/browser/sync/glue/autofill_model_associator_unittest.cc index 94343bc..240962a 100644 --- a/chrome/browser/sync/glue/autofill_model_associator_unittest.cc +++ b/chrome/browser/sync/glue/autofill_model_associator_unittest.cc @@ -14,15 +14,15 @@ class AutofillModelAssociatorTest : public testing::Test { TEST_F(AutofillModelAssociatorTest, KeyToTag) { EXPECT_EQ("foo|bar", - AutofillModelAssociator::ForFormfill::KeyToTag(UTF8ToUTF16("foo"), - UTF8ToUTF16("bar"))); + AutofillModelAssociator::KeyToTag(UTF8ToUTF16("foo"), + UTF8ToUTF16("bar"))); EXPECT_EQ("%7C|%7C", - AutofillModelAssociator::ForFormfill::KeyToTag(UTF8ToUTF16("|"), - UTF8ToUTF16("|"))); + AutofillModelAssociator::KeyToTag(UTF8ToUTF16("|"), + UTF8ToUTF16("|"))); EXPECT_EQ("%7C|", - AutofillModelAssociator::ForFormfill::KeyToTag(UTF8ToUTF16("|"), - UTF8ToUTF16(""))); + AutofillModelAssociator::KeyToTag(UTF8ToUTF16("|"), + UTF8ToUTF16(""))); EXPECT_EQ("|%7C", - AutofillModelAssociator::ForFormfill::KeyToTag(UTF8ToUTF16(""), - UTF8ToUTF16("|"))); + AutofillModelAssociator::KeyToTag(UTF8ToUTF16(""), + UTF8ToUTF16("|"))); } diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index b7f01dc..85c12b0 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -189,8 +189,8 @@ class ProfileSyncServiceAutofillTest : public testing::Test { ASSERT_TRUE(autofill_root.InitByTagLookup(browser_sync::kAutofillTag)); sync_api::WriteNode node(&trans); - std::string tag = AutofillModelAssociator::ForFormfill::KeyToTag( - entry.key().name(), entry.key().value()); + std::string tag = AutofillModelAssociator::KeyToTag(entry.key().name(), + entry.key().value()); ASSERT_TRUE(node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5335a20b..6d1a117 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1922,7 +1922,6 @@ 'browser/transport_security_persister.cc', 'browser/transport_security_persister.h', 'browser/sync/engine/syncapi.h', - 'browser/sync/glue/abstract_autofill_model_associator.h', 'browser/sync/glue/autofill_change_processor.h', 'browser/sync/glue/autofill_change_processor.cc', 'browser/sync/glue/autofill_data_type_controller.cc', |