Chromium Code Reviews| 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..e10f2cdc1b6ace730ee471dc7f0e15e7131f9ede |
| --- /dev/null |
| +++ b/content/common/quota_dispatcher.cc |
| @@ -0,0 +1,95 @@ |
| +// 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() { |
| +} |
| + |
| +bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
| + IPC_MESSAGE_HANDLER(QuotaMsg_DidHandleRequestStorageQuota, |
| + DidHandleRequestStorageQuota) |
| + IPC_MESSAGE_HANDLER(QuotaMsg_DidHandleQueryUsageAndQuotaQuery, |
| + DidHandleUsageAndQuotaQuery); |
|
ericu
2011/04/08 03:31:18
DidHandleRequestUsageAndQuota?
kinuko
2011/04/08 09:02:53
Renamed to DidGrantStorageQuota and introduced Did
|
| + 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::DidHandleRequestStorageQuota( |
| + int request_id, |
| + WebKit::WebStorageQuotaError error, |
| + int64 granted_quota) { |
| + PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); |
| + DCHECK(request); |
| + if (error == WebKit::WebStorageQuotaErrorOk) |
| + request->callbacks->wasGrantedStorageQuota(granted_quota); |
| + else |
| + request->callbacks->didFail(error); |
| + request->callbacks = NULL; |
| + pending_quota_callbacks_.Remove(request_id); |
| +} |
| + |
| +void QuotaDispatcher::DidHandleUsageAndQuotaQuery( |
| + int request_id, |
| + WebKit::WebStorageQuotaError error, |
| + int64 current_usage, |
| + int64 current_quota) { |
| + PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); |
| + DCHECK(request); |
| + if (error == WebKit::WebStorageQuotaErrorOk) |
| + request->callbacks->didQueryStorageUsageAndQuota( |
| + current_usage, current_quota); |
| + else |
| + request->callbacks->didFail(error); |
| + request->callbacks = NULL; |
| + pending_quota_callbacks_.Remove(request_id); |
| +} |