#include "components/commerce/core/compare/cluster_manager.h"
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "base/barrier_callback.h"
#include "base/containers/contains.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_utils.h"
#include "components/commerce/core/compare/candidate_product.h"
#include "components/commerce/core/compare/cluster_server_proxy.h"
#include "components/commerce/core/compare/product_group.h"
#include "components/commerce/core/product_specifications/product_specifications_service.h"
namespace commerce {
namespace {
bool IsUrlOpen(
GURL url,
const ClusterManager::GetOpenUrlInfosCallback& get_open_url_infos_cb) { … }
std::optional<std::string> GetShortLabelForCategory(
const CategoryLabel& category_label) { … }
std::optional<std::string> GetLabelFromBottom(const ProductCategory& category,
int level_from_bottom) { … }
std::string FindTitleForSimilarProducts(
const std::vector<std::pair<GURL, const ProductInfo>>& product_infos) { … }
bool ShouldCluster(const CategoryData& category_data) { … }
bool AreCategoriesSimilar(const CategoryData& first,
const CategoryData& second) { … }
bool IsProductSimilarToGroup(
const CategoryData& category,
const std::vector<CategoryData>& group_categories) { … }
void OnGetCategoryDataDone(
base::OnceCallback<void(const CategoryData&)> callback,
const GURL& url,
const std::optional<const ProductInfo>& product_info) { … }
void GetCategoryData(
const GURL& url,
const ClusterManager::GetProductInfoCallback& get_product_info_cb,
base::OnceCallback<void(const CategoryData&)> callback) { … }
void OnGetProductInfoDone(
base::OnceCallback<void(std::pair<GURL, const ProductInfo>)> callback,
const GURL& url,
const std::optional<const ProductInfo>& product_info) { … }
void GetProductInfo(
const GURL& url,
const ClusterManager::GetProductInfoCallback& get_product_info_cb,
base::OnceCallback<void(std::pair<GURL, const ProductInfo>)> callback) { … }
bool IsCandidateProductInProductGroup(
const GURL& candidate_product_url,
const std::map<base::Uuid, std::unique_ptr<ProductGroup>>&
product_group_map) { … }
}
ClusterManager::ClusterManager(
ProductSpecificationsService* product_specification_service,
std::unique_ptr<ClusterServerProxy> cluster_server_proxy,
const GetProductInfoCallback& get_product_info_cb,
const GetOpenUrlInfosCallback& get_open_url_infos_cb)
: … { … }
ClusterManager::~ClusterManager() { … }
void ClusterManager::OnGetAllProductSpecificationsSets(
const std::vector<ProductSpecificationsSet> sets) { … }
void ClusterManager::OnProductSpecificationsSetAdded(
const ProductSpecificationsSet& product_specifications_set) { … }
void ClusterManager::OnProductSpecificationsSetUpdate(
const ProductSpecificationsSet& before,
const ProductSpecificationsSet& product_specifications_set) { … }
void ClusterManager::OnProductSpecificationsSetRemoved(
const ProductSpecificationsSet& set) { … }
void ClusterManager::WebWrapperDestroyed(const GURL& url) { … }
void ClusterManager::DidNavigatePrimaryMainFrame(const GURL& url) { … }
void ClusterManager::DidNavigateAway(const GURL& from_url) { … }
std::optional<ProductGroup> ClusterManager::GetProductGroupForCandidateProduct(
const GURL& product_url) { … }
void ClusterManager::OnProductInfoRetrieved(
const GURL& url,
const std::optional<const ProductInfo>& product_info) { … }
void ClusterManager::OnAllCategoryDataRetrieved(
const base::Uuid& uuid,
const std::set<GURL>& urls,
const std::vector<CategoryData>& category_data) { … }
void ClusterManager::AddCandidateProduct(
const GURL& url,
const std::optional<const ProductInfo>& product_info) { … }
void ClusterManager::RemoveCandidateProductURLIfNotOpen(const GURL& url) { … }
std::vector<GURL> ClusterManager::FindSimilarCandidateProductsForProductGroup(
const base::Uuid& uuid) { … }
void ClusterManager::AddObserver(Observer* observer) { … }
void ClusterManager::RemoveObserver(Observer* observer) { … }
void ClusterManager::GetComparableProducts(
const EntryPointInfo& entry_point_info,
GetEntryPointInfoCallback callback) { … }
std::set<GURL> ClusterManager::FindSimilarCandidateProducts(
const GURL& product_url) { … }
void ClusterManager::GetEntryPointInfoForNavigation(
const GURL& url,
GetEntryPointInfoCallback callback) { … }
void ClusterManager::GetEntryPointInfoForSelection(
const GURL& old_url,
const GURL& new_url,
GetEntryPointInfoCallback callback) { … }
void ClusterManager::OnProductInfoFetchedForSimilarUrls(
GetEntryPointInfoCallback callback,
const std::vector<std::pair<GURL, const ProductInfo>>& product_infos) { … }
void ClusterManager::OnGetComparableProducts(
const EntryPointInfo& entry_point_info,
GetEntryPointInfoCallback callback,
const std::vector<uint64_t>& cluster_product_ids) { … }
bool ClusterManager::IsSetEligibleForClustering(const base::Uuid& uuid,
const base::Time& update_time) { … }
void ClusterManager::RemoveIneligibleGroupsForClustering() { … }
}