Chromium Code Reviews| Index: chrome/browser/autofill/android/auxiliary_profiles_android.cc |
| diff --git a/chrome/browser/autofill/android/auxiliary_profiles_android.cc b/chrome/browser/autofill/android/auxiliary_profiles_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a7c01eeae18ff735718d4fddba8f21f5aeee00a9 |
| --- /dev/null |
| +++ b/chrome/browser/autofill/android/auxiliary_profiles_android.cc |
| @@ -0,0 +1,126 @@ |
| +// Copyright (c) 2013 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. |
| + |
| +// Populates default autofill profile from user's own Android contact. |
| +#include "chrome/browser/autofill/android/auxiliary_profiles_android.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/guid.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/scoped_vector.h" |
| +#include "base/string16.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/autofill/android/auxiliary_profile_loader_impl_android.h" |
| +#include "chrome/browser/autofill/autofill_profile.h" |
| +#include "chrome/browser/autofill/phone_number.h" |
| + |
| +// Generates the autofill profile by accessing the Android |
| +// ContactsContract.Profile API through PersonalAutofillPopulator via JNI. |
| +// The generated profile corresponds to the user's "ME" contact in the |
| +// "People" app. The caller passes a vector of profiles into the constructor |
| +// then initiates a fetch using |GetContactsProfile()| method. This clears |
| +// any existing addresses. |
| + |
| +// Randomly generated guid. Autofillprofile requires a consistent unique guid |
|
Ilya Sherman
2013/03/05 00:42:38
nit: "Autofillprofile" -> "The AutofillProfile cla
apiccion
2013/03/09 00:53:41
Done.
|
| +// or else things break. |
| +const char kAndroidMeContactA[] = "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9"; |
| + |
| +namespace autofill { |
| + |
| +AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid( |
| + const AuxiliaryProfileLoader& profileLoader) |
| + : profile_loader_(profileLoader) { |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Please fix the indentation here.
apiccion
2013/03/09 00:53:41
Done.
|
| +} |
| + |
| +AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() { |
| +} |
| + |
| +// Mutates profiles vector injecting an autofill profile |
| +// constructed from profileLoader. |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Comments like this belong in the header file,
apiccion
2013/03/09 00:53:41
Done.
|
| +void AuxiliaryProfilesAndroid::LoadContactsProfile( |
| + std::vector<AutofillProfile*>* profiles) { |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Fix indentation.
apiccion
2013/03/09 00:53:41
Done.
|
| + DCHECK(profiles); |
|
Ilya Sherman
2013/03/05 00:42:38
nit: No need for this.
apiccion
2013/03/09 00:53:41
Done.
|
| + profiles->clear(); |
| + |
| + scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA)); |
| + LoadName(profile.get()); |
| + LoadEmailAddress(profile.get()); |
| + LoadPhoneNumbers(profile.get()); |
| + |
| + // Android user's profile contact does not parse its address |
| + // into constituent parts. Instead we just get a long string blob. |
| + // Disable address population until we implement a way to parse the |
| + // data. |
| + // Chromium issue id # 178838 |
|
Ilya Sherman
2013/03/05 00:42:38
nit: "http://crbug.com/178838"
apiccion
2013/03/09 00:53:41
Done.
|
| + // LoadAddress(profile.get()); |
| + |
| + profiles->push_back(profile.release()); |
| +} |
| + |
| +// Takes misc. address information strings from Android API and collapses |
| +// into single string for "address line 2" |
| + |
| +string16 AuxiliaryProfilesAndroid::CollapseAddress(const string16& pobox, |
| + const string16& neighborhood) { |
| + std::vector<string16> accVector; |
|
Ilya Sherman
2013/03/05 00:42:38
nit: hacker_case, spell out whatever "acc" is shor
apiccion
2013/03/09 00:53:41
Done.
|
| + if (!pobox.empty()) accVector.push_back(pobox); |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Move the body of the if-stmt onto a separate
apiccion
2013/03/09 00:53:41
Done.
|
| + if (!neighborhood.empty()) accVector.push_back(neighborhood); |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Move the body of the if-stmt onto a separate
apiccion
2013/03/09 00:53:41
Done.
|
| + |
| + if (accVector.empty()) { |
| + return string16(); |
| + } else { |
|
Ilya Sherman
2013/03/05 00:42:38
nit: No need for an else stmt after a return.
apiccion
2013/03/09 00:53:41
Done.
|
| + string16 acc; |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Spell out whatever "acc" is short for
apiccion
2013/03/09 00:53:41
Done.
|
| + string16 delimeter = ASCIIToUTF16(", "); |
| + for (std::vector<string16>::size_type i = 0; i < accVector.size() - 1; i++){ |
| + acc += accVector[i] + delimeter; |
| + } |
| + acc += accVector[accVector.size() - 1]; |
| + return acc; |
| + } |
|
Ilya Sherman
2013/03/05 00:42:38
Can all of this code be replaced by just calling b
apiccion
2013/03/09 00:53:41
Done.
|
| +} |
| + |
| +void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) { |
| + string16 street = profile_loader_.GetStreet(); |
| + string16 pobox = profile_loader_.GetPostOfficeBox(); |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Spell out "pobox"
apiccion
2013/03/09 00:53:41
Done.
|
| + string16 neighborhood = profile_loader_.GetNeighborhood(); |
| + string16 city = profile_loader_.GetCity(); |
| + string16 postalCode = profile_loader_.GetPostalCode(); |
|
Ilya Sherman
2013/03/05 00:42:38
nit: hacker_case
|
| + string16 region = profile_loader_.GetRegion(); |
| + string16 country = profile_loader_.GetCountry(); |
| + |
| + string16 street2 = CollapseAddress(pobox, neighborhood); |
| + |
| + profile->SetRawInfo(ADDRESS_HOME_LINE1, street); |
| + profile->SetRawInfo(ADDRESS_HOME_LINE2, street2); |
| + profile->SetRawInfo(ADDRESS_HOME_CITY, city); |
| + profile->SetRawInfo(ADDRESS_HOME_STATE, region); |
| + profile->SetRawInfo(ADDRESS_HOME_ZIP, postalCode); |
| + profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country); |
| +} |
| + |
| +void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) { |
| + string16 firstName = profile_loader_.GetFirstName(); |
| + string16 middleName = profile_loader_.GetMiddleName(); |
| + string16 lastName = profile_loader_.GetLastName(); |
|
Ilya Sherman
2013/03/05 00:42:38
nit: hacker_case
apiccion
2013/03/09 00:53:41
Done.
|
| + |
| + profile->SetRawInfo(NAME_FIRST, firstName); |
| + profile->SetRawInfo(NAME_LAST, lastName); |
| + profile->SetRawInfo(NAME_MIDDLE, middleName); |
| +} |
| + |
| +void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) { |
| + std::vector<string16> emailsVector; |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Just name this "emails"
apiccion
2013/03/09 00:53:41
Done.
|
| + profile_loader_.GetEmailAddresses(&emailsVector); |
| + profile->SetRawMultiInfo(EMAIL_ADDRESS, emailsVector); |
| +} |
| + |
| +void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) { |
| + std::vector<string16> phoneNumbersVector; |
|
Ilya Sherman
2013/03/05 00:42:38
nit: Name this "phone_numbers"
apiccion
2013/03/09 00:53:41
Done.
|
| + profile_loader_.GetPhoneNumbers(&phoneNumbersVector); |
| + profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumbersVector); |
| +} |
| + |
| +} // namespace |