Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: content/common/quota_dispatcher.cc

Issue 6811022: Add IPC plumbing code for Quota API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/quota_dispatcher.cc
diff --git a/content/common/quota_dispatcher.cc b/content/common/quota_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b767e345659f92c3f7376d959abc84f713c26bd7
--- /dev/null
+++ b/content/common/quota_dispatcher.cc
@@ -0,0 +1,98 @@
+// Copyright (c) 2011 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 "content/common/quota_dispatcher.h"
+
+#include "content/common/child_thread.h"
+#include "content/common/quota_messages.h"
+#include "googleurl/src/gurl.h"
+#include "ipc/ipc_message.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
+
+using WebKit::WebStorageQuotaCallbacks;
+using WebKit::WebStorageQuotaError;
+using WebKit::WebStorageQuotaType;
+
+struct QuotaDispatcher::PendingQuotaCallbacks {
+ PendingQuotaCallbacks(WebStorageQuotaCallbacks* c) : callbacks(c) { }
+ ~PendingQuotaCallbacks() {
+ if (callbacks)
+ callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
+ }
+ WebStorageQuotaCallbacks* callbacks;
+};
+
+QuotaDispatcher::QuotaDispatcher() {
+}
+
+QuotaDispatcher::~QuotaDispatcher() {
+}
+
+bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg)
+ IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota,
+ DidGrantStorageQuota)
+ IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota,
+ DidQueryStorageUsageAndQuota);
+ IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail);
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void QuotaDispatcher::QueryStorageUsageAndQuota(
+ const GURL& origin_url,
+ WebKit::WebStorageQuotaType type,
+ WebKit::WebStorageQuotaCallbacks* callbacks) {
+ DCHECK(callbacks);
+ int request_id = pending_quota_callbacks_.Add(
+ new PendingQuotaCallbacks(callbacks));
+ ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota(
+ request_id, origin_url, type));
+}
+
+void QuotaDispatcher::RequestStorageQuota(
+ const GURL& origin_url,
+ WebKit::WebStorageQuotaType type,
+ unsigned long long requested_size,
+ WebKit::WebStorageQuotaCallbacks* callbacks) {
+ DCHECK(callbacks);
+ int request_id = pending_quota_callbacks_.Add(
+ new PendingQuotaCallbacks(callbacks));
+ ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota(
+ request_id, origin_url, type, requested_size));
+}
+
+void QuotaDispatcher::DidGrantStorageQuota(
+ int request_id,
+ int64 granted_quota) {
+ PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id);
+ DCHECK(request);
+ request->callbacks->didGrantStorageQuota(granted_quota);
+ request->callbacks = NULL;
+ pending_quota_callbacks_.Remove(request_id);
+}
+
+void QuotaDispatcher::DidQueryStorageUsageAndQuota(
+ int request_id,
+ int64 current_usage,
+ int64 current_quota) {
+ PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id);
+ DCHECK(request);
+ request->callbacks->didQueryStorageUsageAndQuota(
+ current_usage, current_quota);
+ request->callbacks = NULL;
+ pending_quota_callbacks_.Remove(request_id);
+}
+
+void QuotaDispatcher::DidFail(
+ int request_id,
+ WebKit::WebStorageQuotaError error) {
+ PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id);
+ DCHECK(request);
+ request->callbacks->didFail(error);
+ request->callbacks = NULL;
+ pending_quota_callbacks_.Remove(request_id);
+}

Powered by Google App Engine
This is Rietveld 408576698