#include "components/commerce/core/webui/shopping_service_handler.h"
#include <memory>
#include <vector>
#include "base/check_is_test.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/uuid.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/commerce/core/commerce_constants.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_types.h"
#include "components/commerce/core/commerce_utils.h"
#include "components/commerce/core/feature_utils.h"
#include "components/commerce/core/metrics/metrics_utils.h"
#include "components/commerce/core/pref_names.h"
#include "components/commerce/core/price_tracking_utils.h"
#include "components/commerce/core/shopping_service.h"
#include "components/commerce/core/subscriptions/commerce_subscription.h"
#include "components/commerce/core/webui/webui_utils.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/optimization_guide/core/model_quality/feature_type_map.h"
#include "components/optimization_guide/core/model_quality/model_quality_logs_uploader_service.h"
#include "components/optimization_guide/proto/features/product_specifications.pb.h"
#include "components/payments/core/currency_formatter.h"
#include "components/power_bookmarks/core/power_bookmark_utils.h"
#include "components/power_bookmarks/core/proto/power_bookmark_meta.pb.h"
#include "components/power_bookmarks/core/proto/shopping_specifics.pb.h"
#include "components/prefs/pref_service.h"
#include "components/url_formatter/elide_url.h"
#include "url/gurl.h"
namespace commerce {
namespace {
shopping_service::mojom::BookmarkProductInfoPtr BookmarkNodeToMojoProduct(
bookmarks::BookmarkModel& model,
const bookmarks::BookmarkNode* node,
const std::string& locale) { … }
std::vector<shopping_service::mojom::UrlInfoPtr> UrlInfoToMojo(
const std::vector<UrlInfo>& url_infos) { … }
shopping_service::mojom::PriceInsightsInfoPtr PriceInsightsInfoToMojoObject(
const std::optional<PriceInsightsInfo>& info,
const std::string& locale) { … }
shopping_service::mojom::ProductSpecificationsDescriptionTextPtr
DescriptionTextToMojo(const ProductSpecifications::DescriptionText& desc_text) { … }
shopping_service::mojom::ProductSpecificationsPtr ProductSpecsToMojo(
const ProductSpecifications& specs) { … }
shopping_service::mojom::ProductSpecificationsSetPtr ProductSpecsSetToMojo(
const ProductSpecificationsSet& set) { … }
std::unique_ptr<optimization_guide::ModelQualityLogEntry>
PrepareQualityLogEntry(optimization_guide::ModelQualityLogsUploaderService*
model_quality_logs_uploader_service) { … }
void ConvertDescriptionTextToProto(
ProductSpecifications::DescriptionText description_text,
optimization_guide::proto::DescriptionText* description_proto) { … }
void ConvertProductSpecificationsToProto(
ProductSpecifications specs,
optimization_guide::proto::ProductSpecificationData* product_spec_data) { … }
void RecordQualityEntry(
optimization_guide::proto::ProductSpecificationsQuality* quality_proto,
std::vector<GURL> input_urls,
ProductSpecifications specs) { … }
}
BookmarkProductInfo;
BookmarkProductInfoPtr;
ShoppingServiceHandler::ShoppingServiceHandler(
mojo::PendingRemote<shopping_service::mojom::Page> remote_page,
mojo::PendingReceiver<shopping_service::mojom::ShoppingServiceHandler>
receiver,
bookmarks::BookmarkModel* bookmark_model,
ShoppingService* shopping_service,
PrefService* prefs,
feature_engagement::Tracker* tracker,
std::unique_ptr<Delegate> delegate,
optimization_guide::ModelQualityLogsUploaderService*
model_quality_logs_uploader_service)
: … { … }
ShoppingServiceHandler::~ShoppingServiceHandler() = default;
void ShoppingServiceHandler::GetAllPriceTrackedBookmarkProductInfo(
GetAllPriceTrackedBookmarkProductInfoCallback callback) { … }
void ShoppingServiceHandler::OnFetchPriceTrackedBookmarks(
GetAllPriceTrackedBookmarkProductInfoCallback callback,
std::vector<const bookmarks::BookmarkNode*> bookmarks) { … }
void ShoppingServiceHandler::GetAllShoppingBookmarkProductInfo(
GetAllShoppingBookmarkProductInfoCallback callback) { … }
void ShoppingServiceHandler::TrackPriceForBookmark(int64_t bookmark_id) { … }
void ShoppingServiceHandler::UntrackPriceForBookmark(int64_t bookmark_id) { … }
void ShoppingServiceHandler::OnSubscribe(
const CommerceSubscription& subscription,
bool succeeded) { … }
void ShoppingServiceHandler::OnUnsubscribe(
const CommerceSubscription& subscription,
bool succeeded) { … }
void ShoppingServiceHandler::BookmarkModelChanged() { … }
void ShoppingServiceHandler::BookmarkNodeMoved(
const bookmarks::BookmarkNode* old_parent,
size_t old_index,
const bookmarks::BookmarkNode* new_parent,
size_t new_index) { … }
void ShoppingServiceHandler::HandleSubscriptionChange(
const CommerceSubscription& sub,
bool is_tracking) { … }
std::vector<BookmarkProductInfoPtr>
ShoppingServiceHandler::BookmarkListToMojoList(
bookmarks::BookmarkModel& model,
const std::vector<const bookmarks::BookmarkNode*>& bookmarks,
const std::string& locale) { … }
void ShoppingServiceHandler::onPriceTrackResult(int64_t bookmark_id,
bookmarks::BookmarkModel* model,
bool is_tracking,
bool success) { … }
void ShoppingServiceHandler::GetProductInfoForCurrentUrl(
GetProductInfoForCurrentUrlCallback callback) { … }
void ShoppingServiceHandler::GetProductInfoForUrl(
const GURL& url,
GetProductInfoForUrlCallback callback) { … }
void ShoppingServiceHandler::IsShoppingListEligible(
IsShoppingListEligibleCallback callback) { … }
void ShoppingServiceHandler::GetShoppingCollectionBookmarkFolderId(
GetShoppingCollectionBookmarkFolderIdCallback callback) { … }
void ShoppingServiceHandler::GetPriceTrackingStatusForCurrentUrl(
GetPriceTrackingStatusForCurrentUrlCallback callback) { … }
void ShoppingServiceHandler::SetPriceTrackingStatusForCurrentUrl(bool track) { … }
void ShoppingServiceHandler::GetParentBookmarkFolderNameForCurrentUrl(
GetParentBookmarkFolderNameForCurrentUrlCallback callback) { … }
void ShoppingServiceHandler::ShowBookmarkEditorForCurrentUrl() { … }
void ShoppingServiceHandler::ShowProductSpecificationsSetForUuid(
const base::Uuid& uuid,
bool in_new_tab) { … }
void ShoppingServiceHandler::GetPriceInsightsInfoForCurrentUrl(
GetPriceInsightsInfoForCurrentUrlCallback callback) { … }
void ShoppingServiceHandler::GetPriceInsightsInfoForUrl(
const GURL& url,
GetPriceInsightsInfoForUrlCallback callback) { … }
void ShoppingServiceHandler::GetProductSpecificationsForUrls(
const std::vector<::GURL>& urls,
GetProductSpecificationsForUrlsCallback callback) { … }
void ShoppingServiceHandler::GetUrlInfosForProductTabs(
GetUrlInfosForProductTabsCallback callback) { … }
void ShoppingServiceHandler::GetUrlInfosForRecentlyViewedTabs(
GetUrlInfosForRecentlyViewedTabsCallback callback) { … }
void ShoppingServiceHandler::OnFetchPriceInsightsInfoForCurrentUrl(
GetPriceInsightsInfoForCurrentUrlCallback callback,
const GURL& url,
const std::optional<PriceInsightsInfo>& info) { … }
void ShoppingServiceHandler::ShowInsightsSidePanelUI() { … }
void ShoppingServiceHandler::OnGetPriceTrackingStatusForCurrentUrl(
GetPriceTrackingStatusForCurrentUrlCallback callback,
bool tracked) { … }
void ShoppingServiceHandler::OpenUrlInNewTab(const GURL& url) { … }
void ShoppingServiceHandler::SwitchToOrOpenTab(const GURL& url) { … }
void ShoppingServiceHandler::ShowFeedbackForPriceInsights() { … }
void ShoppingServiceHandler::GetAllProductSpecificationsSets(
GetAllProductSpecificationsSetsCallback callback) { … }
void ShoppingServiceHandler::GetProductSpecificationsSetByUuid(
const base::Uuid& uuid,
GetProductSpecificationsSetByUuidCallback callback) { … }
void ShoppingServiceHandler::AddProductSpecificationsSet(
const std::string& name,
const std::vector<GURL>& urls,
AddProductSpecificationsSetCallback callback) { … }
void ShoppingServiceHandler::DeleteProductSpecificationsSet(
const base::Uuid& uuid) { … }
void ShoppingServiceHandler::SetNameForProductSpecificationsSet(
const base::Uuid& uuid,
const std::string& name,
SetNameForProductSpecificationsSetCallback callback) { … }
void ShoppingServiceHandler::SetUrlsForProductSpecificationsSet(
const base::Uuid& uuid,
const std::vector<GURL>& urls,
SetUrlsForProductSpecificationsSetCallback callback) { … }
void ShoppingServiceHandler::SetProductSpecificationsUserFeedback(
shopping_service::mojom::UserFeedback feedback) { … }
void ShoppingServiceHandler::SetProductSpecificationAcceptedDisclosureVersion(
shopping_service::mojom::ProductSpecificationsDisclosureVersion version) { … }
void ShoppingServiceHandler::MaybeShowProductSpecificationDisclosure(
const std::vector<GURL>& urls,
const std::string& name,
MaybeShowProductSpecificationDisclosureCallback callback) { … }
void ShoppingServiceHandler::DeclineProductSpecificationDisclosure() { … }
void ShoppingServiceHandler::GetProductSpecificationsFeatureState(
GetProductSpecificationsFeatureStateCallback callback) { … }
void ShoppingServiceHandler::OnProductSpecificationsSetAdded(
const ProductSpecificationsSet& set) { … }
void ShoppingServiceHandler::OnProductSpecificationsSetUpdate(
const ProductSpecificationsSet& before,
const ProductSpecificationsSet& set) { … }
void ShoppingServiceHandler::OnProductSpecificationsSetRemoved(
const ProductSpecificationsSet& set) { … }
void ShoppingServiceHandler::OnGetProductSpecificationsForUrls(
std::vector<GURL> input_urls,
GetProductSpecificationsForUrlsCallback callback,
std::vector<uint64_t> ids,
std::optional<ProductSpecifications> specs) { … }
void ShoppingServiceHandler::ShowSyncSetupFlow() { … }
void ShoppingServiceHandler::GetPageTitleFromHistory(
const GURL& url,
GetPageTitleFromHistoryCallback callback) { … }
}