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

Side by Side Diff: chrome/browser/autofill/android/auxiliary_profiles_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: Fixed assortment of nits Created 7 years, 9 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 "chrome/browser/autofill/android/auxiliary_profiles_android.h"
7
8 #include <vector>
9
10 #include "base/guid.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/string16.h"
15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/autofill/android/auxiliary_profile_loader_impl_android. h"
17 #include "chrome/browser/autofill/autofill_profile.h"
18 #include "chrome/browser/autofill/phone_number.h"
19
20 // Generates the autofill profile by accessing the Android
21 // ContactsContract.Profile API through PersonalAutofillPopulator via JNI.
22 // The generated profile corresponds to the user's "ME" contact in the
23 // "People" app. The caller passes a vector of profiles into the constructor
24 // then initiates a fetch using |GetContactsProfile()| method. This clears
25 // any existing addresses.
26
27 // 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.
28 // or else things break.
29 const char kAndroidMeContactA[] = "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9";
30
31 namespace autofill {
32
33 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid(
34 const AuxiliaryProfileLoader& profileLoader)
35 : 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.
36 }
37
38 AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() {
39 }
40
41 // Mutates profiles vector injecting an autofill profile
42 // 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.
43 void AuxiliaryProfilesAndroid::LoadContactsProfile(
44 std::vector<AutofillProfile*>* profiles) {
Ilya Sherman 2013/03/05 00:42:38 nit: Fix indentation.
apiccion 2013/03/09 00:53:41 Done.
45 DCHECK(profiles);
Ilya Sherman 2013/03/05 00:42:38 nit: No need for this.
apiccion 2013/03/09 00:53:41 Done.
46 profiles->clear();
47
48 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA));
49 LoadName(profile.get());
50 LoadEmailAddress(profile.get());
51 LoadPhoneNumbers(profile.get());
52
53 // Android user's profile contact does not parse its address
54 // into constituent parts. Instead we just get a long string blob.
55 // Disable address population until we implement a way to parse the
56 // data.
57 // 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.
58 // LoadAddress(profile.get());
59
60 profiles->push_back(profile.release());
61 }
62
63 // Takes misc. address information strings from Android API and collapses
64 // into single string for "address line 2"
65
66 string16 AuxiliaryProfilesAndroid::CollapseAddress(const string16& pobox,
67 const string16& neighborhood) {
68 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.
69 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.
70 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.
71
72 if (accVector.empty()) {
73 return string16();
74 } 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.
75 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.
76 string16 delimeter = ASCIIToUTF16(", ");
77 for (std::vector<string16>::size_type i = 0; i < accVector.size() - 1; i++){
78 acc += accVector[i] + delimeter;
79 }
80 acc += accVector[accVector.size() - 1];
81 return acc;
82 }
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.
83 }
84
85 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) {
86 string16 street = profile_loader_.GetStreet();
87 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.
88 string16 neighborhood = profile_loader_.GetNeighborhood();
89 string16 city = profile_loader_.GetCity();
90 string16 postalCode = profile_loader_.GetPostalCode();
Ilya Sherman 2013/03/05 00:42:38 nit: hacker_case
91 string16 region = profile_loader_.GetRegion();
92 string16 country = profile_loader_.GetCountry();
93
94 string16 street2 = CollapseAddress(pobox, neighborhood);
95
96 profile->SetRawInfo(ADDRESS_HOME_LINE1, street);
97 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2);
98 profile->SetRawInfo(ADDRESS_HOME_CITY, city);
99 profile->SetRawInfo(ADDRESS_HOME_STATE, region);
100 profile->SetRawInfo(ADDRESS_HOME_ZIP, postalCode);
101 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country);
102 }
103
104 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) {
105 string16 firstName = profile_loader_.GetFirstName();
106 string16 middleName = profile_loader_.GetMiddleName();
107 string16 lastName = profile_loader_.GetLastName();
Ilya Sherman 2013/03/05 00:42:38 nit: hacker_case
apiccion 2013/03/09 00:53:41 Done.
108
109 profile->SetRawInfo(NAME_FIRST, firstName);
110 profile->SetRawInfo(NAME_LAST, lastName);
111 profile->SetRawInfo(NAME_MIDDLE, middleName);
112 }
113
114 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) {
115 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.
116 profile_loader_.GetEmailAddresses(&emailsVector);
117 profile->SetRawMultiInfo(EMAIL_ADDRESS, emailsVector);
118 }
119
120 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) {
121 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.
122 profile_loader_.GetPhoneNumbers(&phoneNumbersVector);
123 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumbersVector);
124 }
125
126 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698