Commit af2007f1 authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

Service Workers: Add a sequence checker to ServiceWorkerQuotaClient.

Change-Id: Ie8b1bf20fe9994693d4fefd75aed5d68b9a889cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610050Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840087}
parent 88d0868e
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/bind.h"
#include "base/sequence_checker.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_usage_info.h"
......@@ -36,14 +37,18 @@ void FindUsageForOrigin(QuotaClient::GetOriginUsageCallback callback,
ServiceWorkerQuotaClient::ServiceWorkerQuotaClient(
ServiceWorkerContextWrapper* context)
: context_(context) {
DCHECK(context);
DETACH_FROM_SEQUENCE(sequence_checker_);
}
ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void ServiceWorkerQuotaClient::GetOriginUsage(const url::Origin& origin,
StorageType type,
GetOriginUsageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->GetStorageUsageForOrigin(
origin, base::BindOnce(&FindUsageForOrigin, std::move(callback)));
......@@ -52,6 +57,7 @@ void ServiceWorkerQuotaClient::GetOriginUsage(const url::Origin& origin,
void ServiceWorkerQuotaClient::GetOriginsForType(
StorageType type,
GetOriginsForTypeCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->GetInstalledRegistrationOrigins(base::nullopt, std::move(callback));
}
......@@ -60,6 +66,7 @@ void ServiceWorkerQuotaClient::GetOriginsForHost(
StorageType type,
const std::string& host,
GetOriginsForHostCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->GetInstalledRegistrationOrigins(host, std::move(callback));
}
......@@ -68,6 +75,7 @@ void ServiceWorkerQuotaClient::DeleteOriginData(
const url::Origin& origin,
StorageType type,
DeleteOriginDataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->DeleteForOrigin(
origin, base::BindOnce(&ReportToQuotaStatus, std::move(callback)));
......@@ -76,6 +84,7 @@ void ServiceWorkerQuotaClient::DeleteOriginData(
void ServiceWorkerQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->PerformStorageCleanup(std::move(callback));
}
......
......@@ -8,6 +8,8 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "base/thread_annotations.h"
#include "content/common/content_export.h"
#include "storage/browser/quota/quota_client.h"
#include "storage/browser/quota/quota_client_type.h"
......@@ -25,6 +27,9 @@ class ServiceWorkerQuotaClient : public storage::QuotaClient {
CONTENT_EXPORT explicit ServiceWorkerQuotaClient(
ServiceWorkerContextWrapper* context);
ServiceWorkerQuotaClient(const ServiceWorkerQuotaClient&) = delete;
ServiceWorkerQuotaClient& operator=(const ServiceWorkerQuotaClient&) = delete;
// QuotaClient method overrides
void OnQuotaManagerDestroyed() override {}
void GetOriginUsage(const url::Origin& origin,
......@@ -41,18 +46,16 @@ class ServiceWorkerQuotaClient : public storage::QuotaClient {
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
static constexpr storage::QuotaClientType kType =
storage::QuotaClientType::kServiceWorker;
private:
friend class ServiceWorkerContextWrapper;
friend class ServiceWorkerQuotaClientTest;
~ServiceWorkerQuotaClient() override;
scoped_refptr<ServiceWorkerContextWrapper> context_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerQuotaClient);
scoped_refptr<ServiceWorkerContextWrapper> context_
GUARDED_BY_CONTEXT(sequence_checker_);
};
} // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment