chromium/chrome/browser/cart/cart_service.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/cart/cart_service.h"

#include <optional>
#include <vector>

#include "base/containers/contains.h"
#include "base/json/json_reader.h"
#include "base/metrics/field_trial_params.h"
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/cart/cart_discount_metric_collector.h"
#include "chrome/browser/cart/chrome_cart.mojom.h"
#include "chrome/browser/commerce/coupons/coupon_service_factory.h"
#include "chrome/browser/commerce/shopping_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/new_tab_page/new_tab_page_util.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/commerce/commerce_prompt.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/commerce/core/commerce_constants.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_heuristics_data.h"
#include "components/commerce/core/commerce_heuristics_data_metrics_helper.h"
#include "components/commerce/core/proto/cart_db_content.pb.h"
#include "components/commerce/core/proto/price_tracking.pb.h"
#include "components/commerce/core/shopping_service.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"

namespace {
constexpr char kFakeDataPrefix[] =;
constexpr char kCartPrefsKey[] =;

constexpr base::FeatureParam<std::string> kSkipCartExtractionPattern{};

constexpr base::FeatureParam<bool> kBypassDisocuntFetchingThreshold{};

std::string eTLDPlusOne(const GURL& url) {}

std::string GetKeyForURL(const GURL& url) {}

bool CompareTimeStampForProtoPair(const CartDB::KeyAndValue pair1,
                                  CartDB::KeyAndValue pair2) {}

base::Value::Dict JSONToDictionary(int resource_id) {}

const re2::RE2& GetSkipCartExtractionPattern() {}

// Check if any product in existing_proto is no longer in new_proto.
bool ProductsRemoved(cart_db::ChromeCartContentProto existing_proto,
                     cart_db::ChromeCartContentProto new_proto) {}

// Check if products in existing_proto are the same as the new_proto.
bool HaveSameProducts(cart_db::ChromeCartContentProto existing_proto,
                      cart_db::ChromeCartContentProto new_proto) {}
}  // namespace

CartService::CartService(Profile* profile)
    :{}

CartService::~CartService() = default;

void CartService::RegisterProfilePrefs(PrefRegistrySimple* registry) {}

void CartService::Hide() {}

void CartService::RestoreHidden() {}

bool CartService::IsHidden() {}

void CartService::LoadCart(const std::string& domain,
                           CartDB::LoadCallback callback) {}

void CartService::LoadAllActiveCarts(CartDB::LoadCallback callback) {}

void CartService::AddCart(const GURL& navigation_url,
                          const std::optional<GURL>& cart_url,
                          const cart_db::ChromeCartContentProto& proto) {}

void CartService::DeleteCart(const GURL& url, bool ignore_remove_status) {}

void CartService::HideCart(const GURL& cart_url,
                           CartDB::OperationCallback callback) {}

void CartService::RestoreHiddenCart(const GURL& cart_url,
                                    CartDB::OperationCallback callback) {}

void CartService::RemoveCart(const GURL& cart_url,
                             CartDB::OperationCallback callback) {}

void CartService::RestoreRemovedCart(const GURL& cart_url,
                                     CartDB::OperationCallback callback) {}

void CartService::IncreaseWelcomeSurfaceCounter() {}

bool CartService::ShouldShowWelcomeSurface() {}

void CartService::AcknowledgeDiscountConsent(bool should_enable) {}

void CartService::DismissedDiscountConsent() {}

void CartService::InterestedInDiscountConsent() {}

const GURL CartService::AppendUTM(const GURL& base_url) {}

void CartService::HasActiveCartForURL(const GURL& url,
                                      base::OnceCallback<void(bool)> callback) {}

bool CartService::IsCartEnabled() {}

void CartService::ShouldShowDiscountConsent(
    base::OnceCallback<void(bool)> callback) {}

void CartService::RecordDiscountConsentStatusAtLoad(bool should_show_consent) {}

bool CartService::IsCartExpired(const cart_db::ChromeCartContentProto& proto) {}

void CartService::HasActiveCartForURLCallback(
    base::OnceCallback<void(bool)> callback,
    bool success,
    std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::MaybeCommitDeletion(GURL url) {}

void CartService::ShouldShowDiscountConsentCallback(
    base::OnceCallback<void(bool)> callback,
    bool success,
    std::vector<CartDB::KeyAndValue> proto_pairs) {}

bool CartService::ShouldShowDiscountToggle() {}

bool CartService::IsCartDiscountEnabled() {}

void CartService::SetCartDiscountEnabled(bool enabled) {}

void CartService::GetDiscountURL(
    const GURL& cart_url,
    base::OnceCallback<void(const ::GURL&)> callback) {}

void CartService::OnGetDiscountURL(
    const GURL& default_cart_url,
    base::OnceCallback<void(const ::GURL&)> callback,
    bool success,
    std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::OnDiscountURLFetched(
    const GURL& default_cart_url,
    base::OnceCallback<void(const ::GURL&)> callback,
    const cart_db::ChromeCartContentProto& cart_proto,
    const GURL& discount_url) {}

void CartService::PrepareForNavigation(const GURL& cart_url,
                                       bool is_navigating) {}

void CartService::LoadCartsWithFakeData(CartDB::LoadCallback callback) {}

void CartService::OnOperationFinished(bool success) {}

void CartService::OnOperationFinishedWithCallback(
    CartDB::OperationCallback callback,
    bool success) {}

void CartService::Shutdown() {}

void CartService::OnHistoryDeletions(
    history::HistoryService* history_service,
    const history::DeletionInfo& deletion_info) {}

CartDB* CartService::GetDB() {}

void CartService::AddCartsWithFakeData() {}

void CartService::DeleteCartsWithFakeData() {}

void CartService::DeleteRemovedCartsContent(
    bool success,
    std::vector<CartDB::KeyAndValue> proto_pairs) {}

bool CartService::ShouldSkip(const GURL& url) {}

void CartService::OnLoadCarts(CartDB::LoadCallback callback,
                              bool success,
                              std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::SetCartHiddenStatus(
    bool isHidden,
    CartDB::OperationCallback callback,
    bool success,
    std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::SetCartRemovedStatus(
    bool isRemoved,
    CartDB::OperationCallback callback,
    bool success,
    std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::OnAddCart(const GURL& navigation_url,
                            const std::optional<GURL>& cart_url,
                            cart_db::ChromeCartContentProto proto,
                            bool success,
                            std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::UpdateDiscounts(const GURL& cart_url,
                                  cart_db::ChromeCartContentProto new_proto,
                                  const bool is_tester) {}

void CartService::StartGettingDiscount() {}

bool CartService::IsDiscountUsed(const std::string& rule_id) {}

void CartService::RecordFetchTimestamp() {}

void CartService::UpdateFreeListingCoupons(
    const CouponService::CouponsMap& map) {}

void CartService::CacheUsedDiscounts(
    const cart_db::ChromeCartContentProto& proto) {}

void CartService::CleanUpDiscounts(cart_db::ChromeCartContentProto proto) {}

void CartService::OnDeleteCart(bool success,
                               std::vector<CartDB::KeyAndValue> proto_pairs) {}

void CartService::OnCartFeaturesChanged(const std::string& pref_name) {}

bool CartService::IsCartAndDiscountEnabled() {}

void CartService::SetCartDiscountLinkFetcherForTesting(
    std::unique_ptr<CartDiscountLinkFetcher> discount_link_fetcher) {}

void CartService::SetFetchDiscountWorkerForTesting(
    std::unique_ptr<FetchDiscountWorker> fetch_discount_worker) {}

void CartService::SetCouponServiceForTesting(CouponService* coupon_service) {}

void CartService::ShowNativeConsentDialog(
    Browser* browser,
    base::OnceCallback<void(chrome_cart::mojom::ConsentStatus)>
        consent_status_callback) {}