Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / cache_storage / cache_storage_quota_client.cc
blob9d6ceca4d613301a6df11dc03c91522229277bfb
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"
10 namespace content {
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);
27 delete this;
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)) {
36 callback.Run(0);
37 return;
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>());
50 return;
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>());
64 return;
67 cache_manager_->GetOriginsForHost(host, callback);
70 void CacheStorageQuotaClient::DeleteOriginData(
71 const GURL& origin,
72 storage::StorageType type,
73 const DeletionCallback& callback) {
74 DCHECK_CURRENTLY_ON(BrowserThread::IO);
76 if (!cache_manager_) {
77 callback.Run(storage::kQuotaErrorAbort);
78 return;
81 if (!DoesSupport(type)) {
82 callback.Run(storage::kQuotaStatusOk);
83 return;
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