#include "components/commerce/core/subscriptions/subscriptions_manager.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/subscriptions/commerce_subscription.h"
#include "components/commerce/core/subscriptions/subscriptions_observer.h"
#include "components/commerce/core/subscriptions/subscriptions_server_proxy.h"
#include "components/commerce/core/subscriptions/subscriptions_storage.h"
#include "components/session_proto_db/session_proto_storage.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include <queue>
#include <string>
namespace commerce {
namespace {
const int kDefaultTimeoutMs = …;
const char kTimeoutParam[] = …;
constexpr base::FeatureParam<int> kTimeoutMs{ … };
}
const char kTrackResultHistogramName[] = …;
const char kUntrackResultHistogramName[] = …;
SubscriptionsManager::SubscriptionsManager(
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
SessionProtoStorage<
commerce_subscription_db::CommerceSubscriptionContentProto>*
subscription_proto_db,
AccountChecker* account_checker)
: … { … }
SubscriptionsManager::SubscriptionsManager(
signin::IdentityManager* identity_manager,
std::unique_ptr<SubscriptionsServerProxy> server_proxy,
std::unique_ptr<SubscriptionsStorage> storage,
AccountChecker* account_checker)
: … { … }
SubscriptionsManager::SubscriptionsManager() = default;
SubscriptionsManager::~SubscriptionsManager() = default;
SubscriptionsManager::Request::Request(AsyncOperation operation,
base::OnceCallback<void()> callback)
: … { … }
SubscriptionsManager::Request::Request(Request&&) = default;
SubscriptionsManager::Request::~Request() = default;
void SubscriptionsManager::Subscribe(
std::unique_ptr<std::vector<CommerceSubscription>> subscriptions,
base::OnceCallback<void(bool)> callback) { … }
void SubscriptionsManager::Unsubscribe(
std::unique_ptr<std::vector<CommerceSubscription>> subscriptions,
base::OnceCallback<void(bool)> callback) { … }
void SubscriptionsManager::SyncSubscriptions() { … }
void SubscriptionsManager::IsSubscribed(
CommerceSubscription subscription,
base::OnceCallback<void(bool)> callback) { … }
bool SubscriptionsManager::IsSubscribedFromCache(
const CommerceSubscription& subscription) { … }
void SubscriptionsManager::GetAllSubscriptions(
SubscriptionType type,
base::OnceCallback<void(std::vector<CommerceSubscription>)> callback) { … }
void SubscriptionsManager::CheckTimestampOnBookmarkChange(
int64_t bookmark_subscription_change_time) { … }
void SubscriptionsManager::CheckAndProcessRequest() { … }
void SubscriptionsManager::SyncIfNeeded() { … }
void SubscriptionsManager::OnRequestCompletion() { … }
void SubscriptionsManager::UpdateSyncStates(bool sync_succeeded) { … }
void SubscriptionsManager::HandleSync() { … }
void SubscriptionsManager::OnSyncStatusFetched(
SubscriptionsRequestStatus result) { … }
void SubscriptionsManager::HandleSubscribe(
std::unique_ptr<std::vector<CommerceSubscription>> subscriptions,
base::OnceCallback<void(bool)> callback) { … }
void SubscriptionsManager::OnSubscribeStatusFetched(
std::vector<CommerceSubscription> notified_subscriptions,
base::OnceCallback<void(bool)> callback,
SubscriptionsRequestStatus result) { … }
void SubscriptionsManager::OnIncomingSubscriptionsFilteredForSubscribe(
SubscriptionType type,
SubscriptionsRequestCallback callback,
std::unique_ptr<std::vector<CommerceSubscription>> unique_subscriptions) { … }
void SubscriptionsManager::HandleUnsubscribe(
std::unique_ptr<std::vector<CommerceSubscription>> subscriptions,
base::OnceCallback<void(bool)> callback) { … }
void SubscriptionsManager::OnUnsubscribeStatusFetched(
std::vector<CommerceSubscription> notified_subscriptions,
base::OnceCallback<void(bool)> callback,
SubscriptionsRequestStatus result) { … }
void SubscriptionsManager::OnIncomingSubscriptionsFilteredForUnsubscribe(
SubscriptionType type,
SubscriptionsRequestCallback callback,
std::unique_ptr<std::vector<CommerceSubscription>> unique_subscriptions) { … }
void SubscriptionsManager::GetRemoteSubscriptionsAndUpdateStorage(
SubscriptionType type,
SubscriptionsRequestCallback callback) { … }
void SubscriptionsManager::HandleGetSubscriptionsResponse(
SubscriptionType type,
SubscriptionsRequestCallback callback,
SubscriptionsRequestStatus status,
std::unique_ptr<std::vector<CommerceSubscription>> remote_subscriptions) { … }
void SubscriptionsManager::HandleManageSubscriptionsResponse(
SubscriptionType type,
SubscriptionsRequestCallback callback,
SubscriptionsRequestStatus status,
std::unique_ptr<std::vector<CommerceSubscription>> remote_subscriptions) { … }
void SubscriptionsManager::HandleLookup(
CommerceSubscription subscription,
base::OnceCallback<void(bool)> callback) { … }
void SubscriptionsManager::OnLookupResult(
base::OnceCallback<void(bool)> callback,
bool is_subscribed) { … }
void SubscriptionsManager::HandleGetAll(
SubscriptionType type,
base::OnceCallback<void(std::vector<CommerceSubscription>)> callback) { … }
void SubscriptionsManager::OnGetAllResult(
base::OnceCallback<void(std::vector<CommerceSubscription>)> callback,
std::unique_ptr<std::vector<CommerceSubscription>> subscriptions) { … }
void SubscriptionsManager::HandleCheckTimestampOnBookmarkChange(
int64_t bookmark_subscription_change_time) { … }
void SubscriptionsManager::HandleGetSubscriptionsResponseOnBookmarkChange(
SubscriptionsRequestStatus status,
std::unique_ptr<std::vector<CommerceSubscription>> remote_subscriptions) { … }
void SubscriptionsManager::OnStorageUpdatedOnBookmarkChange(
SubscriptionsRequestStatus status,
std::vector<CommerceSubscription> added_subs,
std::vector<CommerceSubscription> removed_subs) { … }
void SubscriptionsManager::OnSubscribe(
const std::vector<CommerceSubscription>& subscriptions,
bool succeeded) { … }
void SubscriptionsManager::OnUnsubscribe(
const std::vector<CommerceSubscription>& subscriptions,
bool succeeded) { … }
void SubscriptionsManager::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event_details) { … }
bool SubscriptionsManager::HasRequestRunning() { … }
void SubscriptionsManager::AddObserver(SubscriptionsObserver* observer) { … }
void SubscriptionsManager::RemoveObserver(SubscriptionsObserver* observer) { … }
bool SubscriptionsManager::GetLastSyncSucceededForTesting() { … }
int64_t SubscriptionsManager::GetLastSyncTimeForTesting() { … }
void SubscriptionsManager::SetHasRequestRunningForTesting(
bool has_request_running) { … }
bool SubscriptionsManager::HasPendingRequestsForTesting() { … }
void SubscriptionsManager::SetLastRequestStartedTimeForTesting(
base::Time time) { … }
}