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

Side by Side Diff: components/autofill/browser/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: Autofill populator components refactor 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 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 "components/autofill/browser/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/string_util.h"
16 #include "base/utf_string_conversions.h"
17 #include "components/autofill/browser/android/auxiliary_profile_loader_android.h "
18 #include "components/autofill/browser/autofill_profile.h"
19 #include "components/autofill/browser/phone_number.h"
20
21 // Generates the autofill profile by accessing the Android
22 // ContactsContract.Profile API through PersonalAutofillPopulator via JNI.
23 // The generated profile corresponds to the user's "ME" contact in the
24 // "People" app. The caller passes a vector of profiles into the constructor
25 // then initiates a fetch using |GetContactsProfile()| method. This clears
26 // any existing addresses.
27
28 // Randomly generated guid. The Autofillprofile class requires a consistent
29 // unique guid or else things break.
30 const char kAndroidMeContactA[] = "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9";
31
32 namespace {
33
34 // Takes misc. address information strings from Android API and collapses
35 // into single string for "address line 2"
36 string16 CollapseAddress(const string16& post_office_box,
37 const string16& neighborhood) {
38 std::vector<string16> accumulator;
39 if (!post_office_box.empty())
40 accumulator.push_back(post_office_box);
41 if (!neighborhood.empty())
42 accumulator.push_back(neighborhood);
43
44 return JoinString(accumulator, ASCIIToUTF16(", "));
45 }
46
47 } // namespace
48
49 namespace autofill {
50
51 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid(
52 const AuxiliaryProfileLoaderAndroid& profileLoader)
53 : profile_loader_(profileLoader) {}
54
55 AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() {
56 }
57
58 scoped_ptr<AutofillProfile> AuxiliaryProfilesAndroid::LoadContactsProfile() {
59 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA));
60 LoadName(profile.get());
61 LoadEmailAddress(profile.get());
62 LoadPhoneNumbers(profile.get());
63
64 // Android user's profile contact does not parse its address
65 // into constituent parts. Instead we just get a long string blob.
66 // Disable address population until we implement a way to parse the
67 // data.
68 // http://crbug.com/178838
69 // LoadAddress(profile.get());
70
71 return profile.Pass();
72 }
73
74 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) {
75 string16 street = profile_loader_.GetStreet();
76 string16 post_office_box = profile_loader_.GetPostOfficeBox();
77 string16 neighborhood = profile_loader_.GetNeighborhood();
78 string16 city = profile_loader_.GetCity();
79 string16 postal_code = profile_loader_.GetPostalCode();
80 string16 region = profile_loader_.GetRegion();
81 string16 country = profile_loader_.GetCountry();
82
83 string16 street2 = CollapseAddress(post_office_box, neighborhood);
84
85 profile->SetRawInfo(ADDRESS_HOME_LINE1, street);
86 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2);
87 profile->SetRawInfo(ADDRESS_HOME_CITY, city);
88 profile->SetRawInfo(ADDRESS_HOME_STATE, region);
89 profile->SetRawInfo(ADDRESS_HOME_ZIP, postal_code);
90 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country);
91 }
92
93 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) {
94 string16 first_name = profile_loader_.GetFirstName();
95 string16 middle_name = profile_loader_.GetMiddleName();
96 string16 last_name = profile_loader_.GetLastName();
97
98 profile->SetRawInfo(NAME_FIRST, first_name);
99 profile->SetRawInfo(NAME_MIDDLE, middle_name);
100 profile->SetRawInfo(NAME_LAST, last_name);
101 }
102
103 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) {
104 std::vector<string16> emails;
105 profile_loader_.GetEmailAddresses(&emails);
106 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails);
107 }
108
109 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) {
110 std::vector<string16> phone_numbers;
111 profile_loader_.GetPhoneNumbers(&phone_numbers);
112 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_numbers);
113 }
114
115 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698