#include "chrome/browser/cart/fetch_discount_worker.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/cart/cart_discount_fetcher.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/proto/coupon_db_content.pb.h"
#include "components/search/ntp_features.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/variations/variations.mojom.h"
#include "components/variations/variations_client.h"
#include "components/variations/variations_features.h"
#include "components/variations/variations_ids_provider.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_constants.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/re2/src/re2/re2.h"
namespace {
const char kOauthName[] = …;
const char kOauthScopes[] = …;
const char kEmptyToken[] = …;
}
CartDiscountServiceDelegate::CartDiscountServiceDelegate(
CartService* cart_service)
: … { … }
CartDiscountServiceDelegate::~CartDiscountServiceDelegate() = default;
void CartDiscountServiceDelegate::LoadAllCarts(CartDB::LoadCallback callback) { … }
void CartDiscountServiceDelegate::UpdateCart(
const std::string& cart_url,
const cart_db::ChromeCartContentProto new_proto,
const bool is_tester) { … }
void CartDiscountServiceDelegate::RecordFetchTimestamp() { … }
void CartDiscountServiceDelegate::UpdateFreeListingCoupons(
const CouponService::CouponsMap& map) { … }
FetchDiscountWorker::FetchDiscountWorker(
scoped_refptr<network::SharedURLLoaderFactory>
browserProcessURLLoaderFactory,
std::unique_ptr<CartDiscountFetcherFactory> fetcher_factory,
std::unique_ptr<CartDiscountServiceDelegate> cart_discount_service_delegate,
signin::IdentityManager* const identity_manager,
variations::VariationsClient* const chrome_variations_client)
: … { … }
FetchDiscountWorker::~FetchDiscountWorker() = default;
void FetchDiscountWorker::Start(base::TimeDelta delay) { … }
void FetchDiscountWorker::PrepareToFetch() { … }
void FetchDiscountWorker::FetchOauthToken() { … }
void FetchDiscountWorker::OnAuthTokenFetched(
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info) { … }
void FetchDiscountWorker::LoadAllActiveCarts(
const bool is_oauth_fetch,
const std::string access_token_str) { … }
void FetchDiscountWorker::ReadyToFetch(
const bool is_oauth_fetch,
const std::string access_token_str,
bool success,
std::vector<CartDB::KeyAndValue> proto_pairs) { … }
std::string FetchDiscountWorker::GetVariationsHeaders() { … }
void FetchDiscountWorker::FetchInBackground(
std::unique_ptr<network::PendingSharedURLLoaderFactory> pending_factory,
std::unique_ptr<CartDiscountFetcher> fetcher,
AfterFetchingCallback after_fetching_callback,
std::vector<CartDB::KeyAndValue> proto_pairs,
const bool is_oauth_fetch,
const std::string access_token_str,
const std::string fetch_for_locale,
const std::string variation_headers) { … }
void FetchDiscountWorker::DoneFetchingInBackground(
AfterFetchingCallback after_fetching_callback,
CartDiscountFetcher::CartDiscountMap discounts,
bool is_tester) { … }
void FetchDiscountWorker::AfterDiscountFetched(
CartDiscountFetcher::CartDiscountMap discounts,
bool is_tester) { … }
void FetchDiscountWorker::OnUpdatingDiscounts(
CartDiscountFetcher::CartDiscountMap discounts,
bool is_tester,
bool success,
std::vector<CartDB::KeyAndValue> proto_pairs) { … }