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

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

Issue 13697002: Make autofill's Address store country using the country code so that app locale isn't needed for th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Populates default autofill profile from user's own Android contact. 5 // Populates default autofill profile from user's own Android contact.
6 #include "components/autofill/browser/android/auxiliary_profiles_android.h" 6 #include "components/autofill/browser/android/auxiliary_profiles_android.h"
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/guid.h" 10 #include "base/guid.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "components/autofill/browser/android/auxiliary_profile_loader_android.h " 17 #include "components/autofill/browser/android/auxiliary_profile_loader_android.h "
18 #include "components/autofill/browser/autofill_country.h"
18 #include "components/autofill/browser/autofill_profile.h" 19 #include "components/autofill/browser/autofill_profile.h"
19 #include "components/autofill/browser/phone_number.h" 20 #include "components/autofill/browser/phone_number.h"
20 21
21 // Generates the autofill profile by accessing the Android 22 // Generates the autofill profile by accessing the Android
22 // ContactsContract.Profile API through PersonalAutofillPopulator via JNI. 23 // ContactsContract.Profile API through PersonalAutofillPopulator via JNI.
23 // The generated profile corresponds to the user's "ME" contact in the 24 // 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 // "People" app. The caller passes a vector of profiles into the constructor
25 // then initiates a fetch using |GetContactsProfile()| method. This clears 26 // then initiates a fetch using |GetContactsProfile()| method. This clears
26 // any existing addresses. 27 // any existing addresses.
27 28
(...skipping 14 matching lines...) Expand all
42 accumulator.push_back(neighborhood); 43 accumulator.push_back(neighborhood);
43 44
44 return JoinString(accumulator, ASCIIToUTF16(", ")); 45 return JoinString(accumulator, ASCIIToUTF16(", "));
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 namespace autofill { 50 namespace autofill {
50 51
51 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid( 52 AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid(
52 const AuxiliaryProfileLoaderAndroid& profileLoader) 53 const AuxiliaryProfileLoaderAndroid& profileLoader,
53 : profile_loader_(profileLoader) {} 54 const std::string& app_locale)
55 : profile_loader_(profileLoader),
56 app_locale_(app_locale) {}
54 57
55 AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() { 58 AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() {
56 } 59 }
57 60
58 scoped_ptr<AutofillProfile> AuxiliaryProfilesAndroid::LoadContactsProfile() { 61 scoped_ptr<AutofillProfile> AuxiliaryProfilesAndroid::LoadContactsProfile() {
59 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA)); 62 scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA));
60 LoadName(profile.get()); 63 LoadName(profile.get());
61 LoadEmailAddress(profile.get()); 64 LoadEmailAddress(profile.get());
62 LoadPhoneNumbers(profile.get()); 65 LoadPhoneNumbers(profile.get());
63 66
64 // Android user's profile contact does not parse its address 67 // Android user's profile contact does not parse its address
65 // into constituent parts. Instead we just get a long string blob. 68 // into constituent parts. Instead we just get a long string blob.
66 // Disable address population until we implement a way to parse the 69 // Disable address population until we implement a way to parse the
67 // data. 70 // data.
68 // http://crbug.com/178838 71 // http://crbug.com/178838
69 // LoadAddress(profile.get()); 72 // LoadAddress(profile.get());
70 73
71 return profile.Pass(); 74 return profile.Pass();
72 } 75 }
73 76
74 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) { 77 void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) {
75 string16 street = profile_loader_.GetStreet(); 78 string16 street = profile_loader_.GetStreet();
76 string16 post_office_box = profile_loader_.GetPostOfficeBox(); 79 string16 post_office_box = profile_loader_.GetPostOfficeBox();
77 string16 neighborhood = profile_loader_.GetNeighborhood(); 80 string16 neighborhood = profile_loader_.GetNeighborhood();
78 string16 city = profile_loader_.GetCity(); 81 string16 city = profile_loader_.GetCity();
79 string16 postal_code = profile_loader_.GetPostalCode(); 82 string16 postal_code = profile_loader_.GetPostalCode();
80 string16 region = profile_loader_.GetRegion(); 83 string16 region = profile_loader_.GetRegion();
81 string16 country = profile_loader_.GetCountry(); 84 string16 country_name_or_code = profile_loader_.GetCountry();
85 std::string country_code = AutofillCountry::GetCountryCode(
86 country_name_or_code, app_locale_);
82 87
83 string16 street2 = CollapseAddress(post_office_box, neighborhood); 88 string16 street2 = CollapseAddress(post_office_box, neighborhood);
84 89
85 profile->SetRawInfo(ADDRESS_HOME_LINE1, street); 90 profile->SetRawInfo(ADDRESS_HOME_LINE1, street);
86 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2); 91 profile->SetRawInfo(ADDRESS_HOME_LINE2, street2);
87 profile->SetRawInfo(ADDRESS_HOME_CITY, city); 92 profile->SetRawInfo(ADDRESS_HOME_CITY, city);
88 profile->SetRawInfo(ADDRESS_HOME_STATE, region); 93 profile->SetRawInfo(ADDRESS_HOME_STATE, region);
89 profile->SetRawInfo(ADDRESS_HOME_ZIP, postal_code); 94 profile->SetRawInfo(ADDRESS_HOME_ZIP, postal_code);
90 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country); 95 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16(country_code));
Ilya Sherman 2013/04/05 05:18:01 Please call SetInfo with the app_locale rather tha
jam 2013/04/05 06:45:54 Done.
91 } 96 }
92 97
93 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) { 98 void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) {
94 string16 first_name = profile_loader_.GetFirstName(); 99 string16 first_name = profile_loader_.GetFirstName();
95 string16 middle_name = profile_loader_.GetMiddleName(); 100 string16 middle_name = profile_loader_.GetMiddleName();
96 string16 last_name = profile_loader_.GetLastName(); 101 string16 last_name = profile_loader_.GetLastName();
97 102
98 profile->SetRawInfo(NAME_FIRST, first_name); 103 profile->SetRawInfo(NAME_FIRST, first_name);
99 profile->SetRawInfo(NAME_MIDDLE, middle_name); 104 profile->SetRawInfo(NAME_MIDDLE, middle_name);
100 profile->SetRawInfo(NAME_LAST, last_name); 105 profile->SetRawInfo(NAME_LAST, last_name);
101 } 106 }
102 107
103 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) { 108 void AuxiliaryProfilesAndroid::LoadEmailAddress(AutofillProfile* profile) {
104 std::vector<string16> emails; 109 std::vector<string16> emails;
105 profile_loader_.GetEmailAddresses(&emails); 110 profile_loader_.GetEmailAddresses(&emails);
106 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); 111 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails);
107 } 112 }
108 113
109 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) { 114 void AuxiliaryProfilesAndroid::LoadPhoneNumbers(AutofillProfile* profile) {
110 std::vector<string16> phone_numbers; 115 std::vector<string16> phone_numbers;
111 profile_loader_.GetPhoneNumbers(&phone_numbers); 116 profile_loader_.GetPhoneNumbers(&phone_numbers);
112 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_numbers); 117 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phone_numbers);
113 } 118 }
114 119
115 } // namespace autofill 120 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698