Commit b618fb38 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Autofill] Introduce AddressProfileSaveManager

This class will encapsulate the logic for saving address profile.
This CL doesn't introduce any behavioral change.

Bug: 1135178
Change-Id: I4bda0220f56f3e1f5377c24cd47cd0e0b42ae8b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450282Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814246}
parent fd2e0493
......@@ -25,6 +25,8 @@ static_library("browser") {
"address_normalizer.h",
"address_normalizer_impl.cc",
"address_normalizer_impl.h",
"address_profiles/address_profile_save_manager.cc",
"address_profiles/address_profile_save_manager.h",
"address_rewriter.cc",
"address_rewriter.h",
"autocomplete_history_manager.cc",
......@@ -581,6 +583,7 @@ source_set("unit_tests") {
sources = [
"address_normalization_manager_unittest.cc",
"address_normalizer_impl_unittest.cc",
"address_profiles/address_profile_save_manager_unittest.cc",
"address_rewriter_unittest.cc",
"autocomplete_history_manager_unittest.cc",
"autofill_address_policy_handler_unittest.cc",
......
// Copyright 2020 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 "components/autofill/core/browser/address_profiles/address_profile_save_manager.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/personal_data_manager.h"
namespace autofill {
AddressProfileSaveManager::AddressProfileSaveManager(
PersonalDataManager* personal_data_manager)
: personal_data_manager_(personal_data_manager) {}
AddressProfileSaveManager::~AddressProfileSaveManager() = default;
std::string AddressProfileSaveManager::SaveProfile(
const AutofillProfile& profile) {
return personal_data_manager_
? personal_data_manager_->SaveImportedProfile(profile)
: std::string();
}
} // namespace autofill
// Copyright 2020 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.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_PROFILES_ADDRESS_PROFILE_SAVE_MANAGER_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_PROFILES_ADDRESS_PROFILE_SAVE_MANAGER_H_
#include <string>
namespace autofill {
class AutofillProfile;
class PersonalDataManager;
// Manages logic for saving address profiles to the database. Owned by
// FormDataImporter.
class AddressProfileSaveManager {
public:
explicit AddressProfileSaveManager(
PersonalDataManager* personal_data_manager);
AddressProfileSaveManager(const AddressProfileSaveManager&) = delete;
AddressProfileSaveManager& operator=(const AddressProfileSaveManager&) =
delete;
virtual ~AddressProfileSaveManager();
// Saves `imported_profile` using the `personal_data_manager_`. Returns the
// guid of the new or updated profile, or the empty string if no profile was
// saved.
std::string SaveProfile(const AutofillProfile& imported_profile);
private:
// The personal data manager, used to save and load personal data to/from the
// web database.
PersonalDataManager* const personal_data_manager_;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_PROFILES_ADDRESS_PROFILE_SAVE_MANAGER_H_
// Copyright 2020 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 "components/autofill/core/browser/address_profiles/address_profile_save_manager.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
namespace {
class MockPersonalDataManager : public TestPersonalDataManager {
public:
MockPersonalDataManager() = default;
~MockPersonalDataManager() override = default;
MOCK_METHOD(std::string,
SaveImportedProfile,
(const AutofillProfile&),
(override));
};
} // namespace
TEST(AddressProfileSaveManager, SaveProfile) {
MockPersonalDataManager pdm;
AddressProfileSaveManager save_manager(&pdm);
AutofillProfile test_profile = test::GetFullProfile();
EXPECT_CALL(pdm, SaveImportedProfile(test_profile));
save_manager.SaveProfile(test_profile);
}
} // namespace autofill
......@@ -19,6 +19,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/address_profiles/address_profile_save_manager.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/autofill_type.h"
......@@ -230,6 +231,8 @@ FormDataImporter::FormDataImporter(AutofillClient* client,
payments_client,
app_locale,
personal_data_manager)),
address_profile_save_manager_(
std::make_unique<AddressProfileSaveManager>(personal_data_manager)),
#if !defined(OS_ANDROID) && !defined(OS_IOS)
local_card_migration_manager_(
std::make_unique<LocalCardMigrationManager>(client,
......@@ -687,7 +690,7 @@ bool FormDataImporter::ImportAddressProfileForSection(
return false;
std::string guid =
personal_data_manager_->SaveImportedProfile(candidate_profile);
address_profile_save_manager_->SaveProfile(candidate_profile);
return !guid.empty();
}
......
......@@ -24,6 +24,8 @@ class SaveCardOfferObserver;
namespace autofill {
class AddressProfileSaveManager;
// Manages logic for importing address profiles and credit card information from
// web forms into the user's Autofill profile via the PersonalDataManager.
// Owned by AutofillManager.
......@@ -151,6 +153,9 @@ class FormDataImporter {
// Responsible for managing credit card save flows (local or upload).
std::unique_ptr<CreditCardSaveManager> credit_card_save_manager_;
// Responsible for managing address profiles save flows.
std::unique_ptr<AddressProfileSaveManager> address_profile_save_manager_;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
// Responsible for migrating locally saved credit cards to Google Pay.
std::unique_ptr<LocalCardMigrationManager> local_card_migration_manager_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment