1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_cache_quota_client.h"
7 #include "content/browser/service_worker/service_worker_cache_storage_manager.h"
8 #include "content/public/browser/browser_thread.h"
12 ServiceWorkerCacheQuotaClient::ServiceWorkerCacheQuotaClient(
13 base::WeakPtr
<ServiceWorkerCacheStorageManager
> cache_manager
)
14 : cache_manager_(cache_manager
) {
17 ServiceWorkerCacheQuotaClient::~ServiceWorkerCacheQuotaClient() {
20 storage::QuotaClient::ID
ServiceWorkerCacheQuotaClient::id() const {
21 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
22 return kServiceWorkerCache
;
25 void ServiceWorkerCacheQuotaClient::OnQuotaManagerDestroyed() {
26 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
30 void ServiceWorkerCacheQuotaClient::GetOriginUsage(
31 const GURL
& origin_url
,
32 storage::StorageType type
,
33 const GetUsageCallback
& callback
) {
34 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
36 if (!cache_manager_
|| !DoesSupport(type
)) {
41 cache_manager_
->GetOriginUsage(origin_url
, callback
);
44 void ServiceWorkerCacheQuotaClient::GetOriginsForType(
45 storage::StorageType type
,
46 const GetOriginsCallback
& callback
) {
47 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
49 if (!cache_manager_
|| !DoesSupport(type
)) {
50 callback
.Run(std::set
<GURL
>());
54 cache_manager_
->GetOrigins(callback
);
57 void ServiceWorkerCacheQuotaClient::GetOriginsForHost(
58 storage::StorageType type
,
59 const std::string
& host
,
60 const GetOriginsCallback
& callback
) {
61 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
63 if (!cache_manager_
|| !DoesSupport(type
)) {
64 callback
.Run(std::set
<GURL
>());
68 cache_manager_
->GetOriginsForHost(host
, callback
);
71 void ServiceWorkerCacheQuotaClient::DeleteOriginData(
73 storage::StorageType type
,
74 const DeletionCallback
& callback
) {
75 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
77 if (!cache_manager_
) {
78 callback
.Run(storage::kQuotaErrorAbort
);
82 if (!DoesSupport(type
)) {
83 callback
.Run(storage::kQuotaStatusOk
);
87 cache_manager_
->DeleteOriginData(origin
, callback
);
90 bool ServiceWorkerCacheQuotaClient::DoesSupport(
91 storage::StorageType type
) const {
92 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
94 return type
== storage::kStorageTypeTemporary
;
97 } // namespace content