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

Side by Side Diff: components/autofill/browser/android/auxiliary_profiles_android.cc

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 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/strings/string16.h"
15 #include "base/strings/string_util.h"
16 #include "base/strings/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 // The origin string for all profiles loaded from the Android contacts list.
33 const char kAndroidContactsOrigin[] = "Android Contacts";
34
35 namespace {
36
37 // Takes misc. address information strings from Android API and collapses
38 // into single string for "address line 2"
39 base::string16 CollapseAddress(const base::string16& post_office_box,
40 const base::string16& neighborhood) {
41 std::vector<base::string16> accumulator;
42 if (!post_office_box.empty())
43 accumulator.push_back(post_office_box);
44 if (!neighborhood.empty())
45 accumulator.push_back(neighborhood);
46
47 return JoinString(accumulator, ASCIIToUTF16(", "));
48 }
49
50 } // namespace
51
52 namespace autofill {
53
54 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid(
55 const AuxiliaryProfileLoaderAndroid& profileLoader,
56 const std::string& app_locale)
57 : profile_loader_(profileLoader),
58 app_locale_(app_locale) {}
59
60 AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() {
61 }
62
63 scoped_ptr<AutofillProfile> AuxiliaryProfilesAndroid::LoadContactsProfile() {
64 scoped_ptr<AutofillProfile> profile(
65 new AutofillProfile(kAndroidMeContactA, kAndroidContactsOrigin));
66 LoadName(profile.get());
67 LoadEmailAddress(profile.get());
68 LoadPhoneNumbers(profile.get());
69
70 // Android user's profile contact does not parse its address
71 // into constituent parts. Instead we just get a long string blob.
72 // Disable address population until we implement a way to parse the
73 // data.
74 // http://crbug.com/178838
75 // LoadAddress(profile.get());
76
77 return profile.Pass();
78 }
79
80 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) {
81 base::string16 street = profile_loader_.GetStreet();
82 base::string16 post_office_box = profile_loader_.GetPostOfficeBox();
83 base::string16 neighborhood = profile_loader_.GetNeighborhood();
84 base::string16 city = profile_loader_.GetCity();
85 base::string16 postal_code = profile_loader_.GetPostalCode();
86 base::string16 region = profile_loader_.GetRegion();
87 base::string16 country = profile_loader_.GetCountry();
88
89 base::string16 street2 = CollapseAddress(post_office_box, neighborhood);
90
91 profile->SetRawInfo(ADDRESS_HOME_LINE1, street);
92 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2);
93 profile->SetRawInfo(ADDRESS_HOME_CITY, city);
94 profile->SetRawInfo(ADDRESS_HOME_STATE, region);
95 profile->SetRawInfo(ADDRESS_HOME_ZIP, postal_code);
96 profile->SetInfo(ADDRESS_HOME_COUNTRY, country, app_locale_);
97 }
98
99 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) {
100 base::string16 first_name = profile_loader_.GetFirstName();
101 base::string16 middle_name = profile_loader_.GetMiddleName();
102 base::string16 last_name = profile_loader_.GetLastName();
103
104 profile->SetRawInfo(NAME_FIRST, first_name);
105 profile->SetRawInfo(NAME_MIDDLE, middle_name);
106 profile->SetRawInfo(NAME_LAST, last_name);
107 }
108
109 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) {
110 std::vector<base::string16> emails;
111 profile_loader_.GetEmailAddresses(&emails);
112 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails);
113 }
114
115 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) {
116 std::vector<base::string16> phone_numbers;
117 profile_loader_.GetPhoneNumbers(&phone_numbers);
118 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_numbers);
119 }
120
121 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698