Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Replace SaveImportedProfile and SaveImportedCreditCard by Add/UpdateProfile and Add/UpdateCreditCard #61

Merged
merged 1 commit into from
Sep 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions atom/browser/api/atom_api_autofill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "atom/browser/autofill/personal_data_manager_factory.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "brave/browser/brave_content_browser_client.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h"

Expand Down Expand Up @@ -159,7 +161,7 @@ Autofill::~Autofill() {

std::string Autofill::AddProfile(const base::DictionaryValue& profile) {
std::string full_name, company_name, street_address, city, state, locality,
postal_code, sorting_code, country_code, phone, email, language_code;
postal_code, sorting_code, country_code, phone, email, language_code, guid;
profile.GetString("full_name", &full_name);
profile.GetString("company_name", &company_name);
profile.GetString("street_address", &street_address);
Expand All @@ -172,6 +174,10 @@ std::string Autofill::AddProfile(const base::DictionaryValue& profile) {
profile.GetString("phone", &phone);
profile.GetString("email", &email);
profile.GetString("language_code", &language_code);
if (!profile.GetString("guid", &guid)) {
NOTREACHED();
return std::string();
}
autofill::PersonalDataManager* personal_data =
autofill::PersonalDataManagerFactory::GetForBrowserContext(
browser_context_);
Expand All @@ -180,7 +186,8 @@ std::string Autofill::AddProfile(const base::DictionaryValue& profile) {
return std::string();
}

autofill::AutofillProfile autofill_profile;
autofill::AutofillProfile autofill_profile(guid, autofill::kSettingsOrigin);

if (!full_name.empty()) {
autofill_profile.SetInfo(autofill::AutofillType(autofill::NAME_FULL),
base::UTF8ToUTF16(full_name),
Expand Down Expand Up @@ -249,7 +256,13 @@ std::string Autofill::AddProfile(const base::DictionaryValue& profile) {
if (!language_code.empty())
autofill_profile.set_language_code(language_code);

return personal_data->SaveImportedProfile(autofill_profile);
if (!base::IsValidGUID(autofill_profile.guid())) {
autofill_profile.set_guid(base::GenerateGUID());
personal_data->AddProfile(autofill_profile);
} else {
personal_data->UpdateProfile(autofill_profile);
}
return autofill_profile.guid();
}

autofill::AutofillProfile* Autofill::GetProfile(const std::string& guid) {
Expand Down Expand Up @@ -278,11 +291,15 @@ bool Autofill::RemoveProfile(const std::string& guid) {
}

std::string Autofill::AddCreditCard(const base::DictionaryValue& card) {
std::string name, card_number, expiration_month, expiration_year;
std::string name, card_number, expiration_month, expiration_year, guid;
card.GetString("name", &name);
card.GetString("card_number", &card_number);
card.GetString("expiration_month", &expiration_month);
card.GetString("expiration_year", &expiration_year);
if (!card.GetString("guid", &guid)) {
NOTREACHED();
return std::string();
}
autofill::PersonalDataManager* personal_data =
autofill::PersonalDataManagerFactory::GetForBrowserContext(
browser_context_);
Expand All @@ -291,7 +308,7 @@ std::string Autofill::AddCreditCard(const base::DictionaryValue& card) {
return std::string();
}

autofill::CreditCard credit_card;
autofill::CreditCard credit_card(guid, autofill::kSettingsOrigin);
if (!name.empty()) {
credit_card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL,
base::UTF8ToUTF16(name));
Expand All @@ -315,7 +332,13 @@ std::string Autofill::AddCreditCard(const base::DictionaryValue& card) {
base::UTF8ToUTF16(expiration_year));
}

return personal_data->SaveImportedCreditCard(credit_card);
if (!base::IsValidGUID(credit_card.guid())) {
credit_card.set_guid(base::GenerateGUID());
personal_data->AddCreditCard(credit_card);
} else {
personal_data->UpdateCreditCard(credit_card);
}
return credit_card.guid();
}

autofill::CreditCard* Autofill::GetCreditCard(const std::string& guid) {
Expand Down