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

Side by Side Diff: chrome/browser/autofill/auxiliary_profile_impl_android.cc

Issue 12282004: Added personal_data_manager android implementation for auto-populating auto-fill on android builds … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 10 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 <vector>
7 #include "base/guid.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/string16.h"
12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autofill/auxiliary_profile_impl_android.h"
David Trainor- moved to gerrit 2013/02/27 07:49:28 I think this should be at the top?
apiccion 2013/02/28 01:31:04 Done.
apiccion 2013/02/28 01:31:04 Done.
14 #include "chrome/browser/autofill/auxiliary_profile_loader_android.h"
15 #include "chrome/browser/autofill/phone_number.h"
16
17 /*
18 * Generates the autofill profile by accessing the Android
19 * ContactsContract.Profile API through PersonalAutofillPopulator via JNI.
20 * The generated profile corresponds to the user's "ME" contact in the
21 * "People" app. The caller passes a vector of profiles into the constructor
22 * then initiates a fetch using |GetContactsProfile()| method. This clears
23 * any existing addresses.
24 */
25
26 static const char kAndroidMeContactA[] = "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9";
27
28 void AuxiliaryProfilesImpl::GetContactsProfile() {
29 profiles_.clear();
30
31 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA));
32 DCHECK(base::IsValidGUID(profile->guid()));
33 LoadName(profile.get());
34 LoadEmailAddress(profile.get());
35 LoadPhoneNumbers(profile.get());
36
37 /*
38 * Android user's profile contact does not prase its address
David Trainor- moved to gerrit 2013/02/27 07:49:28 prase -> parse
apiccion 2013/02/28 01:31:04 Done.
39 * into constituent parts. Instead we just get a long string blob.
40 * Disable address population until we implement a way to parse the
41 * data.
42 * LoadAddress(profile.get());
David Trainor- moved to gerrit 2013/02/27 07:49:28 File a bug for this at crbug.com and add the bug n
apiccion 2013/02/28 01:31:04 Done.
43 */
44
45 profiles_.push_back(profile.release());
46 }
47 /*
David Trainor- moved to gerrit 2013/02/27 07:49:28 blank line between } and /*
apiccion 2013/02/28 01:31:04 Done.
48 * Takes misc. address information strings from Android API and collapses
49 * into single string for "address line 2"
50 */
51
52 string16 AuxiliaryProfilesImpl::CollapseAddress(string16 pobox,
53 string16 neighborhood) {
54 std::vector<string16> accVector;
55 if (!pobox.empty()) {
56 accVector.push_back(pobox);
David Trainor- moved to gerrit 2013/02/27 07:49:28 For one line if statements don't add { }
apiccion 2013/02/28 01:31:04 Done.
57 }
58 if (!neighborhood.empty()) {
David Trainor- moved to gerrit 2013/02/27 07:49:28 Same
apiccion 2013/02/28 01:31:04 Done.
59 accVector.push_back(neighborhood);
60 }
61
62 if (accVector.empty()) {
63 return string16();
64 } else {
65 string16 acc;
66 string16 delimeter = ASCIIToUTF16(", ");
67 for (std::vector<string16>::size_type i = 0; i < accVector.size() - 1; i++){
68 acc += accVector[i] + delimeter;
69 }
70 acc += accVector[accVector.size() - 1];
71 return acc;
72 }
73 }
74
75 void AuxiliaryProfilesImpl::LoadAddress(AutofillProfile* profile) {
76 string16 street = profileLoader_.GetStreet();
77 string16 pobox = profileLoader_.GetPobox();
78 string16 neighborhood = profileLoader_.GetNeighborhood();
79 string16 city = profileLoader_.GetCity();
80 string16 postalCode = profileLoader_.GetPostalCode();
81 string16 region = profileLoader_.GetRegion();
82 string16 country = profileLoader_.GetCountry();
83
84 string16 street2 = CollapseAddress(pobox, neighborhood);
85
86 profile->SetRawInfo(ADDRESS_HOME_LINE1, street);
87 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2);
88 profile->SetRawInfo(ADDRESS_HOME_CITY, city);
89 profile->SetRawInfo(ADDRESS_HOME_STATE, region);
90 profile->SetRawInfo(ADDRESS_HOME_ZIP, postalCode);
91 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country);
92 }
93
94 void AuxiliaryProfilesImpl::LoadName(AutofillProfile* profile) {
95 string16 firstName = profileLoader_.GetFirstName();
96 string16 middleName = profileLoader_.GetMiddleName();
97 string16 lastName = profileLoader_.GetLastName();
98
99 profile->SetRawInfo(NAME_FIRST, firstName);
100 profile->SetRawInfo(NAME_LAST, lastName);
101 profile->SetRawInfo(NAME_MIDDLE, middleName);
102
103 /* Trips NOTREACHED assertion in |NameInfo| due
David Trainor- moved to gerrit 2013/02/27 07:49:28 Just remove this if it's working as expected and w
apiccion 2013/02/28 01:31:04 Done.
104 * to absense of NAME_SUFFIX case handler
105 * string16 suffix = profileLoader_.GetSuffix();
106 * profile->SetRawInfo(NAME_SUFFIX, suffix);
107 */
108 }
109
110 void AuxiliaryProfilesImpl::LoadEmailAddress(AutofillProfile* profile) {
111 std::vector<string16> emailAddressVector = profileLoader_.GetEmailAddresses();
112 profile->SetRawMultiInfo(EMAIL_ADDRESS, emailAddressVector);
113 }
114
115 void AuxiliaryProfilesImpl::LoadPhoneNumbers(AutofillProfile* profile) {
116 std::vector<string16> phoneNumbersVector = profileLoader_.GetPhoneNumbers();
117 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumbersVector);
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698