#include "components/services/storage/service_worker/service_worker_storage_control_impl.h"
#include "base/containers/contains.h"
#include "base/debug/alias.h"
#include "base/not_fatal_until.h"
#include "base/task/sequenced_task_runner.h"
#include "components/services/storage/service_worker/service_worker_resource_ops.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
namespace storage {
namespace {
void DidGetAllRegistrations(
ServiceWorkerStorageControlImpl::GetAllRegistrationsDeprecatedCallback
callback,
mojom::ServiceWorkerDatabaseStatus status,
std::unique_ptr<ServiceWorkerStorage::RegistrationList> registrations) { … }
}
class ServiceWorkerLiveVersionRefImpl
: public mojom::ServiceWorkerLiveVersionRef { … };
mojo::SelfOwnedReceiverRef<mojom::ServiceWorkerStorageControl>
ServiceWorkerStorageControlImpl::Create(
mojo::PendingReceiver<mojom::ServiceWorkerStorageControl> receiver,
const base::FilePath& user_data_directory,
scoped_refptr<base::SequencedTaskRunner> database_task_runner) { … }
ServiceWorkerStorageControlImpl::ServiceWorkerStorageControlImpl(
const base::FilePath& user_data_directory,
scoped_refptr<base::SequencedTaskRunner> database_task_runner)
: … { … }
ServiceWorkerStorageControlImpl::ServiceWorkerStorageControlImpl(
const base::FilePath& user_data_directory,
scoped_refptr<base::SequencedTaskRunner> database_task_runner,
mojo::PendingReceiver<mojom::ServiceWorkerStorageControl> receiver)
: … { … }
ServiceWorkerStorageControlImpl::~ServiceWorkerStorageControlImpl() = default;
void ServiceWorkerStorageControlImpl::OnNoLiveVersion(int64_t version_id) { … }
void ServiceWorkerStorageControlImpl::LazyInitializeForTest() { … }
void ServiceWorkerStorageControlImpl::Disable(DisableCallback callback) { … }
void ServiceWorkerStorageControlImpl::Delete(DeleteCallback callback) { … }
void ServiceWorkerStorageControlImpl::Recover(
std::vector<mojom::ServiceWorkerLiveVersionInfoPtr> versions,
RecoverCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetRegisteredStorageKeys(
GetRegisteredStorageKeysCallback callback) { … }
void ServiceWorkerStorageControlImpl::FindRegistrationForClientUrl(
const GURL& client_url,
const blink::StorageKey& key,
FindRegistrationForClientUrlCallback callback) { … }
void ServiceWorkerStorageControlImpl::FindRegistrationForScope(
const GURL& scope,
const blink::StorageKey& key,
FindRegistrationForScopeCallback callback) { … }
void ServiceWorkerStorageControlImpl::FindRegistrationForId(
int64_t registration_id,
const std::optional<blink::StorageKey>& key,
FindRegistrationForIdCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetRegistrationsForStorageKey(
const blink::StorageKey& key,
GetRegistrationsForStorageKeyCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUsageForStorageKey(
const blink::StorageKey& key,
GetUsageForStorageKeyCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetAllRegistrationsDeprecated(
GetAllRegistrationsDeprecatedCallback callback) { … }
void ServiceWorkerStorageControlImpl::StoreRegistration(
mojom::ServiceWorkerRegistrationDataPtr registration,
std::vector<mojom::ServiceWorkerResourceRecordPtr> resources,
StoreRegistrationCallback callback) { … }
void ServiceWorkerStorageControlImpl::DeleteRegistration(
int64_t registration_id,
const blink::StorageKey& key,
DeleteRegistrationCallback callback) { … }
void ServiceWorkerStorageControlImpl::UpdateToActiveState(
int64_t registration_id,
const blink::StorageKey& key,
UpdateToActiveStateCallback callback) { … }
void ServiceWorkerStorageControlImpl::UpdateLastUpdateCheckTime(
int64_t registration_id,
const blink::StorageKey& key,
base::Time last_update_check_time,
UpdateLastUpdateCheckTimeCallback callback) { … }
void ServiceWorkerStorageControlImpl::UpdateNavigationPreloadEnabled(
int64_t registration_id,
const blink::StorageKey& key,
bool enable,
UpdateNavigationPreloadEnabledCallback callback) { … }
void ServiceWorkerStorageControlImpl::UpdateNavigationPreloadHeader(
int64_t registration_id,
const blink::StorageKey& key,
const std::string& value,
UpdateNavigationPreloadHeaderCallback callback) { … }
void ServiceWorkerStorageControlImpl::UpdateFetchHandlerType(
int64_t registration_id,
const blink::StorageKey& key,
blink::mojom::ServiceWorkerFetchHandlerType type,
UpdateFetchHandlerTypeCallback callback) { … }
void ServiceWorkerStorageControlImpl::UpdateResourceSha256Checksums(
int64_t registration_id,
const blink::StorageKey& key,
const base::flat_map<int64_t, std::string>& updated_sha256_checksums,
UpdateResourceSha256ChecksumsCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetNewRegistrationId(
GetNewRegistrationIdCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetNewVersionId(
GetNewVersionIdCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetNewResourceId(
GetNewResourceIdCallback callback) { … }
void ServiceWorkerStorageControlImpl::CreateResourceReader(
int64_t resource_id,
mojo::PendingReceiver<mojom::ServiceWorkerResourceReader> reader) { … }
void ServiceWorkerStorageControlImpl::CreateResourceWriter(
int64_t resource_id,
mojo::PendingReceiver<mojom::ServiceWorkerResourceWriter> writer) { … }
void ServiceWorkerStorageControlImpl::CreateResourceMetadataWriter(
int64_t resource_id,
mojo::PendingReceiver<mojom::ServiceWorkerResourceMetadataWriter> writer) { … }
void ServiceWorkerStorageControlImpl::StoreUncommittedResourceId(
int64_t resource_id,
StoreUncommittedResourceIdCallback callback) { … }
void ServiceWorkerStorageControlImpl::DoomUncommittedResources(
const std::vector<int64_t>& resource_ids,
DoomUncommittedResourcesCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUserData(
int64_t registration_id,
const std::vector<std::string>& keys,
GetUserDataCallback callback) { … }
void ServiceWorkerStorageControlImpl::StoreUserData(
int64_t registration_id,
const blink::StorageKey& key,
std::vector<mojom::ServiceWorkerUserDataPtr> user_data,
StoreUserDataCallback callback) { … }
void ServiceWorkerStorageControlImpl::ClearUserData(
int64_t registration_id,
const std::vector<std::string>& keys,
ClearUserDataCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUserDataByKeyPrefix(
int64_t registration_id,
const std::string& key_prefix,
GetUserDataByKeyPrefixCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUserKeysAndDataByKeyPrefix(
int64_t registration_id,
const std::string& key_prefix,
GetUserKeysAndDataByKeyPrefixCallback callback) { … }
void ServiceWorkerStorageControlImpl::ClearUserDataByKeyPrefixes(
int64_t registration_id,
const std::vector<std::string>& key_prefixes,
ClearUserDataByKeyPrefixesCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUserDataForAllRegistrations(
const std::string& key,
GetUserDataForAllRegistrationsCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUserDataForAllRegistrationsByKeyPrefix(
const std::string& key_prefix,
GetUserDataForAllRegistrationsByKeyPrefixCallback callback) { … }
void ServiceWorkerStorageControlImpl::
ClearUserDataForAllRegistrationsByKeyPrefix(
const std::string& key_prefix,
ClearUserDataForAllRegistrationsByKeyPrefixCallback callback) { … }
void ServiceWorkerStorageControlImpl::PerformStorageCleanup(
PerformStorageCleanupCallback callback) { … }
void ServiceWorkerStorageControlImpl::ApplyPolicyUpdates(
const std::vector<mojom::StoragePolicyUpdatePtr> policy_updates,
ApplyPolicyUpdatesCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetPurgingResourceIdsForTest(
GetPurgeableResourceIdsForTestCallback callback) { … }
void ServiceWorkerStorageControlImpl::
GetPurgingResourceIdsForLiveVersionForTest(
int64_t version_id,
GetPurgeableResourceIdsForTestCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetPurgeableResourceIdsForTest(
GetPurgeableResourceIdsForTestCallback callback) { … }
void ServiceWorkerStorageControlImpl::GetUncommittedResourceIdsForTest(
GetPurgeableResourceIdsForTestCallback callback) { … }
void ServiceWorkerStorageControlImpl::SetPurgingCompleteCallbackForTest(
SetPurgingCompleteCallbackForTestCallback callback) { … }
void ServiceWorkerStorageControlImpl::DidFindRegistrationForClientUrl(
FindRegistrationForClientUrlCallback callback,
mojom::ServiceWorkerRegistrationDataPtr data,
std::unique_ptr<ResourceList> resources,
const std::optional<std::vector<GURL>>& scopes,
mojom::ServiceWorkerDatabaseStatus status) { … }
void ServiceWorkerStorageControlImpl::DidFindRegistration(
base::OnceCallback<void(mojom::ServiceWorkerDatabaseStatus status,
mojom::ServiceWorkerFindRegistrationResultPtr)>
callback,
mojom::ServiceWorkerRegistrationDataPtr data,
std::unique_ptr<ResourceList> resources,
mojom::ServiceWorkerDatabaseStatus status) { … }
void ServiceWorkerStorageControlImpl::DidGetRegistrationsForStorageKey(
GetRegistrationsForStorageKeyCallback callback,
mojom::ServiceWorkerDatabaseStatus status,
std::unique_ptr<ServiceWorkerStorage::RegistrationList>
registration_data_list,
std::unique_ptr<std::vector<ResourceList>> resources_list) { … }
void ServiceWorkerStorageControlImpl::DidStoreRegistration(
StoreRegistrationCallback callback,
int64_t stored_version_id,
mojom::ServiceWorkerDatabaseStatus status,
int64_t deleted_version_id,
uint64_t deleted_resources_size,
const std::vector<int64_t>& newly_purgeable_resources) { … }
void ServiceWorkerStorageControlImpl::DidDeleteRegistration(
DeleteRegistrationCallback callback,
mojom::ServiceWorkerDatabaseStatus status,
ServiceWorkerStorage::StorageKeyState storage_key_state,
int64_t deleted_version_id,
uint64_t deleted_resources_size,
const std::vector<int64_t>& newly_purgeable_resources) { … }
void ServiceWorkerStorageControlImpl::DidGetNewVersionId(
GetNewVersionIdCallback callback,
int64_t version_id) { … }
mojo::PendingRemote<mojom::ServiceWorkerLiveVersionRef>
ServiceWorkerStorageControlImpl::CreateLiveVersionReferenceRemote(
int64_t version_id) { … }
void ServiceWorkerStorageControlImpl::MaybePurgeResources(
int64_t version_id,
const std::vector<int64_t>& purgeable_resources) { … }
void ServiceWorkerStorageControlImpl::MaybeCancelPurgeResources(
int64_t version_id) { … }
}