Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "content/browser/service_worker/service_worker_quota_client.h" | |
|
jsbell
2014/10/08 19:26:41
Needs copyright header
dmurph
2014/10/11 00:02:26
Done.
| |
| 2 | |
| 3 #include "base/bind.h" | |
| 4 #include "content/browser/service_worker/service_worker_context_wrapper.h" | |
| 5 #include "content/public/browser/browser_thread.h" | |
| 6 | |
| 7 using storage::QuotaClient; | |
| 8 | |
| 9 namespace content { | |
|
jsbell
2014/10/08 19:26:41
nit: blanks inside namespace {} (I think)
dmurph
2014/10/11 00:02:26
clang format left it alone
| |
| 10 namespace { | |
| 11 void ReportOrigins(const QuotaClient::GetOriginsCallback& callback, | |
| 12 bool restrict_on_host, const std::string host, | |
| 13 const std::vector<ServiceWorkerUsageInfo>& usage_info) { | |
| 14 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 15 std::set<GURL> origins; | |
| 16 for (const ServiceWorkerUsageInfo& info : usage_info) { | |
| 17 if (restrict_on_host && info.origin.host() != host) { | |
|
jsbell
2014/10/08 19:26:41
nit: don't need braces here
dmurph
2014/10/11 00:02:26
I would like to keep them
| |
| 18 continue; | |
| 19 } | |
| 20 origins.insert(info.origin); | |
| 21 } | |
| 22 callback.Run(origins); | |
| 23 } | |
| 24 | |
| 25 void ReportUsage(const QuotaClient::GetUsageCallback& callback, | |
| 26 const GURL& origin, | |
| 27 const std::vector<ServiceWorkerUsageInfo>& usage_info) { | |
| 28 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 29 int serviceworkers = 0; | |
| 30 DLOG(ERROR) << "Getting origin " << origin.spec(); | |
|
michaeln
2014/10/08 23:09:15
This and other in here aren't really error logging
dmurph
2014/10/11 00:02:26
Done.
| |
| 31 for (const ServiceWorkerUsageInfo& info : usage_info) { | |
| 32 DLOG(ERROR) << "Considering origin " << info.origin.spec(); | |
| 33 if (info.origin == origin) { | |
|
jsbell
2014/10/08 19:26:41
nit: don't need braces here
dmurph
2014/10/11 00:02:26
I would like to keep
| |
| 34 serviceworkers++; | |
| 35 } | |
| 36 } | |
| 37 // FIXME: Expose real usage numbers; | |
|
jsbell
2014/10/08 19:26:41
Chromium style is: TODO(dmurph): ...
Can you docu
dmurph
2014/10/11 00:02:26
Done.
| |
| 38 callback.Run(serviceworkers); | |
|
michaeln
2014/10/08 23:09:15
Be careful with reporting bogus values to the quot
dmurph
2014/10/11 00:02:26
Cool, I changed this to always report 0, so having
| |
| 39 } | |
| 40 | |
| 41 void ReportToQuotaStatus(const QuotaClient::DeletionCallback& callback, | |
| 42 bool status) { | |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 44 callback.Run(status ? storage::QuotaStatusCode::kQuotaStatusOk | |
| 45 : storage::QuotaStatusCode::kQuotaStatusUnknown); | |
| 46 } | |
| 47 } // namespace | |
| 48 | |
| 49 ServiceWorkerQuotaClient::ServiceWorkerQuotaClient( | |
| 50 ServiceWorkerContextWrapper* context) | |
| 51 : context_(context) {} | |
| 52 | |
| 53 ServiceWorkerQuotaClient::~ServiceWorkerQuotaClient() {} | |
| 54 | |
| 55 QuotaClient::ID ServiceWorkerQuotaClient::id() const { | |
| 56 return QuotaClient::kServiceWorker; | |
| 57 } | |
| 58 | |
| 59 void ServiceWorkerQuotaClient::OnQuotaManagerDestroyed() { | |
| 60 delete this; | |
| 61 } | |
| 62 | |
| 63 void ServiceWorkerQuotaClient::GetOriginUsage( | |
| 64 const GURL& origin, storage::StorageType type, | |
| 65 const GetUsageCallback& callback) { | |
| 66 DLOG(ERROR) << "Usage called for type " << type << " and origin " << origin; | |
| 67 if (type != storage::StorageType::kStorageTypePersistent) { | |
|
jsbell
2014/10/08 19:26:41
My bad: should be kStorageTypeTemporary (here and
dmurph
2014/10/11 00:02:26
Done.
| |
| 68 callback.Run(0); | |
| 69 return; | |
| 70 } | |
| 71 context_->GetAllOriginsInfo(base::Bind(&ReportUsage, callback, origin)); | |
|
michaeln
2014/10/08 23:09:15
Might be nice to have a more focused getter for a
dmurph
2014/10/11 00:02:26
Isn't that what this does?
| |
| 72 } | |
| 73 | |
| 74 void ServiceWorkerQuotaClient::GetOriginsForType( | |
| 75 storage::StorageType type, const GetOriginsCallback& callback) { | |
| 76 DLOG(ERROR) << "origins for type called with storage type " << type; | |
| 77 if (type != storage::StorageType::kStorageTypePersistent) { | |
| 78 callback.Run(std::set<GURL>()); | |
| 79 return; | |
| 80 } | |
| 81 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, false, "")); | |
| 82 } | |
| 83 | |
| 84 void ServiceWorkerQuotaClient::GetOriginsForHost( | |
| 85 storage::StorageType type, const std::string& host, | |
| 86 const GetOriginsCallback& callback) { | |
| 87 DLOG(ERROR) << "Origins for host " << type << " and host " << host; | |
| 88 if (type != storage::StorageType::kStorageTypePersistent) { | |
| 89 callback.Run(std::set<GURL>()); | |
| 90 return; | |
| 91 } | |
| 92 context_->GetAllOriginsInfo(base::Bind(&ReportOrigins, callback, true, host)); | |
| 93 } | |
| 94 | |
| 95 void ServiceWorkerQuotaClient::DeleteOriginData( | |
| 96 const GURL& origin, storage::StorageType type, | |
| 97 const DeletionCallback& callback) { | |
| 98 DLOG(ERROR) << "!!! Delete called for type " << type << " and origin " | |
| 99 << origin; | |
| 100 if (type != storage::StorageType::kStorageTypePersistent) { | |
| 101 callback.Run(storage::QuotaStatusCode::kQuotaStatusOk); | |
| 102 return; | |
| 103 } | |
| 104 context_->DeleteForOrigin(origin, base::Bind(&ReportToQuotaStatus, callback)); | |
| 105 } | |
| 106 | |
| 107 bool ServiceWorkerQuotaClient::DoesSupport(storage::StorageType type) const { | |
| 108 return type == storage::StorageType::kStorageTypePersistent; | |
| 109 } | |
| 110 | |
| 111 | |
|
jsbell
2014/10/08 19:26:41
nit: remove extra blank line
dmurph
2014/10/11 00:02:26
Done.
| |
| 112 } // namespace content | |
| OLD | NEW |