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/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 "chrome/browser/autofill/android/auxiliary_profile_loader_android.h" | |
18 #include "chrome/browser/autofill/autofill_profile.h" | |
19 #include "chrome/browser/autofill/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 } | |
Ilya Sherman
2013/03/09 01:42:58
nit: No need for curly braces. Ditto below.
apiccion
2013/03/09 03:43:17
Done.
| |
42 if (!neighborhood.empty()) { | |
43 accumulator.push_back(neighborhood); | |
44 } | |
45 | |
46 return JoinString(accumulator, ASCIIToUTF16(", ")); | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 namespace autofill { | |
52 | |
53 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid( | |
54 const AuxiliaryProfileLoaderAndroid& profileLoader) | |
55 : profile_loader_(profileLoader) {} | |
Ilya Sherman
2013/03/09 01:42:58
nit: Indent this line two fewer spaces.
apiccion
2013/03/09 03:43:17
Done.
| |
56 | |
57 AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() { | |
58 } | |
59 | |
60 scoped_ptr<AutofillProfile> AuxiliaryProfilesAndroid::LoadContactsProfile() { | |
61 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA)); | |
62 LoadName(profile.get()); | |
63 LoadEmailAddress(profile.get()); | |
64 LoadPhoneNumbers(profile.get()); | |
65 | |
66 // Android user's profile contact does not parse its address | |
67 // into constituent parts. Instead we just get a long string blob. | |
68 // Disable address population until we implement a way to parse the | |
69 // data. | |
70 // http://crbug.com/178838 | |
71 // LoadAddress(profile.get()); | |
72 | |
73 return profile.Pass(); | |
74 } | |
75 | |
76 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) { | |
77 string16 street = profile_loader_.GetStreet(); | |
78 string16 post_office_box = profile_loader_.GetPostOfficeBox(); | |
79 string16 neighborhood = profile_loader_.GetNeighborhood(); | |
80 string16 city = profile_loader_.GetCity(); | |
81 string16 postal_code = profile_loader_.GetPostalCode(); | |
82 string16 region = profile_loader_.GetRegion(); | |
83 string16 country = profile_loader_.GetCountry(); | |
84 | |
85 string16 street2 = | |
86 CollapseAddress(post_office_box, neighborhood); | |
87 | |
88 profile->SetRawInfo(ADDRESS_HOME_LINE1, street); | |
89 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2); | |
90 profile->SetRawInfo(ADDRESS_HOME_CITY, city); | |
91 profile->SetRawInfo(ADDRESS_HOME_STATE, region); | |
92 profile->SetRawInfo(ADDRESS_HOME_ZIP, postal_code); | |
93 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country); | |
94 } | |
95 | |
96 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) { | |
97 string16 firstName = profile_loader_.GetFirstName(); | |
98 string16 middleName = profile_loader_.GetMiddleName(); | |
99 string16 lastName = profile_loader_.GetLastName(); | |
100 | |
101 profile->SetRawInfo(NAME_FIRST, firstName); | |
102 profile->SetRawInfo(NAME_LAST, lastName); | |
103 profile->SetRawInfo(NAME_MIDDLE, middleName); | |
104 } | |
105 | |
106 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) { | |
107 std::vector<string16> emails; | |
108 profile_loader_.GetEmailAddresses(&emails); | |
109 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); | |
110 } | |
111 | |
112 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) { | |
113 std::vector<string16> phone_numbers; | |
114 profile_loader_.GetPhoneNumbers(&phone_numbers); | |
115 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_numbers); | |
116 } | |
117 | |
118 } // namespace | |
OLD | NEW |