Commit 2f0c4225 authored by isherman@chromium.org's avatar isherman@chromium.org

[Autofill] Style cleanup: Move AutofillProfileSyncableService into the autofill namespace.

Also, re-arrange a bit of code in the implementation file for slightly clearer
structuring.

BUG=none
TEST=none
R=estade@chromium.org
TBR=joi@chromium.org,zea@chromium.org

Review URL: https://codereview.chromium.org/122313007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243541 0039d316-1c4b-4281-b951-d872f2087c98
parent 8192fb46
......@@ -376,7 +376,7 @@ base::WeakPtr<syncer::SyncableService> ProfileSyncComponentsFactoryImpl::
return AutocompleteSyncableService::FromWebDataService(
web_data_service_.get())->AsWeakPtr();
} else {
return AutofillProfileSyncableService::FromWebDataService(
return autofill::AutofillProfileSyncableService::FromWebDataService(
web_data_service_.get())->AsWeakPtr();
}
}
......
......@@ -69,6 +69,7 @@ using autofill::ServerFieldType;
using autofill::AutofillKey;
using autofill::AutofillProfile;
using autofill::AutofillProfileChange;
using autofill::AutofillProfileSyncableService;
using autofill::AutofillTable;
using autofill::AutofillWebDataService;
using autofill::PersonalDataManager;
......@@ -642,7 +643,7 @@ class ProfileSyncServiceAutofillTest
bool AddAutofillSyncNode(const AutofillProfile& profile) {
syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
syncer::ReadNode autofill_root(&trans);
if (autofill_root.InitByTagLookup(kAutofillProfileTag) !=
if (autofill_root.InitByTagLookup(autofill::kAutofillProfileTag) !=
BaseNode::INIT_OK) {
return false;
}
......@@ -706,7 +707,7 @@ class ProfileSyncServiceAutofillTest
std::vector<AutofillProfile>* profiles) {
syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
syncer::ReadNode autofill_root(&trans);
if (autofill_root.InitByTagLookup(kAutofillProfileTag) !=
if (autofill_root.InitByTagLookup(autofill::kAutofillProfileTag) !=
BaseNode::INIT_OK) {
return false;
}
......
......@@ -22,14 +22,10 @@
using base::ASCIIToUTF16;
using base::UTF8ToUTF16;
using base::UTF16ToUTF8;
using autofill::AutofillCountry;
using autofill::ServerFieldType;
using autofill::AutofillProfile;
using autofill::AutofillProfileChange;
using autofill::AutofillTable;
using autofill::AutofillWebDataService;
using content::BrowserThread;
namespace autofill {
namespace {
std::string LimitData(const std::string& data) {
......@@ -51,7 +47,7 @@ void* UserDataKey() {
const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
AutofillProfileSyncableService::AutofillProfileSyncableService(
autofill::AutofillWebDataBackend* webdata_backend,
AutofillWebDataBackend* webdata_backend,
const std::string& app_locale)
: webdata_backend_(webdata_backend),
app_locale_(app_locale),
......@@ -69,7 +65,7 @@ AutofillProfileSyncableService::~AutofillProfileSyncableService() {
// static
void AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
AutofillWebDataService* web_data_service,
autofill::AutofillWebDataBackend* webdata_backend,
AutofillWebDataBackend* webdata_backend,
const std::string& app_locale) {
web_data_service->GetDBUserData()->SetUserData(
UserDataKey(),
......@@ -118,8 +114,8 @@ AutofillProfileSyncableService::MergeDataAndStartSyncing(
profiles_.begin(); ix != profiles_.end(); ++ix) {
AutofillProfile* p = *ix;
DVLOG(2) << "[AUTOFILL MIGRATION] "
<< p->GetRawInfo(autofill::NAME_FIRST)
<< p->GetRawInfo(autofill::NAME_LAST)
<< UTF16ToUTF8(p->GetRawInfo(NAME_FIRST))
<< UTF16ToUTF8(p->GetRawInfo(NAME_LAST))
<< p->guid();
}
}
......@@ -157,8 +153,8 @@ AutofillProfileSyncableService::MergeDataAndStartSyncing(
bundle.profiles_to_sync_back.push_back(it->second);
DVLOG(2) << "[AUTOFILL SYNC]"
<< "Found similar profile in sync db but with a different guid: "
<< UTF16ToUTF8(it->second->GetRawInfo(autofill::NAME_FIRST))
<< UTF16ToUTF8(it->second->GetRawInfo(autofill::NAME_LAST))
<< UTF16ToUTF8(it->second->GetRawInfo(NAME_FIRST))
<< UTF16ToUTF8(it->second->GetRawInfo(NAME_LAST))
<< "New guid " << it->second->guid()
<< ". Profile to be deleted "
<< profile_to_merge->second->guid();
......@@ -298,7 +294,7 @@ bool AutofillProfileSyncableService::SaveChangesToWebData(
const DataBundle& bundle) {
DCHECK(CalledOnValidThread());
autofill::AutofillTable* autofill_table = GetAutofillTable();
AutofillTable* autofill_table = GetAutofillTable();
bool success = true;
for (size_t i = 0; i< bundle.profiles_to_delete.size(); ++i) {
......@@ -333,35 +329,41 @@ bool AutofillProfileSyncableService::OverwriteProfileWithServerData(
DCHECK(!was_verified || profile->IsVerified());
}
diff = UpdateMultivaluedField(autofill::NAME_FIRST,
// Update all multivalued fields: names, emails, and phones.
diff = UpdateMultivaluedField(NAME_FIRST,
specifics.name_first(), profile) || diff;
diff = UpdateMultivaluedField(autofill::NAME_MIDDLE,
diff = UpdateMultivaluedField(NAME_MIDDLE,
specifics.name_middle(), profile) || diff;
diff = UpdateMultivaluedField(autofill::NAME_LAST,
diff = UpdateMultivaluedField(NAME_LAST,
specifics.name_last(), profile) || diff;
diff = UpdateField(autofill::ADDRESS_HOME_LINE1,
diff = UpdateMultivaluedField(EMAIL_ADDRESS,
specifics.email_address(), profile) || diff;
diff = UpdateMultivaluedField(PHONE_HOME_WHOLE_NUMBER,
specifics.phone_home_whole_number(),
profile) || diff;
// Update all simple single-valued address fields.
diff = UpdateField(COMPANY_NAME, specifics.company_name(), profile) || diff;
diff = UpdateField(ADDRESS_HOME_LINE1,
specifics.address_home_line1(), profile) || diff;
diff = UpdateField(autofill::ADDRESS_HOME_LINE2,
diff = UpdateField(ADDRESS_HOME_LINE2,
specifics.address_home_line2(), profile) || diff;
diff = UpdateField(autofill::ADDRESS_HOME_CITY,
diff = UpdateField(ADDRESS_HOME_CITY,
specifics.address_home_city(), profile) || diff;
diff = UpdateField(autofill::ADDRESS_HOME_STATE,
diff = UpdateField(ADDRESS_HOME_STATE,
specifics.address_home_state(), profile) || diff;
diff = UpdateField(ADDRESS_HOME_ZIP,
specifics.address_home_zip(), profile) || diff;
// Update the country field, which can contain either a country code (if set
// by a newer version of Chrome), or a country name (if set by an older
// version of Chrome).
base::string16 country_name_or_code =
ASCIIToUTF16(specifics.address_home_country());
std::string country_code = AutofillCountry::GetCountryCode(
country_name_or_code, app_locale);
diff = UpdateField(
autofill::ADDRESS_HOME_COUNTRY, country_code, profile) || diff;
diff = UpdateField(autofill::ADDRESS_HOME_ZIP,
specifics.address_home_zip(), profile) || diff;
diff = UpdateMultivaluedField(autofill::EMAIL_ADDRESS,
specifics.email_address(), profile) || diff;
diff = UpdateField(
autofill::COMPANY_NAME, specifics.company_name(), profile) || diff;
diff = UpdateMultivaluedField(autofill::PHONE_HOME_WHOLE_NUMBER,
specifics.phone_home_whole_number(),
profile) || diff;
std::string country_code =
AutofillCountry::GetCountryCode(country_name_or_code, app_locale);
diff = UpdateField(ADDRESS_HOME_COUNTRY, country_code, profile) || diff;
return diff;
}
......@@ -385,44 +387,43 @@ void AutofillProfileSyncableService::WriteAutofillProfile(
specifics->set_origin(profile.origin());
std::vector<base::string16> values;
profile.GetRawMultiInfo(autofill::NAME_FIRST, &values);
profile.GetRawMultiInfo(NAME_FIRST, &values);
for (size_t i = 0; i < values.size(); ++i) {
specifics->add_name_first(LimitData(UTF16ToUTF8(values[i])));
}
profile.GetRawMultiInfo(autofill::NAME_MIDDLE, &values);
profile.GetRawMultiInfo(NAME_MIDDLE, &values);
for (size_t i = 0; i < values.size(); ++i) {
specifics->add_name_middle(LimitData(UTF16ToUTF8(values[i])));
}
profile.GetRawMultiInfo(autofill::NAME_LAST, &values);
profile.GetRawMultiInfo(NAME_LAST, &values);
for (size_t i = 0; i < values.size(); ++i) {
specifics->add_name_last(LimitData(UTF16ToUTF8(values[i])));
}
specifics->set_address_home_line1(
LimitData(UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_LINE1))));
LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE1))));
specifics->set_address_home_line2(
LimitData(UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_LINE2))));
LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE2))));
specifics->set_address_home_city(
LimitData(UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_CITY))));
LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY))));
specifics->set_address_home_state(
LimitData(UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_STATE))));
specifics->set_address_home_country(
LimitData(
UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY))));
LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE))));
specifics->set_address_home_zip(
LimitData(UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP))));
LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP))));
specifics->set_address_home_country(
LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))));
profile.GetRawMultiInfo(autofill::EMAIL_ADDRESS, &values);
profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
for (size_t i = 0; i < values.size(); ++i) {
specifics->add_email_address(LimitData(UTF16ToUTF8(values[i])));
}
specifics->set_company_name(
LimitData(UTF16ToUTF8(profile.GetRawInfo(autofill::COMPANY_NAME))));
LimitData(UTF16ToUTF8(profile.GetRawInfo(COMPANY_NAME))));
profile.GetRawMultiInfo(autofill::PHONE_HOME_WHOLE_NUMBER, &values);
profile.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
for (size_t i = 0; i < values.size(); ++i) {
specifics->add_phone_home_whole_number(LimitData(UTF16ToUTF8(values[i])));
}
......@@ -484,8 +485,8 @@ AutofillProfileSyncableService::CreateOrUpdateProfile(
bundle->profiles_to_delete.push_back(local_profile->guid());
DVLOG(2) << "[AUTOFILL SYNC]"
<< "Found in sync db but with a different guid: "
<< UTF16ToUTF8(local_profile->GetRawInfo(autofill::NAME_FIRST))
<< UTF16ToUTF8(local_profile->GetRawInfo(autofill::NAME_LAST))
<< UTF16ToUTF8(local_profile->GetRawInfo(NAME_FIRST))
<< UTF16ToUTF8(local_profile->GetRawInfo(NAME_LAST))
<< "New guid " << new_profile->guid()
<< ". Profile to be deleted " << local_profile->guid();
profile_map->erase(it);
......@@ -624,3 +625,5 @@ void AutofillProfileSyncableService::InjectStartSyncFlare(
AutofillProfileSyncableService::DataBundle::DataBundle() {}
AutofillProfileSyncableService::DataBundle::~DataBundle() {}
} // namespace autofill
......@@ -29,11 +29,11 @@ class ProfileSyncServiceAutofillTest;
class WebDataServiceBase;
namespace autofill {
class AutofillProfile;
class AutofillTable;
class AutofillWebDataService;
class FormGroup;
} // namespace autofill
extern const char kAutofillProfileTag[];
......@@ -44,7 +44,7 @@ extern const char kAutofillProfileTag[];
class AutofillProfileSyncableService
: public base::SupportsUserData::Data,
public syncer::SyncableService,
public autofill::AutofillWebDataServiceObserverOnDBThread,
public AutofillWebDataServiceObserverOnDBThread,
public base::NonThreadSafe {
public:
virtual ~AutofillProfileSyncableService();
......@@ -52,13 +52,13 @@ class AutofillProfileSyncableService
// Creates a new AutofillProfileSyncableService and hangs it off of
// |web_data_service|, which takes ownership.
static void CreateForWebDataServiceAndBackend(
autofill::AutofillWebDataService* web_data_service,
autofill::AutofillWebDataBackend* webdata_backend,
AutofillWebDataService* web_data_service,
AutofillWebDataBackend* webdata_backend,
const std::string& app_locale);
// Retrieves the AutofillProfileSyncableService stored on |web_data_service|.
static AutofillProfileSyncableService* FromWebDataService(
autofill::AutofillWebDataService* web_data_service);
AutofillWebDataService* web_data_service);
static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; }
......@@ -77,7 +77,7 @@ class AutofillProfileSyncableService
// AutofillWebDataServiceObserverOnDBThread implementation.
virtual void AutofillProfileChanged(
const autofill::AutofillProfileChange& change) OVERRIDE;
const AutofillProfileChange& change) OVERRIDE;
// Provides a StartSyncFlare to the SyncableService. See
// sync_start_util for more.
......@@ -85,9 +85,8 @@ class AutofillProfileSyncableService
const syncer::SyncableService::StartSyncFlare& flare);
protected:
AutofillProfileSyncableService(
autofill::AutofillWebDataBackend* webdata_backend,
const std::string& app_locale);
AutofillProfileSyncableService(AutofillWebDataBackend* webdata_backend,
const std::string& app_locale);
// A convenience wrapper of a bunch of state we pass around while
// associating models, and send to the WebDatabase for persistence.
......@@ -98,8 +97,7 @@ class AutofillProfileSyncableService
// Helper to query WebDatabase for the current autofill state.
// Made virtual for ease of mocking in unit tests.
// Caller owns returned |profiles|.
virtual bool LoadAutofillData(
std::vector<autofill::AutofillProfile*>* profiles);
virtual bool LoadAutofillData(std::vector<AutofillProfile*>* profiles);
// Helper to persist any changes that occured during model association to
// the WebDatabase.
......@@ -114,10 +112,10 @@ class AutofillProfileSyncableService
// Creates syncer::SyncData based on supplied |profile|.
// Exposed for unit tests.
static syncer::SyncData CreateData(const autofill::AutofillProfile& profile);
static syncer::SyncData CreateData(const AutofillProfile& profile);
private:
friend class ProfileSyncServiceAutofillTest;
friend class ::ProfileSyncServiceAutofillTest;
FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest,
UpdateField);
FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest,
......@@ -126,24 +124,23 @@ class AutofillProfileSyncableService
MergeProfile);
// The map of the guid to profiles owned by the |profiles_| vector.
typedef std::map<std::string, autofill::AutofillProfile*> GUIDToProfileMap;
typedef std::map<std::string, AutofillProfile*> GUIDToProfileMap;
// Helper function that overwrites |profile| with data from proto-buffer
// |specifics|.
static bool OverwriteProfileWithServerData(
const sync_pb::AutofillProfileSpecifics& specifics,
autofill::AutofillProfile* profile,
AutofillProfile* profile,
const std::string& app_locale);
// Writes |profile| data into supplied |profile_specifics|.
static void WriteAutofillProfile(const autofill::AutofillProfile& profile,
static void WriteAutofillProfile(const AutofillProfile& profile,
sync_pb::EntitySpecifics* profile_specifics);
// Creates |profile_map| from the supplied |profiles| vector. Necessary for
// fast processing of the changes.
void CreateGUIDToProfileMap(
const std::vector<autofill::AutofillProfile*>& profiles,
GUIDToProfileMap* profile_map);
void CreateGUIDToProfileMap(const std::vector<AutofillProfile*>& profiles,
GUIDToProfileMap* profile_map);
// Creates or updates a profile based on |data|. Looks at the guid of the data
// and if a profile with such guid is present in |profile_map| updates it. If
......@@ -156,20 +153,20 @@ class AutofillProfileSyncableService
DataBundle* bundle);
// Syncs |change| to the cloud.
void ActOnChange(const autofill::AutofillProfileChange& change);
void ActOnChange(const AutofillProfileChange& change);
autofill::AutofillTable* GetAutofillTable() const;
AutofillTable* GetAutofillTable() const;
// Helper to compare the local value and cloud value of a field, copy into
// the local value if they differ, and return whether the change happened.
static bool UpdateField(autofill::ServerFieldType field_type,
static bool UpdateField(ServerFieldType field_type,
const std::string& new_value,
autofill::AutofillProfile* autofill_profile);
AutofillProfile* autofill_profile);
// The same as |UpdateField|, but for multi-valued fields.
static bool UpdateMultivaluedField(
autofill::ServerFieldType field_type,
ServerFieldType field_type,
const ::google::protobuf::RepeatedPtrField<std::string>& new_value,
autofill::AutofillProfile* autofill_profile);
AutofillProfile* autofill_profile);
// Calls merge_into->OverwriteWithOrAddTo() and then checks if the
// |merge_into| has extra data. Returns |true| if |merge_into| posseses some
......@@ -177,18 +174,18 @@ class AutofillProfileSyncableService
// of the two profiles differ, false otherwise.
// TODO(isherman): Seems like this should return |true| if |merge_into| was
// modified at all: http://crbug.com/248440
static bool MergeProfile(const autofill::AutofillProfile& merge_from,
autofill::AutofillProfile* merge_into,
static bool MergeProfile(const AutofillProfile& merge_from,
AutofillProfile* merge_into,
const std::string& app_locale);
autofill::AutofillWebDataBackend* webdata_backend_; // WEAK
AutofillWebDataBackend* webdata_backend_; // WEAK
std::string app_locale_;
ScopedObserver<autofill::AutofillWebDataBackend,
ScopedObserver<AutofillWebDataBackend,
AutofillProfileSyncableService> scoped_observer_;
// Cached Autofill profiles. *Warning* deleted profiles are still in the
// vector - use the |profiles_map_| to iterate through actual profiles.
ScopedVector<autofill::AutofillProfile> profiles_;
ScopedVector<AutofillProfile> profiles_;
GUIDToProfileMap profiles_map_;
scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
......@@ -206,14 +203,16 @@ struct AutofillProfileSyncableService::DataBundle {
~DataBundle();
std::vector<std::string> profiles_to_delete;
std::vector<autofill::AutofillProfile*> profiles_to_update;
std::vector<autofill::AutofillProfile*> profiles_to_add;
std::vector<AutofillProfile*> profiles_to_update;
std::vector<AutofillProfile*> profiles_to_add;
// When we go through sync we find profiles that are similar but unmatched.
// Merge such profiles.
GUIDToProfileMap candidates_to_merge;
// Profiles that have multi-valued fields that are not in sync.
std::vector<autofill::AutofillProfile*> profiles_to_sync_back;
std::vector<AutofillProfile*> profiles_to_sync_back;
};
} // namespace autofill
#endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_
......@@ -29,6 +29,7 @@
#include "grit/generated_resources.h"
using autofill::AutofillWebDataService;
using autofill::AutofillProfileSyncableService;
using content::BrowserThread;
namespace {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment