OLD | NEW |
---|---|
(Empty) | |
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. | |
4 #include "content/browser/service_worker/service_worker_quota_client.h" | |
5 | |
6 #include "base/bind.h" | |
7 #include "content/browser/service_worker/service_worker_context_wrapper.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 | |
10 using storage::QuotaClient; | |
11 | |
12 namespace content { | |
13 namespace { | |
14 void ReportOrigins(const QuotaClient::GetOriginsCallback& callback, | |
15 bool restrict_on_host, | |
16 const std::string host, | |
17 const std::vector<ServiceWorkerUsageInfo>& usage_info) { | |
18 std::set<GURL> origins; | |
19 for (const ServiceWorkerUsageInfo& info : usage_info) { | |
20 if (restrict_on_host && info.origin.host() != host) { | |
21 continue; | |
22 } | |
23 origins.insert(info.origin); | |
24 } | |
25 callback.Run(origins); | |
26 } | |
27 | |
28 void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback, | |
29 bool status) { | |
30 callback.Run(status ? storage::QuotaStatusCode::kQuotaStatusOk | |
31 : storage::QuotaStatusCode::kQuotaStatusUnknown); | |
32 } | |
33 } // namespace | |
34 | |
35 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( | |
36 ServiceWorkerContextWrapper* context) | |
37 : context_(context) { | |
38 } | |
39 | |
40 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() { | |
41 } | |
42 | |
43 QuotaClient::ID ServiceWorkerQuotaClient::id() const { | |
44 return QuotaClient::kServiceWorker; | |
45 } | |
46 | |
47 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { | |
48 delete this; | |
49 } | |
50 | |
51 void ServiceWorkerQuotaClient::GetOriginUsage( | |
52 const GURL& origin, | |
53 storage::StorageType type, | |
54 const GetUsageCallback& callback) { | |
55 // TODO(dmurph): Add usage fetching when information is available. | |
56 callback.Run(0); | |
57 } | |
58 | |
59 void ServiceWorkerQuotaClient::GetOriginsForType( | |
60 storage::StorageType type, | |
61 const GetOriginsCallback& callback) { | |
62 if (type != storage::StorageType::kStorageTypeTemporary || | |
63 !context_->IsAlive()) { | |
michaeln
2014/10/20 20:08:22
Wdyt about putting this test into wrapper class di
dmurph
2014/10/20 21:34:18
I'm good with that.
| |
64 callback.Run(std::set<GURL>()); | |
65 return; | |
66 } | |
67 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); | |
68 } | |
69 | |
70 void ServiceWorkerQuotaClient::GetOriginsForHost( | |
71 storage::StorageType type, | |
72 const std::string& host, | |
73 const GetOriginsCallback& callback) { | |
74 if (type != storage::StorageType::kStorageTypeTemporary || | |
75 !context_->IsAlive()) { | |
76 callback.Run(std::set<GURL>()); | |
77 return; | |
78 } | |
79 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, true, host)); | |
80 } | |
81 | |
82 void ServiceWorkerQuotaClient::DeleteOriginData( | |
83 const GURL& origin, | |
84 storage::StorageType type, | |
85 const DeletionCallback& callback) { | |
86 if (type != storage::StorageType::kStorageTypeTemporary) { | |
87 callback.Run(storage::QuotaStatusCode::kQuotaStatusOk); | |
88 return; | |
89 } | |
90 if (!context_->IsAlive()) { | |
91 callback.Run(storage::QuotaStatusCode::kQuotaStatusUnknown); | |
92 return; | |
93 } | |
94 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); | |
95 } | |
96 | |
97 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { | |
98 return type == storage::StorageType::kStorageTypeTemporary; | |
99 } | |
100 | |
101 } // namespace content | |
OLD | NEW |