chromium/components/offline_pages/core/background/request_coordinator.cc

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

#include "components/offline_pages/core/background/request_coordinator.h"

#include <limits>
#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/system/sys_info.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "components/offline_pages/core/background/offliner.h"
#include "components/offline_pages/core/background/offliner_client.h"
#include "components/offline_pages/core/background/offliner_policy.h"
#include "components/offline_pages/core/background/save_page_request.h"
#include "components/offline_pages/core/offline_clock.h"
#include "components/offline_pages/core/offline_page_client_policy.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/offline_page_item.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/offline_pages/core/offline_store_utils.h"
#include "services/network/public/cpp/network_quality_tracker.h"

namespace offline_pages {

namespace {
const bool kUserRequest =;
const bool kStartOfProcessing =;
const int kDisabledTaskRecheckSeconds =;

// Returns whether |result| is a successful result for a single request.
bool IsSingleSuccessResult(const UpdateRequestsResult& result) {}

FailState RequestStatusToFailState(Offliner::RequestStatus request_status) {}

// Returns true if |status| originates from the RequestCoordinator, as opposed
// to an |Offliner| result.
constexpr bool IsCanceledOrInternalFailure(Offliner::RequestStatus status) {}

// Returns the |BackgroundSavePageResult| appropriate for a single attempt
// status. Returns |std::nullopt| for indeterminate status values that can be
// retried.
std::optional<RequestNotifier::BackgroundSavePageResult> SingleAttemptResult(
    Offliner::RequestStatus status) {}

}  // namespace

RequestCoordinator::SavePageLaterParams::SavePageLaterParams()
    :{}

RequestCoordinator::SavePageLaterParams::SavePageLaterParams(
    const SavePageLaterParams& other) = default;

RequestCoordinator::SavePageLaterParams::~SavePageLaterParams() = default;

RequestCoordinator::RequestCoordinator(
    std::unique_ptr<OfflinerPolicy> policy,
    std::unique_ptr<Offliner> offliner,
    std::unique_ptr<RequestQueue> queue,
    std::unique_ptr<Scheduler> scheduler,
    network::NetworkQualityTracker* network_quality_tracker,
    std::unique_ptr<ActiveTabInfo> active_tab_info)
    :{}

RequestCoordinator::~RequestCoordinator() {}

int64_t RequestCoordinator::SavePageLater(
    const SavePageLaterParams& save_page_later_params,
    SavePageLaterCallback save_page_later_callback) {}

void RequestCoordinator::GetAllRequests(GetRequestsCallback callback) {}

void RequestCoordinator::SetAutoFetchNotificationState(
    int64_t request_id,
    SavePageRequest::AutoFetchNotificationState state,
    base::OnceCallback<void(bool updated)> callback) {}

void RequestCoordinator::GetQueuedRequestsCallback(
    GetRequestsCallback callback,
    GetRequestsResult result,
    std::vector<std::unique_ptr<SavePageRequest>> requests) {}

void RequestCoordinator::StopProcessing(Offliner::RequestStatus stop_status) {}

void RequestCoordinator::GetRequestsForSchedulingCallback(
    GetRequestsResult result,
    std::vector<std::unique_ptr<SavePageRequest>> requests) {}

bool RequestCoordinator::CancelActiveRequestIfItMatches(int64_t request_id) {}

void RequestCoordinator::UpdateRequestForAbortedAttempt(
    const SavePageRequest& request) {}

void RequestCoordinator::RemoveAttemptedRequest(
    const SavePageRequest& request,
    RequestNotifier::BackgroundSavePageResult result) {}

void RequestCoordinator::MarkAttemptAborted(int64_t request_id,
                                            const std::string& name_space) {}

void RequestCoordinator::MarkAttemptDone(int64_t request_id,
                                         const std::string& name_space,
                                         UpdateRequestsResult result) {}

void RequestCoordinator::RemoveRequests(const std::vector<int64_t>& request_ids,
                                        RemoveRequestsCallback callback) {}

void RequestCoordinator::RemoveRequestsIf(
    const base::RepeatingCallback<bool(const SavePageRequest&)>&
        remove_predicate,
    RemoveRequestsCallback callback) {}

void RequestCoordinator::PauseRequests(
    const std::vector<int64_t>& request_ids) {}

void RequestCoordinator::ResumeRequests(
    const std::vector<int64_t>& request_ids) {}

void RequestCoordinator::AddRequestResultCallback(
    SavePageLaterCallback save_page_later_callback,
    RequestAvailability availability,
    AddRequestResult result,
    const SavePageRequest& request) {}

void RequestCoordinator::UpdateMultipleRequestsCallback(
    UpdateRequestsResult result) {}

void RequestCoordinator::ReconcileCallback(UpdateRequestsResult result) {}

void RequestCoordinator::HandleRemovedRequestsAndCallback(
    RemoveRequestsCallback callback,
    RequestNotifier::BackgroundSavePageResult status,
    UpdateRequestsResult result) {}

void RequestCoordinator::HandleRemovedRequests(
    RequestNotifier::BackgroundSavePageResult status,
    UpdateRequestsResult result) {}

void RequestCoordinator::MarkDeferredAttemptCallback(
    UpdateRequestsResult result) {}

void RequestCoordinator::ScheduleAsNeeded() {}

void RequestCoordinator::CancelProcessing() {}

// Returns true if the caller should expect a callback, false otherwise. For
// instance, this would return false if a request is already in progress.
bool RequestCoordinator::StartScheduledProcessing(
    const DeviceConditions& device_conditions,
    const base::RepeatingCallback<void(bool)>& callback) {}

// Returns true if the caller should expect a callback, false otherwise.
bool RequestCoordinator::StartImmediateProcessing(
    const base::RepeatingCallback<void(bool)>& callback) {}

// The current_conditions_ must be set sometime before calling
// StartProcessingInternal on all calling code paths.
bool RequestCoordinator::StartProcessingInternal(
    const ProcessingWindowState processing_state,
    const base::RepeatingCallback<void(bool)>& callback) {}

void RequestCoordinator::StartImmediatelyIfConnected() {}

RequestCoordinator::OfflinerImmediateStartStatus
RequestCoordinator::TryImmediateStart(
    const base::RepeatingCallback<void(bool)>& callback) {}

void RequestCoordinator::RequestConnectedEventForStarting() {}

void RequestCoordinator::ClearConnectedEventRequest() {}

void RequestCoordinator::HandleConnectedEventForStarting() {}

void RequestCoordinator::UpdateCurrentConditionsFromAndroid() {}

void RequestCoordinator::TryNextRequest(bool is_start_of_processing) {}

// Called by the request picker when a request has been picked.
void RequestCoordinator::RequestPicked(
    const SavePageRequest& picked_request,
    std::unique_ptr<std::vector<SavePageRequest>> available_requests,
    bool cleanup_needed) {}

void RequestCoordinator::RequestNotPicked(
    bool non_user_requested_tasks_remaining,
    bool cleanup_needed,
    base::Time available_time) {}

void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) {}

void RequestCoordinator::StartOffliner(int64_t request_id,
                                       const std::string& client_namespace,
                                       UpdateRequestsResult update_result) {}

void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
                                              Offliner::RequestStatus status) {}

void RequestCoordinator::UpdateRequestForAttempt(
    const SavePageRequest& request,
    Offliner::RequestStatus status) {}

void RequestCoordinator::ScheduleOrTryNextRequest(
    Offliner::RequestStatus previous_status) {}

void RequestCoordinator::OfflinerProgressCallback(
    const SavePageRequest& request,
    int64_t received_bytes) {}

bool RequestCoordinator::ShouldTryNextRequest(
    Offliner::RequestStatus previous_request_status) const {}

void RequestCoordinator::EnableForOffliner(int64_t request_id,
                                           const ClientId& client_id) {}

void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {}

const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions(
    const bool user_requested) {}

void RequestCoordinator::AddObserver(Observer* observer) {}

void RequestCoordinator::RemoveObserver(Observer* observer) {}

void RequestCoordinator::NotifyAdded(const SavePageRequest& request) {}

void RequestCoordinator::NotifyCompleted(
    const SavePageRequest& request,
    RequestNotifier::BackgroundSavePageResult status) {}

void RequestCoordinator::NotifyChanged(const SavePageRequest& request) {}

void RequestCoordinator::NotifyNetworkProgress(const SavePageRequest& request,
                                               int64_t received_bytes) {}

void RequestCoordinator::RecordOfflinerResult(const SavePageRequest& request,
                                              Offliner::RequestStatus status) {}

void RequestCoordinator::Shutdown() {}

}  // namespace offline_pages