| Index: chrome/browser/autofill/wallet/wallet_address.cc
|
| diff --git a/chrome/browser/autofill/wallet/wallet_address.cc b/chrome/browser/autofill/wallet/wallet_address.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1f58d82f8f8637ea87124641f10eb63d3ad78035
|
| --- /dev/null
|
| +++ b/chrome/browser/autofill/wallet/wallet_address.cc
|
| @@ -0,0 +1,172 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +#include "chrome/browser/autofill/wallet/wallet_address.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/values.h"
|
| +
|
| +namespace wallet {
|
| +
|
| +Address::Address() {}
|
| +
|
| +Address::Address(const std::string& country_name_code,
|
| + const std::string& recipient_name,
|
| + const std::string& address_line_1,
|
| + const std::string& address_line_2,
|
| + const std::string& locality_name,
|
| + const std::string& administrative_area_name,
|
| + const std::string& postal_code_number,
|
| + const std::string& phone_number,
|
| + const std::string& object_id)
|
| + : country_name_code_(country_name_code),
|
| + recipient_name_(recipient_name),
|
| + address_line_1_(address_line_1),
|
| + address_line_2_(address_line_2),
|
| + locality_name_(locality_name),
|
| + administrative_area_name_(administrative_area_name),
|
| + postal_code_number_(postal_code_number),
|
| + phone_number_(phone_number),
|
| + object_id_(object_id) {}
|
| +
|
| +Address::~Address() {}
|
| +
|
| +scoped_ptr<Address> Address::FromWalletDictionary(
|
| + base::DictionaryValue* dictionary) {
|
| + if (!dictionary)
|
| + return scoped_ptr<Address>();
|
| +
|
| + std::string object_id;
|
| + if (!dictionary->GetString("id", &object_id)) {
|
| + LOG(ERROR) << "Response from Google Wallet missing object id";
|
| + return scoped_ptr<Address>();
|
| + }
|
| + std::string phone_number;
|
| + if (!dictionary->GetString("phone_number", &phone_number)) {
|
| + VLOG(1) << "Response from Google Wallet missing phone number";
|
| + }
|
| + std::string country_name_code;
|
| + if (!dictionary->GetString("postal_address.country_name_code",
|
| + &country_name_code)) {
|
| + LOG(ERROR) << "Response from Google Wallet missing country name";
|
| + return scoped_ptr<Address>();
|
| + }
|
| + std::string recipient_name;
|
| + if (!dictionary->GetString("postal_address.recipient_name",
|
| + &recipient_name)) {
|
| + LOG(ERROR) << "Response from Google Wallet recipient name";
|
| + return scoped_ptr<Address>();
|
| + }
|
| + std::string address_line_1;
|
| + std::string address_line_2;
|
| + ListValue* address_line_list;
|
| + if (dictionary->GetList("postal_address.address_line", &address_line_list)) {
|
| + if (!address_line_list->GetString(0, &address_line_1))
|
| + VLOG(1) << "Response from Google Wallet missing address line 1";
|
| + if (!address_line_list->GetString(1, &address_line_2))
|
| + VLOG(1) << "Response from Google Wallet missing address line 2";
|
| + } else {
|
| + VLOG(1) << "Response from Google Wallet missing address lines";
|
| + }
|
| + std::string locality_name;
|
| + if (!dictionary->GetString("postal_address.locality_name",
|
| + &locality_name)) {
|
| + VLOG(1) << "Response from Google Wallet missing locality name";
|
| + }
|
| + std::string administrative_area_name;
|
| + if (!dictionary->GetString("postal_address.administrative_area_name",
|
| + &administrative_area_name)) {
|
| + VLOG(1) << "Response from Google Wallet missing administrative area name";
|
| + }
|
| + std::string postal_code_number;
|
| + if (!dictionary->GetString("postal_address.postal_code_number",
|
| + &postal_code_number)) {
|
| + LOG(ERROR) << "Response from Google Wallet missing postal code number";
|
| + return scoped_ptr<Address>();
|
| + }
|
| +
|
| + return scoped_ptr<Address>(new Address(country_name_code,
|
| + recipient_name ,
|
| + address_line_1,
|
| + address_line_2,
|
| + locality_name,
|
| + administrative_area_name,
|
| + postal_code_number,
|
| + phone_number,
|
| + object_id));
|
| +}
|
| +
|
| +
|
| +scoped_ptr<Address> Address::FromClientDictionary(
|
| + base::DictionaryValue* dictionary) {
|
| + std::string country_code;
|
| + if (!dictionary->GetString("country_code", &country_code)) {
|
| + LOG(ERROR) << "Reponse from Google Wallet missing country code";
|
| + return scoped_ptr<Address>();
|
| + }
|
| + std::string name;
|
| + if (!dictionary->GetString("name", &name)) {
|
| + LOG(ERROR) << "Reponse from Google Wallet missing name";
|
| + return scoped_ptr<Address>();
|
| + }
|
| + std::string address1;
|
| + if (!dictionary->GetString("address1", &address1))
|
| + VLOG(1) << "Reponse from Google Wallet missing address1";
|
| + std::string address2;
|
| + if (!dictionary->GetString("address2", &address2))
|
| + VLOG(1) << "Reponse from Google Wallet missing address2";
|
| + std::string city;
|
| + if (!dictionary->GetString("city", &city))
|
| + VLOG(1) << "Reponse from Google Wallet missing city";
|
| + std::string state;
|
| + if (!dictionary->GetString("state", &state))
|
| + VLOG(1) << "Reponse from Google Wallet missing state";
|
| + std::string postal_code;
|
| + if (!dictionary->GetString("postal_code", &postal_code)) {
|
| + LOG(ERROR) << "Reponse from Google Wallet missing postal code";
|
| + return scoped_ptr<Address>();
|
| + }
|
| + std::string phone_number;
|
| + if (!dictionary->GetString("phone_number", &phone_number))
|
| + VLOG(1) << "Reponse from Google Wallet missing phone number";
|
| +
|
| + return scoped_ptr<Address>(new Address(country_code,
|
| + name,
|
| + address1,
|
| + address2,
|
| + city,
|
| + state,
|
| + postal_code,
|
| + phone_number,
|
| + ""));
|
| +}
|
| +
|
| +bool Address::operator==(const Address& other) const {
|
| + if (country_name_code_.compare(other.country_name_code_) != 0)
|
| + return false;
|
| + if (recipient_name_.compare(other.recipient_name_) != 0)
|
| + return false;
|
| + if (address_line_1_.compare(other.address_line_1_) != 0)
|
| + return false;
|
| + if (address_line_2_.compare(other.address_line_2_) != 0)
|
| + return false;
|
| + if (locality_name_.compare(other.locality_name_) != 0)
|
| + return false;
|
| + if (administrative_area_name_.compare(other.administrative_area_name_) != 0)
|
| + return false;
|
| + if (postal_code_number_ != other.postal_code_number_)
|
| + return false;
|
| + if (phone_number_.compare(other.phone_number_) != 0)
|
| + return false;
|
| + if (object_id_.compare(other.object_id_) != 0)
|
| + return false;
|
| + return true;
|
| +}
|
| +
|
| +bool Address::operator!=(const Address& other) const {
|
| + return !(*this == other);
|
| +}
|
| +
|
| +
|
| +} // end wallet namespace
|
|
|