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() {
26 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
30 void CacheStorageQuotaClient::GetOriginUsage(const GURL
& origin_url
,
31 storage::StorageType type
,
32 const GetUsageCallback
& callback
) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
35 if (!cache_manager_
|| !DoesSupport(type
)) {
40 cache_manager_
->GetOriginUsage(origin_url
, callback
);
43 void CacheStorageQuotaClient::GetOriginsForType(
44 storage::StorageType type
,
45 const GetOriginsCallback
& callback
) {
46 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
48 if (!cache_manager_
|| !DoesSupport(type
)) {
49 callback
.Run(std::set
<GURL
>());
53 cache_manager_
->GetOrigins(callback
);
56 void CacheStorageQuotaClient::GetOriginsForHost(
57 storage::StorageType type
,
58 const std::string
& host
,
59 const GetOriginsCallback
& callback
) {
60 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
62 if (!cache_manager_
|| !DoesSupport(type
)) {
63 callback
.Run(std::set
<GURL
>());
67 cache_manager_
->GetOriginsForHost(host
, callback
);
70 void CacheStorageQuotaClient::DeleteOriginData(
72 storage::StorageType type
,
73 const DeletionCallback
& callback
) {
74 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
76 if (!cache_manager_
) {
77 callback
.Run(storage::kQuotaErrorAbort
);
81 if (!DoesSupport(type
)) {
82 callback
.Run(storage::kQuotaStatusOk
);
86 cache_manager_
->DeleteOriginData(origin
, callback
);
89 bool CacheStorageQuotaClient::DoesSupport(storage::StorageType type
) const {
90 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
92 return type
== storage::kStorageTypeTemporary
;
95 } // namespace content