#include "components/commerce/core/product_specifications/product_specifications_service.h"
#include <memory>
#include <optional>
#include "base/base64.h"
#include "base/containers/map_util.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/hash/sha1.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_types.h"
#include "components/commerce/core/product_specifications/product_specifications_set.h"
#include "components/sync/model/proxy_data_type_controller_delegate.h"
#include "components/sync/protocol/product_comparison_specifics.pb.h"
namespace {
std::string GetSuffix(const std::string& uuid) { … }
syncer::UniquePosition GetNextPosition(
const syncer::UniquePosition& prev_position,
const std::string& suffix) { … }
const sync_pb::ProductComparisonSpecifics* GetTopLevelSpecific(
const std::string& uuid,
const std::map<std::string, sync_pb::ProductComparisonSpecifics>& entries) { … }
std::vector<sync_pb::ProductComparisonSpecifics> GetItemSpecifics(
const std::string& uuid,
const std::map<std::string, sync_pb::ProductComparisonSpecifics>& entries) { … }
std::vector<sync_pb::ProductComparisonSpecifics> CreateItemLevelSpecifics(
const std::string& top_level_uuid,
const std::vector<commerce::UrlInfo>& url_infos,
const base::Time& now) { … }
void SortItemSpecifics(
std::vector<sync_pb::ProductComparisonSpecifics>& item_specifics) { … }
std::optional<commerce::ProductSpecificationsSet>
GetProductSpecificationsSetFromMultiSpecifics(
const base::Uuid& uuid,
const std::map<std::string, sync_pb::ProductComparisonSpecifics>& entries) { … }
std::vector<GURL> GetUrls(const std::vector<commerce::UrlInfo> url_infos) { … }
std::vector<commerce::UrlInfo> GetUrlInfos(std::vector<GURL> urls) { … }
}
namespace commerce {
ProductSpecificationsService::ProductSpecificationsService(
syncer::OnceDataTypeStoreFactory create_store_callback,
std::unique_ptr<syncer::DataTypeLocalChangeProcessor> change_processor)
: … { … }
ProductSpecificationsService::~ProductSpecificationsService() = default;
base::WeakPtr<syncer::DataTypeControllerDelegate>
ProductSpecificationsService::GetSyncControllerDelegate() { … }
const std::vector<ProductSpecificationsSet>
ProductSpecificationsService::GetAllProductSpecifications() { … }
void ProductSpecificationsService::GetAllProductSpecifications(
GetAllCallback callback) { … }
const std::optional<ProductSpecificationsSet>
ProductSpecificationsService::GetSetByUuid(const base::Uuid& uuid) { … }
void ProductSpecificationsService::GetSetByUuid(
const base::Uuid& uuid,
base::OnceCallback<void(std::optional<ProductSpecificationsSet>)>
callback) { … }
const std::optional<ProductSpecificationsSet>
ProductSpecificationsService::AddProductSpecificationsSet(
const std::string& name,
const std::vector<UrlInfo>& url_infos) { … }
const std::optional<ProductSpecificationsSet>
ProductSpecificationsService::SetUrls(const base::Uuid& uuid,
const std::vector<UrlInfo>& url_infos) { … }
const std::optional<ProductSpecificationsSet>
ProductSpecificationsService::SetName(const base::Uuid& uuid,
const std::string& name) { … }
void ProductSpecificationsService::DeleteProductSpecificationsSet(
const std::string& uuid) { … }
void ProductSpecificationsService::AddObserver(
commerce::ProductSpecificationsSet::Observer* observer) { … }
void ProductSpecificationsService::RemoveObserver(
commerce::ProductSpecificationsSet::Observer* observer) { … }
void ProductSpecificationsService::OnInit() { … }
void ProductSpecificationsService::OnProductSpecificationsSetAdded(
const ProductSpecificationsSet& product_specifications_set) { … }
void ProductSpecificationsService::OnSpecificsAdded(
const std::vector<sync_pb::ProductComparisonSpecifics> specifics) { … }
void ProductSpecificationsService::OnSpecificsUpdated(
const std::vector<std::pair<sync_pb::ProductComparisonSpecifics,
sync_pb::ProductComparisonSpecifics>>
before_after_specifics) { … }
void ProductSpecificationsService::OnSpecificsRemoved(
const std::vector<sync_pb::ProductComparisonSpecifics> removed_specifics) { … }
void ProductSpecificationsService::OnMultiSpecificsChanged(
const std::vector<sync_pb::ProductComparisonSpecifics> changed_specifics,
const std::map<std::string, sync_pb::ProductComparisonSpecifics>
before_entries) { … }
void ProductSpecificationsService::NotifyProductSpecificationsAdded(
const ProductSpecificationsSet& added_set) { … }
void ProductSpecificationsService::NotifyProductSpecificationsUpdate(
const ProductSpecificationsSet& before,
const ProductSpecificationsSet& after) { … }
void ProductSpecificationsService::NotifyProductSpecificationsRemoval(
const ProductSpecificationsSet& set) { … }
void ProductSpecificationsService::MigrateLegacySpecificsIfApplicable() { … }
}