summaryrefslogtreecommitdiffstats
path: root/webkit/browser/appcache/appcache_quota_client.cc
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-05 09:36:55 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-05 09:36:55 +0000
commitd5b2fdf360715ef8024b013af9825cee132843c2 (patch)
tree491fa0bd0ca326481a358565c59876f3e2d50e4a /webkit/browser/appcache/appcache_quota_client.cc
parent439dce0e361ea60656fa91eeb84d50b19a405027 (diff)
downloadchromium_src-d5b2fdf360715ef8024b013af9825cee132843c2.zip
chromium_src-d5b2fdf360715ef8024b013af9825cee132843c2.tar.gz
chromium_src-d5b2fdf360715ef8024b013af9825cee132843c2.tar.bz2
Move webkit/appcache/* into webkit/{browser,common}/appcache
This moves following files to webkit/common/appcache - appcache/appcache_interfaces* Following files to webkit/renderer/appcache - appcache/appcache_frontend_impl* - appcache/web_application_cache_host_impl* and everything else to webkit/browser/appcache. BUG=239109 TBR=avi@chromium.org, michaeln@chromium.org, thestig@chromium.org Review URL: https://codereview.chromium.org/16081004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204218 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser/appcache/appcache_quota_client.cc')
-rw-r--r--webkit/browser/appcache/appcache_quota_client.cc246
1 files changed, 246 insertions, 0 deletions
diff --git a/webkit/browser/appcache/appcache_quota_client.cc b/webkit/browser/appcache/appcache_quota_client.cc
new file mode 100644
index 0000000..7f2d647
--- /dev/null
+++ b/webkit/browser/appcache/appcache_quota_client.cc
@@ -0,0 +1,246 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/browser/appcache/appcache_quota_client.h"
+
+#include <algorithm>
+#include <map>
+#include <set>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "webkit/browser/appcache/appcache_service.h"
+
+using quota::QuotaClient;
+
+namespace {
+quota::QuotaStatusCode NetErrorCodeToQuotaStatus(int code) {
+ if (code == net::OK)
+ return quota::kQuotaStatusOk;
+ else if (code == net::ERR_ABORTED)
+ return quota::kQuotaErrorAbort;
+ else
+ return quota::kQuotaStatusUnknown;
+}
+
+void RunFront(appcache::AppCacheQuotaClient::RequestQueue* queue) {
+ base::Closure request = queue->front();
+ queue->pop_front();
+ request.Run();
+}
+} // namespace
+
+namespace appcache {
+
+AppCacheQuotaClient::AppCacheQuotaClient(AppCacheService* service)
+ : service_(service),
+ appcache_is_ready_(false),
+ quota_manager_is_destroyed_(false) {
+}
+
+AppCacheQuotaClient::~AppCacheQuotaClient() {
+ DCHECK(pending_batch_requests_.empty());
+ DCHECK(pending_serial_requests_.empty());
+ DCHECK(current_delete_request_callback_.is_null());
+}
+
+QuotaClient::ID AppCacheQuotaClient::id() const {
+ return kAppcache;
+}
+
+void AppCacheQuotaClient::OnQuotaManagerDestroyed() {
+ DeletePendingRequests();
+ if (!current_delete_request_callback_.is_null()) {
+ current_delete_request_callback_.Reset();
+ GetServiceDeleteCallback()->Cancel();
+ }
+
+ quota_manager_is_destroyed_ = true;
+ if (!service_)
+ delete this;
+}
+
+void AppCacheQuotaClient::GetOriginUsage(
+ const GURL& origin,
+ quota::StorageType type,
+ const GetUsageCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(!quota_manager_is_destroyed_);
+
+ if (!service_) {
+ callback.Run(0);
+ return;
+ }
+
+ if (!appcache_is_ready_) {
+ pending_batch_requests_.push_back(
+ base::Bind(&AppCacheQuotaClient::GetOriginUsage,
+ base::Unretained(this), origin, type, callback));
+ return;
+ }
+
+ if (type != quota::kStorageTypeTemporary) {
+ callback.Run(0);
+ return;
+ }
+
+ const AppCacheStorage::UsageMap* map = GetUsageMap();
+ AppCacheStorage::UsageMap::const_iterator found = map->find(origin);
+ if (found == map->end()) {
+ callback.Run(0);
+ return;
+ }
+ callback.Run(found->second);
+}
+
+void AppCacheQuotaClient::GetOriginsForType(
+ quota::StorageType type,
+ const GetOriginsCallback& callback) {
+ GetOriginsHelper(type, std::string(), callback);
+}
+
+void AppCacheQuotaClient::GetOriginsForHost(
+ quota::StorageType type,
+ const std::string& host,
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
+ if (host.empty()) {
+ callback.Run(std::set<GURL>());
+ return;
+ }
+ GetOriginsHelper(type, host, callback);
+}
+
+void AppCacheQuotaClient::DeleteOriginData(const GURL& origin,
+ quota::StorageType type,
+ const DeletionCallback& callback) {
+ DCHECK(!quota_manager_is_destroyed_);
+
+ if (!service_) {
+ callback.Run(quota::kQuotaErrorAbort);
+ return;
+ }
+
+ if (!appcache_is_ready_ || !current_delete_request_callback_.is_null()) {
+ pending_serial_requests_.push_back(
+ base::Bind(&AppCacheQuotaClient::DeleteOriginData,
+ base::Unretained(this), origin, type, callback));
+ return;
+ }
+
+ current_delete_request_callback_ = callback;
+ if (type != quota::kStorageTypeTemporary) {
+ DidDeleteAppCachesForOrigin(net::OK);
+ return;
+ }
+
+ service_->DeleteAppCachesForOrigin(
+ origin, GetServiceDeleteCallback()->callback());
+}
+
+void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) {
+ DCHECK(service_);
+ if (quota_manager_is_destroyed_)
+ return;
+
+ // Finish the request by calling our callers callback.
+ current_delete_request_callback_.Run(NetErrorCodeToQuotaStatus(rv));
+ current_delete_request_callback_.Reset();
+ if (pending_serial_requests_.empty())
+ return;
+
+ // Start the next in the queue.
+ RunFront(&pending_serial_requests_);
+}
+
+void AppCacheQuotaClient::GetOriginsHelper(
+ quota::StorageType type,
+ const std::string& opt_host,
+ const GetOriginsCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(!quota_manager_is_destroyed_);
+
+ if (!service_) {
+ callback.Run(std::set<GURL>());
+ return;
+ }
+
+ if (!appcache_is_ready_) {
+ pending_batch_requests_.push_back(
+ base::Bind(&AppCacheQuotaClient::GetOriginsHelper,
+ base::Unretained(this), type, opt_host, callback));
+ return;
+ }
+
+ if (type != quota::kStorageTypeTemporary) {
+ callback.Run(std::set<GURL>());
+ return;
+ }
+
+ const AppCacheStorage::UsageMap* map = GetUsageMap();
+ std::set<GURL> origins;
+ for (AppCacheStorage::UsageMap::const_iterator iter = map->begin();
+ iter != map->end(); ++iter) {
+ if (opt_host.empty() || iter->first.host() == opt_host)
+ origins.insert(iter->first);
+ }
+ callback.Run(origins);
+}
+
+void AppCacheQuotaClient::ProcessPendingRequests() {
+ DCHECK(appcache_is_ready_);
+ while (!pending_batch_requests_.empty())
+ RunFront(&pending_batch_requests_);
+
+ if (!pending_serial_requests_.empty())
+ RunFront(&pending_serial_requests_);
+}
+
+void AppCacheQuotaClient::DeletePendingRequests() {
+ pending_batch_requests_.clear();
+ pending_serial_requests_.clear();
+}
+
+const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() {
+ DCHECK(service_);
+ return service_->storage()->usage_map();
+}
+
+net::CancelableCompletionCallback*
+AppCacheQuotaClient::GetServiceDeleteCallback() {
+ // Lazily created due to CancelableCompletionCallback's threading
+ // restrictions, there is no way to detach from the thread created on.
+ if (!service_delete_callback_) {
+ service_delete_callback_.reset(
+ new net::CancelableCompletionCallback(
+ base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin,
+ base::Unretained(this))));
+ }
+ return service_delete_callback_.get();
+}
+
+void AppCacheQuotaClient::NotifyAppCacheReady() {
+ appcache_is_ready_ = true;
+ ProcessPendingRequests();
+}
+
+void AppCacheQuotaClient::NotifyAppCacheDestroyed() {
+ service_ = NULL;
+ while (!pending_batch_requests_.empty())
+ RunFront(&pending_batch_requests_);
+
+ while (!pending_serial_requests_.empty())
+ RunFront(&pending_serial_requests_);
+
+ if (!current_delete_request_callback_.is_null()) {
+ current_delete_request_callback_.Run(quota::kQuotaErrorAbort);
+ current_delete_request_callback_.Reset();
+ GetServiceDeleteCallback()->Cancel();
+ }
+
+ if (quota_manager_is_destroyed_)
+ delete this;
+}
+
+} // namespace appcache