Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Populates default autofill profile from user's own Android contact. | |
| 6 #include "chrome/browser/autofill/auxiliary_profiles_android.h" | |
| 7 | |
| 8 #include <vector> | |
|
Ilya Sherman
2013/03/01 01:55:04
nit: Leave a blank line after this one.
apiccion
2013/03/02 03:37:01
Done.
apiccion
2013/03/02 03:37:01
Done.
| |
| 9 #include "base/guid.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/scoped_vector.h" | |
| 13 #include "base/string16.h" | |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "chrome/browser/autofill/auxiliary_profile_loader_impl_android.h" | |
| 16 #include "chrome/browser/autofill/phone_number.h" | |
| 17 | |
| 18 /* | |
| 19 * Generates the autofill profile by accessing the Android | |
| 20 * ContactsContract.Profile API through PersonalAutofillPopulator via JNI. | |
| 21 * The generated profile corresponds to the user's "ME" contact in the | |
| 22 * "People" app. The caller passes a vector of profiles into the constructor | |
| 23 * then initiates a fetch using |GetContactsProfile()| method. This clears | |
| 24 * any existing addresses. | |
| 25 */ | |
|
Ilya Sherman
2013/03/01 01:55:04
nit: Use "// " for comments, not "/* ... */"
apiccion
2013/03/02 03:37:01
Done.
| |
| 26 | |
| 27 static const char kAndroidMeContactA[] = "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9"; | |
|
Ilya Sherman
2013/03/01 01:55:04
nit: Docs.
Ilya Sherman
2013/03/01 01:55:04
nit: Omit "static"
apiccion
2013/03/02 03:37:01
Done.
apiccion
2013/03/02 03:37:01
Done.
| |
| 28 | |
| 29 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid( | |
| 30 ScopedVector<AutofillProfile>* profiles, | |
| 31 AuxiliaryProfileLoader* profileLoader) | |
|
Ilya Sherman
2013/03/01 01:55:04
nit: Indentation is off.
apiccion
2013/03/02 03:37:01
Done.
| |
| 32 : profiles_(*profiles), profile_loader_(*profileLoader) { | |
| 33 DCHECK(profiles); | |
| 34 DCHECK(profileLoader); | |
| 35 } | |
| 36 | |
| 37 void AuxiliaryProfilesAndroid::GetContactsProfile() { | |
| 38 profiles_.clear(); | |
| 39 | |
| 40 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA)); | |
| 41 DCHECK(base::IsValidGUID(profile->guid())); | |
| 42 LoadName(profile.get()); | |
| 43 LoadEmailAddress(profile.get()); | |
| 44 LoadPhoneNumbers(profile.get()); | |
| 45 | |
| 46 /* | |
| 47 * Android user's profile contact does not parse its address | |
| 48 * into constituent parts. Instead we just get a long string blob. | |
| 49 * Disable address population until we implement a way to parse the | |
| 50 * data. | |
| 51 * Chromium issue id # 178838 | |
| 52 * LoadAddress(profile.get()); | |
| 53 */ | |
| 54 | |
| 55 profiles_.push_back(profile.release()); | |
| 56 } | |
| 57 | |
| 58 /* | |
| 59 * Takes misc. address information strings from Android API and collapses | |
| 60 * into single string for "address line 2" | |
| 61 */ | |
| 62 | |
| 63 string16 AuxiliaryProfilesAndroid::CollapseAddress(string16 pobox, | |
| 64 string16 neighborhood) { | |
| 65 std::vector<string16> accVector; | |
| 66 if (!pobox.empty()) accVector.push_back(pobox); | |
| 67 if (!neighborhood.empty()) accVector.push_back(neighborhood); | |
| 68 | |
| 69 if (accVector.empty()) { | |
| 70 return string16(); | |
| 71 } else { | |
| 72 string16 acc; | |
| 73 string16 delimeter = ASCIIToUTF16(", "); | |
| 74 for (std::vector<string16>::size_type i = 0; i < accVector.size() - 1; i++){ | |
| 75 acc += accVector[i] + delimeter; | |
| 76 } | |
| 77 acc += accVector[accVector.size() - 1]; | |
| 78 return acc; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) { | |
| 83 string16 street = profile_loader_.GetStreet(); | |
| 84 string16 pobox = profile_loader_.GetPobox(); | |
| 85 string16 neighborhood = profile_loader_.GetNeighborhood(); | |
| 86 string16 city = profile_loader_.GetCity(); | |
| 87 string16 postalCode = profile_loader_.GetPostalCode(); | |
| 88 string16 region = profile_loader_.GetRegion(); | |
| 89 string16 country = profile_loader_.GetCountry(); | |
| 90 | |
| 91 string16 street2 = CollapseAddress(pobox, neighborhood); | |
| 92 | |
| 93 profile->SetRawInfo(ADDRESS_HOME_LINE1, street); | |
| 94 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2); | |
| 95 profile->SetRawInfo(ADDRESS_HOME_CITY, city); | |
| 96 profile->SetRawInfo(ADDRESS_HOME_STATE, region); | |
| 97 profile->SetRawInfo(ADDRESS_HOME_ZIP, postalCode); | |
| 98 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country); | |
| 99 } | |
| 100 | |
| 101 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) { | |
| 102 string16 firstName = profile_loader_.GetFirstName(); | |
| 103 string16 middleName = profile_loader_.GetMiddleName(); | |
| 104 string16 lastName = profile_loader_.GetLastName(); | |
| 105 | |
| 106 profile->SetRawInfo(NAME_FIRST, firstName); | |
| 107 profile->SetRawInfo(NAME_LAST, lastName); | |
| 108 profile->SetRawInfo(NAME_MIDDLE, middleName); | |
| 109 } | |
| 110 | |
| 111 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) { | |
| 112 std::vector<string16> emailsVector = profile_loader_.GetEmailAddresses(); | |
| 113 profile->SetRawMultiInfo(EMAIL_ADDRESS, emailsVector); | |
| 114 } | |
| 115 | |
| 116 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) { | |
| 117 std::vector<string16> phoneNumbersVector = profile_loader_.GetPhoneNumbers(); | |
| 118 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumbersVector); | |
| 119 } | |
| OLD | NEW |