Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1008)

Unified Diff: chrome/browser/sync/glue/autofill_model_associator.cc

Issue 5159001: Rest of the autofill work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Autofill code after fixing the lint errors. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/autofill_model_associator.cc
diff --git a/chrome/browser/sync/glue/autofill_model_associator.cc b/chrome/browser/sync/glue/autofill_model_associator.cc
index 9047d2f271df26495d8fb652fe37df78c709c78e..0cc199a7cc71719a64c534dbf75d2e6507cd5560 100644
--- a/chrome/browser/sync/glue/autofill_model_associator.cc
+++ b/chrome/browser/sync/glue/autofill_model_associator.cc
@@ -13,12 +13,17 @@
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/guid.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/autofill_change_processor.h"
+#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
+#include "chrome/browser/sync/glue/do_optimistic_refresh_Task.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
+#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/webdata/web_database.h"
+#include "chrome/common/pref_names.h"
#include "net/base/escape.h"
using base::TimeTicks;
@@ -37,16 +42,6 @@ struct AutofillModelAssociator::DataBundle {
~DataBundle() { STLDeleteElements(&new_profiles); }
};
-AutofillModelAssociator::DoOptimisticRefreshTask::DoOptimisticRefreshTask(
- PersonalDataManager* pdm) : pdm_(pdm) {}
-
-AutofillModelAssociator::DoOptimisticRefreshTask::~DoOptimisticRefreshTask() {}
-
-void AutofillModelAssociator::DoOptimisticRefreshTask::Run() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- pdm_->Refresh();
-}
-
AutofillModelAssociator::AutofillModelAssociator(
ProfileSyncService* sync_service,
WebDatabase* web_database,
@@ -55,7 +50,9 @@ AutofillModelAssociator::AutofillModelAssociator(
web_database_(web_database),
personal_data_(personal_data),
autofill_node_id_(sync_api::kInvalidId),
- abort_association_pending_(false) {
+ autofill_migration_state_(syncable::Directory::PersistedKernelInfo::NOT_DETERMINED),
+ abort_association_pending_(false),
+ number_of_entries_created_(0) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
DCHECK(sync_service_);
DCHECK(web_database_);
@@ -114,6 +111,7 @@ bool AutofillModelAssociator::TraverseAndAssociateChromeAutofillEntries(
node.SetTitle(UTF8ToWide(tag));
AutofillChangeProcessor::WriteAutofillEntry(*ix, &node);
Associate(&tag, node.GetId());
+ number_of_entries_created_++;
}
current_entries->insert(ix->key());
@@ -121,21 +119,6 @@ bool AutofillModelAssociator::TraverseAndAssociateChromeAutofillEntries(
return true;
}
-bool AutofillModelAssociator::MakeNewAutofillProfileSyncNode(
- sync_api::WriteTransaction* trans, const sync_api::BaseNode& autofill_root,
- const std::string& tag, const AutoFillProfile& profile, int64* sync_id) {
- sync_api::WriteNode node(trans);
- if (!node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag)) {
- LOG(ERROR) << "Failed to create autofill sync node.";
- return false;
- }
- node.SetTitle(UTF8ToWide(tag));
- AutofillChangeProcessor::WriteAutofillProfile(profile, &node);
- *sync_id = node.GetId();
- return true;
-}
-
-
bool AutofillModelAssociator::LoadAutofillData(
std::vector<AutofillEntry>* entries,
std::vector<AutoFillProfile*>* profiles) {
@@ -205,8 +188,18 @@ bool AutofillModelAssociator::AssociateModels() {
return false;
}
+ if (sync_service_->backend()->GetAutofillMigrationState() !=
+ syncable::Directory::PersistedKernelInfo::MIGRATED) {
+ syncable::AutofillMigrationDebugInfo debug_info;
tim (not reviewing) 2010/12/10 22:16:02 indent here or line above looks off
lipalani 2010/12/11 00:12:36 Done.
+ debug_info.autofill_entries_added_during_migration =
+ number_of_entries_created_;
tim (not reviewing) 2010/12/10 22:16:02 4 spaces indent
lipalani 2010/12/11 00:12:36 Done.
+ sync_service_->backend()->SetAutofillMigrationDebugInfo(
+ syncable::AutofillMigrationDebugInfo::ENTRIES_ADDED,
tim (not reviewing) 2010/12/10 22:16:02 4 spaces indent
lipalani 2010/12/11 00:12:36 Done.
+ debug_info);
+ }
+
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- new DoOptimisticRefreshTask(personal_data_));
+ new DoOptimisticRefreshForAutofill(personal_data_));
return true;
}
@@ -244,6 +237,8 @@ bool AutofillModelAssociator::TraverseAndAssociateAllSyncNodes(
const std::vector<AutoFillProfile*>& all_profiles_from_db) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ bool autofill_profile_not_migrated = HasNotMigratedYet(write_trans);
+
int64 sync_child_id = autofill_root.GetFirstChildId();
while (sync_child_id != sync_api::kInvalidId) {
sync_api::ReadNode sync_child(write_trans);
@@ -256,13 +251,15 @@ bool AutofillModelAssociator::TraverseAndAssociateAllSyncNodes(
if (autofill.has_value()) {
AddNativeEntryIfNeeded(autofill, bundle, sync_child);
- } else if (autofill.has_profile() && HasNotMigratedYet()) {
+ } else if (autofill.has_profile()) {
// Ignore autofill profiles if we are not upgrading.
- AddNativeProfileIfNeeded(
- autofill.profile(),
- bundle,
- sync_child,
- all_profiles_from_db);
+ if (autofill_profile_not_migrated) {
+ AddNativeProfileIfNeeded(
+ autofill.profile(),
+ bundle,
+ sync_child,
+ all_profiles_from_db);
+ }
} else {
NOTREACHED() << "AutofillSpecifics has no autofill data!";
}
@@ -332,10 +329,10 @@ void AutofillModelAssociator::AddNativeProfileIfNeeded(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
- scoped_ptr<AutoFillProfile> profile_in_web_db(FindCorrespondingNodeFromWebDB(
- profile, all_profiles_from_db));
+ AutoFillProfile* profile_in_web_db = FindCorrespondingNodeFromWebDB(
tim (not reviewing) 2010/12/10 22:16:02 why no scoped_ptr?
lipalani 2010/12/11 00:12:36 The pointer we are getting is part of the vector a
+ profile, all_profiles_from_db);
- if (profile_in_web_db.get() != NULL) {
+ if (profile_in_web_db != NULL) {
int64 sync_id = node.GetId();
std::string guid = profile_in_web_db->guid();
Associate(&guid, sync_id);
@@ -509,8 +506,48 @@ bool AutofillModelAssociator::FillProfileWithServerData(
return diff;
}
-bool AutofillModelAssociator::HasNotMigratedYet() {
- return true;
-}
+bool AutofillModelAssociator::HasNotMigratedYet(
+ const sync_api::BaseTransaction* trans) {
+
lipalani 2010/12/09 19:45:25 get rid of the variable.
lipalani 2010/12/11 00:12:36 we need the transaction variable. this comment was
+ // If state is migrated in our cached variable return true. We dont have
+ // to check against the directory as it will not change.
+ if (autofill_migration_state_ ==
+ syncable::Directory::PersistedKernelInfo::MIGRATED) {
+ return false;
+ }
+
+ // Now read the current value from the directory.
+ autofill_migration_state_ =
+ sync_service()->backend()->GetAutofillMigrationState();
+
lipalani 2010/12/09 19:45:25 add a redirect comment.
lipalani 2010/12/11 00:12:36 Done.
+ DCHECK_NE(autofill_migration_state_,
+ syncable::Directory::PersistedKernelInfo::NOT_DETERMINED);
+ if (autofill_migration_state_ ==
+ syncable::Directory::PersistedKernelInfo::NOT_MIGRATED) {
+ return true;
+ }
+
+ if (autofill_migration_state_ ==
+ syncable::Directory::PersistedKernelInfo::INSUFFICIENT_INFO_TO_DETERMINE) {
+ sync_api::ReadNode autofill_profile_root_node(trans);
+ if (!autofill_profile_root_node.InitByTagLookup(
+ browser_sync::kAutofillProfileTag) ||
+ autofill_profile_root_node.GetFirstChildId()==
+ static_cast<int64>(0)) {
+ sync_service()->backend()->SetAutofillMigrationState(
+ syncable::Directory::PersistedKernelInfo::NOT_MIGRATED);
+ return true;
+ }
+
+ sync_service()->backend()->SetAutofillMigrationState(
+ syncable::Directory::PersistedKernelInfo::MIGRATED);
+
+ autofill_migration_state_ =
+ syncable::Directory::PersistedKernelInfo::MIGRATED;
+ }
+ return false;
+
+}
} // namespace browser_sync
+

Powered by Google App Engine
This is Rietveld 408576698