#include "components/offline_pages/core/model/offline_page_model_taskified.h"
#include <string>
#include <utility>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "components/offline_pages/core/archive_manager.h"
#include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/model/add_page_task.h"
#include "components/offline_pages/core/model/cleanup_visuals_task.h"
#include "components/offline_pages/core/model/delete_page_task.h"
#include "components/offline_pages/core/model/get_pages_task.h"
#include "components/offline_pages/core/model/get_visuals_task.h"
#include "components/offline_pages/core/model/mark_page_accessed_task.h"
#include "components/offline_pages/core/model/offline_page_model_utils.h"
#include "components/offline_pages/core/model/persistent_page_consistency_check_task.h"
#include "components/offline_pages/core/model/startup_maintenance_task.h"
#include "components/offline_pages/core/model/store_visuals_task.h"
#include "components/offline_pages/core/model/update_publish_id_task.h"
#include "components/offline_pages/core/model/visuals_availability_task.h"
#include "components/offline_pages/core/offline_clock.h"
#include "components/offline_pages/core/offline_page_archive_publisher.h"
#include "components/offline_pages/core/offline_page_client_policy.h"
#include "components/offline_pages/core/offline_page_metadata_store.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/offline_pages/core/offline_store_utils.h"
#include "url/gurl.h"
namespace offline_pages {
ArchiverResult;
ClearStorageResult;
namespace {
void WrapInMultipleItemsCallback(MultipleOfflineIdCallback callback,
const MultipleOfflinePageItemResult& pages) { … }
SavePageResult ArchiverResultToSavePageResult(ArchiverResult archiver_result) { … }
SavePageResult AddPageResultToSavePageResult(AddPageResult add_page_result) { … }
void ReportSavedPagesCount(MultipleOfflinePageItemCallback callback,
const MultipleOfflinePageItemResult& all_items) { … }
void OnUpdateFilePathDone(PublishPageCallback publish_done_callback,
const base::FilePath& new_file_path,
SavePageResult result,
bool update_file_result) { … }
}
constexpr base::TimeDelta OfflinePageModelTaskified::kMaintenanceTasksDelay;
constexpr base::TimeDelta OfflinePageModelTaskified::kClearStorageInterval;
OfflinePageModelTaskified::OfflinePageModelTaskified(
std::unique_ptr<OfflinePageMetadataStore> store,
std::unique_ptr<ArchiveManager> archive_manager,
std::unique_ptr<OfflinePageArchivePublisher> archive_publisher,
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: … { … }
OfflinePageModelTaskified::~OfflinePageModelTaskified() = default;
void OfflinePageModelTaskified::AddObserver(Observer* observer) { … }
void OfflinePageModelTaskified::RemoveObserver(Observer* observer) { … }
void OfflinePageModelTaskified::OnTaskQueueIsIdle() { … }
void OfflinePageModelTaskified::SavePage(
const SavePageParams& save_page_params,
std::unique_ptr<OfflinePageArchiver> archiver,
content::WebContents* web_contents,
SavePageCallback callback) { … }
void OfflinePageModelTaskified::AddPage(const OfflinePageItem& page,
AddPageCallback callback) { … }
void OfflinePageModelTaskified::MarkPageAccessed(int64_t offline_id) { … }
void OfflinePageModelTaskified::DeletePagesWithCriteria(
const PageCriteria& criteria,
DeletePageCallback callback) { … }
void OfflinePageModelTaskified::DeleteCachedPagesByURLPredicate(
const UrlPredicate& predicate,
DeletePageCallback callback) { … }
void OfflinePageModelTaskified::GetAllPages(
MultipleOfflinePageItemCallback callback) { … }
void OfflinePageModelTaskified::GetPageByOfflineId(
int64_t offline_id,
SingleOfflinePageItemCallback callback) { … }
void OfflinePageModelTaskified::GetPagesWithCriteria(
const PageCriteria& criteria,
MultipleOfflinePageItemCallback callback) { … }
void OfflinePageModelTaskified::GetOfflineIdsForClientId(
const ClientId& client_id,
MultipleOfflineIdCallback callback) { … }
void OfflinePageModelTaskified::StoreThumbnail(int64_t offline_id,
std::string thumbnail) { … }
void OfflinePageModelTaskified::StoreFavicon(int64_t offline_id,
std::string favicon) { … }
void OfflinePageModelTaskified::GetVisualsByOfflineId(
int64_t offline_id,
base::OnceCallback<void(std::unique_ptr<OfflinePageVisuals>)> callback) { … }
void OfflinePageModelTaskified::GetVisualsAvailability(
int64_t offline_id,
base::OnceCallback<void(VisualsAvailability)> callback) { … }
const base::FilePath& OfflinePageModelTaskified::GetArchiveDirectory(
const std::string& name_space) const { … }
bool OfflinePageModelTaskified::IsArchiveInInternalDir(
const base::FilePath& file_path) const { … }
OfflineEventLogger* OfflinePageModelTaskified::GetLogger() { … }
void OfflinePageModelTaskified::InformSavePageDone(SavePageCallback callback,
SavePageResult result,
const ClientId& client_id,
int64_t offline_id) { … }
void OfflinePageModelTaskified::OnCreateArchiveDone(
const SavePageParams& save_page_params,
int64_t offline_id,
base::Time start_time,
std::unique_ptr<OfflinePageArchiver> archiver,
SavePageCallback callback,
ArchiverResult archiver_result,
const GURL& saved_url,
const base::FilePath& file_path,
const std::u16string& title,
int64_t file_size,
const std::string& digest) { … }
void OfflinePageModelTaskified::PublishArchiveDone(
SavePageCallback callback,
base::Time publish_start_time,
const OfflinePageItem& offline_page,
PublishArchiveResult publish_results) { … }
void OfflinePageModelTaskified::PublishInternalArchive(
const OfflinePageItem& offline_page,
PublishPageCallback publish_done_callback) { … }
void OfflinePageModelTaskified::PublishInternalArchiveDone(
PublishPageCallback publish_done_callback,
const OfflinePageItem& offline_page,
PublishArchiveResult publish_results) { … }
void OfflinePageModelTaskified::OnAddPageForSavePageDone(
SavePageCallback callback,
const OfflinePageItem& page_attempted,
base::Time add_page_start_time,
AddPageResult add_page_result,
int64_t offline_id) { … }
void OfflinePageModelTaskified::OnAddPageDone(const OfflinePageItem& page,
AddPageCallback callback,
AddPageResult result) { … }
void OfflinePageModelTaskified::OnDeleteDone(
DeletePageCallback callback,
DeletePageResult result,
const std::vector<OfflinePageItem>& deleted_items) { … }
void OfflinePageModelTaskified::OnStoreThumbnailDone(int64_t offline_id,
bool success,
std::string thumbnail) { … }
void OfflinePageModelTaskified::OnStoreFaviconDone(int64_t offline_id,
bool success,
std::string favicon) { … }
void OfflinePageModelTaskified::Unpublish(
base::WeakPtr<OfflinePageArchivePublisher> publisher,
const std::vector<PublishedArchiveId>& publish_ids) { … }
void OfflinePageModelTaskified::ScheduleMaintenanceTasks() { … }
void OfflinePageModelTaskified::RunMaintenanceTasks(base::Time now,
bool first_run) { … }
void OfflinePageModelTaskified::OnPersistentPageConsistencyCheckDone(
bool success,
const std::vector<PublishedArchiveId>& ids_of_deleted_pages) { … }
void OfflinePageModelTaskified::RemovePagesMatchingUrlAndNamespace(
const OfflinePageItem& page) { … }
void OfflinePageModelTaskified::CreateArchivesDirectoryIfNeeded() { … }
}