#include "components/feed/core/v2/web_feed_subscription_coordinator.h"
#include <memory>
#include <optional>
#include <ostream>
#include "base/debug/stack_trace.h"
#include "base/feature_list.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "components/feed/core/common/pref_names.h"
#include "components/feed/core/proto/v2/store.pb.h"
#include "components/feed/core/proto/v2/wire/web_feeds.pb.h"
#include "components/feed/core/v2/config.h"
#include "components/feed/core/v2/feed_stream.h"
#include "components/feed/core/v2/feedstore_util.h"
#include "components/feed/core/v2/metrics_reporter.h"
#include "components/feed/core/v2/operation_token.h"
#include "components/feed/core/v2/public/feed_api.h"
#include "components/feed/core/v2/public/types.h"
#include "components/feed/core/v2/types.h"
#include "components/feed/core/v2/web_feed_subscriptions/fetch_subscribed_web_feeds_task.h"
#include "components/feed/core/v2/web_feed_subscriptions/subscribe_to_web_feed_task.h"
#include "components/feed/core/v2/web_feed_subscriptions/web_feed_metadata_model.h"
#include "components/feed/core/v2/web_feed_subscriptions/web_feed_subscription_model.h"
#include "components/feed/feed_feature_list.h"
#include "components/offline_pages/task/closure_task.h"
#include "components/prefs/pref_service.h"
namespace feed {
namespace {
WebFeedMetadata MakeWebFeedMetadata(
WebFeedSubscriptionStatus subscribe_status,
const feedstore::WebFeedInfo& web_feed_info) { … }
WebFeedMetadata MakeWebFeedMetadata(WebFeedSubscriptionStatus subscribe_status,
std::string web_feed_id = std::string()) { … }
bool IsTerminalStatus(WebFeedSubscriptionRequestStatus status) { … }
}
WebFeedSubscriptionCoordinator::HooksForTesting::HooksForTesting() = default;
WebFeedSubscriptionCoordinator::HooksForTesting::~HooksForTesting() = default;
WebFeedSubscriptionCoordinator::WebFeedSubscriptionCoordinator(
Delegate* delegate,
FeedStream* feed_stream)
: … { … }
bool WebFeedSubscriptionCoordinator::IsSignedInAndWebFeedsEnabled() const { … }
WebFeedSubscriptionCoordinator::~WebFeedSubscriptionCoordinator() = default;
void WebFeedSubscriptionCoordinator::Populate(
const FeedStore::WebFeedStartupData& startup_data) { … }
void WebFeedSubscriptionCoordinator::ClearAllFinished() { … }
void WebFeedSubscriptionCoordinator::FollowWebFeed(
const WebFeedPageInformation& page_info,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(FollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::FollowWebFeedFromUrlStart(
const WebFeedPageInformation& page_info,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(FollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::FollowWebFeed(
const std::string& web_feed_id,
bool is_durable_request,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(FollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::FollowWebFeedInternal(
const std::string& web_feed_id,
WebFeedInFlightChangeStrategy strategy,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(FollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::UpdatePendingOperationBeforeAttempt(
const std::string& web_feed_id,
WebFeedInFlightChangeStrategy strategy,
feedstore::PendingWebFeedOperation::Kind kind,
feedwire::webfeed::WebFeedChangeReason change_reason) { … }
void WebFeedSubscriptionCoordinator::FollowWebFeedFromIdStart(
const std::string& web_feed_id,
WebFeedInFlightChangeStrategy strategy,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(FollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::FollowWebFeedComplete(
base::OnceCallback<void(FollowWebFeedResult)> callback,
bool followed_with_id,
SubscribeToWebFeedTask::Result result) { … }
void WebFeedSubscriptionCoordinator::UnfollowWebFeed(
const std::string& web_feed_id,
bool is_durable_request,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(UnfollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::UnfollowWebFeedInternal(
const std::string& web_feed_id,
WebFeedInFlightChangeStrategy strategy,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(UnfollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::UnfollowWebFeedStart(
const std::string& web_feed_id,
WebFeedInFlightChangeStrategy strategy,
feedwire::webfeed::WebFeedChangeReason change_reason,
base::OnceCallback<void(UnfollowWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::UnfollowWebFeedComplete(
base::OnceCallback<void(UnfollowWebFeedResult)> callback,
UnsubscribeFromWebFeedTask::Result result) { … }
void WebFeedSubscriptionCoordinator::FindWebFeedInfoForPage(
const WebFeedPageInformation& page_info,
base::OnceCallback<void(WebFeedMetadata)> callback) { … }
void WebFeedSubscriptionCoordinator::FindWebFeedInfoForPageStart(
const WebFeedPageInformation& page_info,
base::OnceCallback<void(WebFeedMetadata)> callback) { … }
void WebFeedSubscriptionCoordinator::FindWebFeedInfoForWebFeedId(
const std::string& web_feed_id,
base::OnceCallback<void(WebFeedMetadata)> callback) { … }
void WebFeedSubscriptionCoordinator::FindWebFeedInfoForWebFeedIdStart(
const std::string& web_feed_id,
base::OnceCallback<void(WebFeedMetadata)> callback) { … }
WebFeedSubscriptionStatus
WebFeedSubscriptionCoordinator::GetWebFeedSubscriptionStatus(
const std::string& web_feed_id) const { … }
void WebFeedSubscriptionCoordinator::LookupWebFeedDataAndRespond(
const std::string& web_feed_id,
const WebFeedPageInformation* maybe_page_info,
base::OnceCallback<void(WebFeedMetadata)> callback) { … }
void WebFeedSubscriptionCoordinator::WithModel(base::OnceClosure closure) { … }
void WebFeedSubscriptionCoordinator::ReadWebFeedStartupDataTask() { … }
void WebFeedSubscriptionCoordinator::ModelDataLoaded(
FeedStore::WebFeedStartupData startup_data) { … }
void WebFeedSubscriptionCoordinator::EnqueueInFlightChange(
bool subscribing,
WebFeedInFlightChangeStrategy strategy,
feedwire::webfeed::WebFeedChangeReason change_reason,
std::optional<WebFeedPageInformation> page_information,
std::optional<feedstore::WebFeedInfo> info) { … }
WebFeedInFlightChange WebFeedSubscriptionCoordinator::DequeueInflightChange() { … }
const WebFeedInFlightChange* WebFeedSubscriptionCoordinator::FindInflightChange(
const std::string& web_feed_id,
const WebFeedPageInformation* maybe_page_info) const { … }
void WebFeedSubscriptionCoordinator::GetAllSubscriptions(
base::OnceCallback<void(std::vector<WebFeedMetadata>)> callback) { … }
void WebFeedSubscriptionCoordinator::GetAllSubscriptionsStart(
base::OnceCallback<void(std::vector<WebFeedMetadata>)> callback) { … }
void WebFeedSubscriptionCoordinator::RefreshSubscriptions(
base::OnceCallback<void(RefreshResult)> callback) { … }
WebFeedSubscriptionInfo WebFeedSubscriptionCoordinator::FindSubscriptionInfo(
const WebFeedPageInformation& page_info) { … }
WebFeedSubscriptionInfo
WebFeedSubscriptionCoordinator::FindSubscriptionInfoById(
const std::string& web_feed_id) { … }
void WebFeedSubscriptionCoordinator::RefreshRecommendedFeeds(
base::OnceCallback<void(RefreshResult)> callback) { … }
void WebFeedSubscriptionCoordinator::FetchRecommendedWebFeedsIfStale() { … }
void WebFeedSubscriptionCoordinator::FetchRecommendedWebFeedsStart() { … }
void WebFeedSubscriptionCoordinator::FetchRecommendedWebFeedsComplete(
FetchRecommendedWebFeedsTask::Result result) { … }
void WebFeedSubscriptionCoordinator::
CallRefreshRecommendedFeedsCompleteCallbacks(RefreshResult result) { … }
void WebFeedSubscriptionCoordinator::FetchSubscribedWebFeedsIfStale(
base::OnceClosure callback) { … }
void WebFeedSubscriptionCoordinator::FetchSubscribedWebFeedsStart() { … }
void WebFeedSubscriptionCoordinator::FetchSubscribedWebFeedsComplete(
FetchSubscribedWebFeedsTask::Result result) { … }
void WebFeedSubscriptionCoordinator::CallRefreshCompleteCallbacks(
RefreshResult result) { … }
void WebFeedSubscriptionCoordinator::IsWebFeedSubscriber(
base::OnceCallback<void(bool)> callback) { … }
void WebFeedSubscriptionCoordinator::SubscribedWebFeedCount(
base::OnceCallback<void(int)> callback) { … }
std::vector<std::pair<std::string, WebFeedSubscriptionStatus>>
WebFeedSubscriptionCoordinator::GetAllWebFeedSubscriptionStatus() const { … }
void WebFeedSubscriptionCoordinator::SubscriptionsChanged() { … }
void WebFeedSubscriptionCoordinator::DumpStateForDebugging(std::ostream& os) { … }
void WebFeedSubscriptionCoordinator::IsWebFeedSubscriberDone(
base::OnceCallback<void(bool)> callback) { … }
void WebFeedSubscriptionCoordinator::SubscribedWebFeedCountDone(
base::OnceCallback<void(int)> callback) { … }
void WebFeedSubscriptionCoordinator::RetryPendingOperations() { … }
std::string WebFeedSubscriptionCoordinator::DescribeStateForTesting() const { … }
std::vector<feedstore::PendingWebFeedOperation>
WebFeedSubscriptionCoordinator::GetPendingOperationStateForTesting() { … }
void WebFeedSubscriptionCoordinator::QueryWebFeed(
const GURL& url,
base::OnceCallback<void(QueryWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::QueryWebFeedId(
const std::string& id,
base::OnceCallback<void(QueryWebFeedResult)> callback) { … }
void WebFeedSubscriptionCoordinator::QueryWebFeedComplete(
base::OnceCallback<void(QueryWebFeedResult)> callback,
QueryWebFeedResult result) { … }
}