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

Unified Diff: chrome/browser/autofill/auxiliary_profile_impl_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: Rebased Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/auxiliary_profile_impl_android.cc
diff --git a/chrome/browser/autofill/auxiliary_profile_impl_android.cc b/chrome/browser/autofill/auxiliary_profile_impl_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ba2ac601d38f788ee8eaf807434cad835bf9a36e
--- /dev/null
+++ b/chrome/browser/autofill/auxiliary_profile_impl_android.cc
@@ -0,0 +1,118 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Populates default autofill profile from user's own Android contact.
+#include <vector>
+#include "base/guid.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/auxiliary_profile_impl_android.h"
David Trainor- moved to gerrit 2013/02/27 07:49:28 I think this should be at the top?
apiccion 2013/02/28 01:31:04 Done.
apiccion 2013/02/28 01:31:04 Done.
+#include "chrome/browser/autofill/auxiliary_profile_loader_android.h"
+#include "chrome/browser/autofill/phone_number.h"
+
+/*
+ * Generates the autofill profile by accessing the Android
+ * ContactsContract.Profile API through PersonalAutofillPopulator via JNI.
+ * The generated profile corresponds to the user's "ME" contact in the
+ * "People" app. The caller passes a vector of profiles into the constructor
+ * then initiates a fetch using |GetContactsProfile()| method. This clears
+ * any existing addresses.
+ */
+
+static const char kAndroidMeContactA[] = "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9";
+
+void AuxiliaryProfilesImpl::GetContactsProfile() {
+ profiles_.clear();
+
+ scoped_ptr<AutofillProfile> profile(new AutofillProfile(kAndroidMeContactA));
+ DCHECK(base::IsValidGUID(profile->guid()));
+ LoadName(profile.get());
+ LoadEmailAddress(profile.get());
+ LoadPhoneNumbers(profile.get());
+
+ /*
+ * Android user's profile contact does not prase its address
David Trainor- moved to gerrit 2013/02/27 07:49:28 prase -> parse
apiccion 2013/02/28 01:31:04 Done.
+ * into constituent parts. Instead we just get a long string blob.
+ * Disable address population until we implement a way to parse the
+ * data.
+ * LoadAddress(profile.get());
David Trainor- moved to gerrit 2013/02/27 07:49:28 File a bug for this at crbug.com and add the bug n
apiccion 2013/02/28 01:31:04 Done.
+ */
+
+ profiles_.push_back(profile.release());
+}
+/*
David Trainor- moved to gerrit 2013/02/27 07:49:28 blank line between } and /*
apiccion 2013/02/28 01:31:04 Done.
+ * Takes misc. address information strings from Android API and collapses
+ * into single string for "address line 2"
+ */
+
+string16 AuxiliaryProfilesImpl::CollapseAddress(string16 pobox,
+ string16 neighborhood) {
+ std::vector<string16> accVector;
+ if (!pobox.empty()) {
+ accVector.push_back(pobox);
David Trainor- moved to gerrit 2013/02/27 07:49:28 For one line if statements don't add { }
apiccion 2013/02/28 01:31:04 Done.
+ }
+ if (!neighborhood.empty()) {
David Trainor- moved to gerrit 2013/02/27 07:49:28 Same
apiccion 2013/02/28 01:31:04 Done.
+ accVector.push_back(neighborhood);
+ }
+
+ if (accVector.empty()) {
+ return string16();
+ } else {
+ string16 acc;
+ string16 delimeter = ASCIIToUTF16(", ");
+ for (std::vector<string16>::size_type i = 0; i < accVector.size() - 1; i++){
+ acc += accVector[i] + delimeter;
+ }
+ acc += accVector[accVector.size() - 1];
+ return acc;
+ }
+}
+
+void AuxiliaryProfilesImpl::LoadAddress(AutofillProfile* profile) {
+ string16 street = profileLoader_.GetStreet();
+ string16 pobox = profileLoader_.GetPobox();
+ string16 neighborhood = profileLoader_.GetNeighborhood();
+ string16 city = profileLoader_.GetCity();
+ string16 postalCode = profileLoader_.GetPostalCode();
+ string16 region = profileLoader_.GetRegion();
+ string16 country = profileLoader_.GetCountry();
+
+ string16 street2 = CollapseAddress(pobox, neighborhood);
+
+ profile->SetRawInfo(ADDRESS_HOME_LINE1, street);
+ profile->SetRawInfo(ADDRESS_HOME_LINE2, street2);
+ profile->SetRawInfo(ADDRESS_HOME_CITY, city);
+ profile->SetRawInfo(ADDRESS_HOME_STATE, region);
+ profile->SetRawInfo(ADDRESS_HOME_ZIP, postalCode);
+ profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country);
+}
+
+void AuxiliaryProfilesImpl::LoadName(AutofillProfile* profile) {
+ string16 firstName = profileLoader_.GetFirstName();
+ string16 middleName = profileLoader_.GetMiddleName();
+ string16 lastName = profileLoader_.GetLastName();
+
+ profile->SetRawInfo(NAME_FIRST, firstName);
+ profile->SetRawInfo(NAME_LAST, lastName);
+ profile->SetRawInfo(NAME_MIDDLE, middleName);
+
+/* Trips NOTREACHED assertion in |NameInfo| due
David Trainor- moved to gerrit 2013/02/27 07:49:28 Just remove this if it's working as expected and w
apiccion 2013/02/28 01:31:04 Done.
+ * to absense of NAME_SUFFIX case handler
+ * string16 suffix = profileLoader_.GetSuffix();
+ * profile->SetRawInfo(NAME_SUFFIX, suffix);
+*/
+}
+
+void AuxiliaryProfilesImpl::LoadEmailAddress(AutofillProfile* profile) {
+ std::vector<string16> emailAddressVector = profileLoader_.GetEmailAddresses();
+ profile->SetRawMultiInfo(EMAIL_ADDRESS, emailAddressVector);
+}
+
+void AuxiliaryProfilesImpl::LoadPhoneNumbers(AutofillProfile* profile) {
+ std::vector<string16> phoneNumbersVector = profileLoader_.GetPhoneNumbers();
+ profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumbersVector);
+}

Powered by Google App Engine
This is Rietveld 408576698