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/cache_storage/cache_storage_quota_client.h"
7 #include "content/browser/cache_storage/cache_storage_manager.h"
8 #include "content/public/browser/browser_thread.h"
12 CacheStorageQuotaClient::CacheStorageQuotaClient(
13 base::WeakPtr
<CacheStorageManager
> cache_manager
)
14 : cache_manager_(cache_manager
) {
17 CacheStorageQuotaClient::~CacheStorageQuotaClient() {
20 storage::QuotaClient::ID
CacheStorageQuotaClient::id() const {
21 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
22 return kServiceWorkerCache
;
25 void CacheStorageQuotaClient::OnQuotaManagerDestroyed() {
29 void CacheStorageQuotaClient::GetOriginUsage(const GURL
& origin_url
,
30 storage::StorageType type
,
31 const GetUsageCallback
& callback
) {
32 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
34 if (!cache_manager_
|| !DoesSupport(type
)) {
39 cache_manager_
->GetOriginUsage(origin_url
, callback
);
42 void CacheStorageQuotaClient::GetOriginsForType(
43 storage::StorageType type
,
44 const GetOriginsCallback
& callback
) {
45 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
47 if (!cache_manager_
|| !DoesSupport(type
)) {
48 callback
.Run(std::set
<GURL
>());
52 cache_manager_
->GetOrigins(callback
);
55 void CacheStorageQuotaClient::GetOriginsForHost(
56 storage::StorageType type
,
57 const std::string
& host
,
58 const GetOriginsCallback
& callback
) {
59 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
61 if (!cache_manager_
|| !DoesSupport(type
)) {
62 callback
.Run(std::set
<GURL
>());
66 cache_manager_
->GetOriginsForHost(host
, callback
);
69 void CacheStorageQuotaClient::DeleteOriginData(
71 storage::StorageType type
,
72 const DeletionCallback
& callback
) {
73 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
75 if (!cache_manager_
) {
76 callback
.Run(storage::kQuotaErrorAbort
);
80 if (!DoesSupport(type
)) {
81 callback
.Run(storage::kQuotaStatusOk
);
85 cache_manager_
->DeleteOriginData(origin
, callback
);
88 bool CacheStorageQuotaClient::DoesSupport(storage::StorageType type
) const {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
91 return type
== storage::kStorageTypeTemporary
;
94 } // namespace content