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 cc5a37f9d5f5ede3347eacfa5155c3eac9d58872..33c3bdc8fe2b5724aa35ac6db147746d4b7e9084 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" |
tim (not reviewing)
2010/12/13 19:24:33
illegal include
lipalani
2010/12/14 21:05:57
Done.
|
#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::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::MIGRATED) { |
+ syncable::AutofillMigrationDebugInfo debug_info; |
+ debug_info.autofill_entries_added_during_migration = |
+ number_of_entries_created_; |
+ sync_service_->backend()->SetAutofillMigrationDebugInfo( |
+ syncable::AutofillMigrationDebugInfo::ENTRIES_ADDED, |
+ debug_info); |
+ } |
+ |
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
- new DoOptimisticRefreshTask(personal_data_)); |
+ new DoOptimisticRefreshForAutofill(personal_data_)); |
return true; |
} |
@@ -244,6 +237,27 @@ bool AutofillModelAssociator::TraverseAndAssociateAllSyncNodes( |
const std::vector<AutoFillProfile*>& all_profiles_from_db) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
+ bool autofill_profile_not_migrated = HasNotMigratedYet(write_trans); |
+ |
+ if (MigrationLoggingEnabled() && |
+ autofill_profile_not_migrated) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "Printing profiles from web db"; |
+ |
+ for (std::vector<AutoFillProfile*>::const_iterator ix = |
+ all_profiles_from_db.begin(); ix != all_profiles_from_db.end(); ++ix) { |
+ AutoFillProfile* p = *ix; |
+ VLOG(1) << "[AUTOFILL MIGRATION] " |
+ << UTF16ToUTF8(p->GetFieldText(AutoFillType(NAME_FIRST))) |
+ << UTF16ToUTF8(p->GetFieldText(AutoFillType(NAME_LAST))); |
+ } |
+ } |
+ |
+ if (MigrationLoggingEnabled() && autofill_profile_not_migrated) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "Iterating over sync db"; |
+ } |
+ |
int64 sync_child_id = autofill_root.GetFirstChildId(); |
while (sync_child_id != sync_api::kInvalidId) { |
sync_api::ReadNode sync_child(write_trans); |
@@ -256,13 +270,20 @@ 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) { |
+ if (MigrationLoggingEnabled()) { |
+ VLOG(1) << "[AUTOFILL MIGRATION] Looking for " |
tim (not reviewing)
2010/12/13 19:24:33
it seems weird to combine vlog with another condit
lipalani
2010/12/14 21:05:57
Would it be OK if I dealt with logging on the next
|
+ << autofill.profile().name_first() |
+ << autofill.profile().name_last(); |
+ } |
+ AddNativeProfileIfNeeded( |
+ autofill.profile(), |
+ bundle, |
+ sync_child, |
+ all_profiles_from_db); |
+ } |
} else { |
NOTREACHED() << "AutofillSpecifics has no autofill data!"; |
} |
@@ -332,15 +353,23 @@ 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( |
+ profile, all_profiles_from_db); |
- if (profile_in_web_db.get() != NULL) { |
+ if (profile_in_web_db != NULL) { |
+ if (MigrationLoggingEnabled()) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "Node found in web db. So associating"; |
+ } |
int64 sync_id = node.GetId(); |
std::string guid = profile_in_web_db->guid(); |
Associate(&guid, sync_id); |
return; |
} else { // Create a new node. |
+ if (MigrationLoggingEnabled()) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "Node not found in web db so creating and associating"; |
+ } |
std::string guid = guid::GenerateGUID(); |
Associate(&guid, node.GetId()); |
AutoFillProfile* p = new AutoFillProfile(guid); |
@@ -509,8 +538,72 @@ bool AutofillModelAssociator::FillProfileWithServerData( |
return diff; |
} |
-bool AutofillModelAssociator::HasNotMigratedYet() { |
- return true; |
+bool AutofillModelAssociator::HasNotMigratedYet( |
+ const sync_api::BaseTransaction* trans) { |
+ |
+ // 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_ == |
tim (not reviewing)
2010/12/13 19:24:33
I thought we were getting rid of this cache?
lipalani
2010/12/14 21:05:57
Yeah I got rid of it! it is reflected in the curre
|
+ syncable::MIGRATED) { |
tim (not reviewing)
2010/12/13 19:24:33
I think this fits on previous line, but it shouldn
lipalani
2010/12/14 21:05:57
I fixed the line indentation. Not sure I understan
|
+ return false; |
+ } |
+ |
+ // Now read the current value from the directory. |
+ autofill_migration_state_ = |
+ sync_service()->backend()->GetAutofillMigrationState(); |
+ |
+ DCHECK_NE(autofill_migration_state_, syncable::NOT_DETERMINED); |
+ |
+ if (autofill_migration_state_== syncable::NOT_DETERMINED) { |
+ VLOG(1) << "Autofill migration state is not determined inside " |
+ << " model associator"; |
+ } |
+ if (autofill_migration_state_ == |
+ syncable::NOT_MIGRATED) { |
tim (not reviewing)
2010/12/13 19:24:33
same comment as above
lipalani
2010/12/14 21:05:57
Done.
|
+ return true; |
+ } |
+ |
+ if (autofill_migration_state_ == |
+ syncable::INSUFFICIENT_INFO_TO_DETERMINE) { |
+ if (MigrationLoggingEnabled()) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "current autofill migration state is 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::NOT_MIGRATED); |
+ |
+ if (MigrationLoggingEnabled()) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "Current autofill migration state is NOT Migrated becausse" |
+ << "legacy autofil root node is preseent whereas new " |
+ << "Autofill profile root node is not present"; |
+ } |
+ return true; |
+ } |
+ |
+ sync_service()->backend()->SetAutofillMigrationState( |
+ syncable::MIGRATED); |
+ |
+ if (MigrationLoggingEnabled()) { |
+ VLOG(1) << "[AUTOFILL MIGRATION]" |
+ << "Current autofill migration state is migrated"; |
+ } |
+ autofill_migration_state_ = |
+ syncable::MIGRATED; |
tim (not reviewing)
2010/12/13 19:24:33
prev line
lipalani
2010/12/14 21:05:57
Removed.
On 2010/12/13 19:24:33, timsteele wrote:
|
+ } |
+ |
+ return false; |
} |
+bool AutofillModelAssociator::MigrationLoggingEnabled() { |
+ // [TODO] enable logging via a command line flag. |
tim (not reviewing)
2010/12/13 19:24:33
what's the plan here?
lipalani
2010/12/14 21:05:57
Logging part of the next cl?
On 2010/12/13 19:24:3
|
+ return false; |
+} |
} // namespace browser_sync |
+ |