OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 |
| 5 #include "content/common/quota_dispatcher.h" |
| 6 |
| 7 #include "content/common/child_thread.h" |
| 8 #include "content/common/quota_messages.h" |
| 9 #include "googleurl/src/gurl.h" |
| 10 #include "ipc/ipc_message.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba
cks.h" |
| 12 |
| 13 using WebKit::WebStorageQuotaCallbacks; |
| 14 using WebKit::WebStorageQuotaError; |
| 15 using WebKit::WebStorageQuotaType; |
| 16 |
| 17 struct QuotaDispatcher::PendingQuotaCallbacks { |
| 18 PendingQuotaCallbacks(WebStorageQuotaCallbacks* c) : callbacks(c) { } |
| 19 ~PendingQuotaCallbacks() { |
| 20 if (callbacks) |
| 21 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 22 } |
| 23 WebStorageQuotaCallbacks* callbacks; |
| 24 }; |
| 25 |
| 26 QuotaDispatcher::QuotaDispatcher() { |
| 27 } |
| 28 |
| 29 QuotaDispatcher::~QuotaDispatcher() { |
| 30 } |
| 31 |
| 32 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 33 bool handled = true; |
| 34 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
| 35 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, |
| 36 DidGrantStorageQuota) |
| 37 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, |
| 38 DidQueryStorageUsageAndQuota); |
| 39 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); |
| 40 IPC_MESSAGE_UNHANDLED(handled = false) |
| 41 IPC_END_MESSAGE_MAP() |
| 42 return handled; |
| 43 } |
| 44 |
| 45 void QuotaDispatcher::QueryStorageUsageAndQuota( |
| 46 const GURL& origin_url, |
| 47 WebKit::WebStorageQuotaType type, |
| 48 WebKit::WebStorageQuotaCallbacks* callbacks) { |
| 49 DCHECK(callbacks); |
| 50 int request_id = pending_quota_callbacks_.Add( |
| 51 new PendingQuotaCallbacks(callbacks)); |
| 52 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
| 53 request_id, origin_url, type)); |
| 54 } |
| 55 |
| 56 void QuotaDispatcher::RequestStorageQuota( |
| 57 const GURL& origin_url, |
| 58 WebKit::WebStorageQuotaType type, |
| 59 unsigned long long requested_size, |
| 60 WebKit::WebStorageQuotaCallbacks* callbacks) { |
| 61 DCHECK(callbacks); |
| 62 int request_id = pending_quota_callbacks_.Add( |
| 63 new PendingQuotaCallbacks(callbacks)); |
| 64 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
| 65 request_id, origin_url, type, requested_size)); |
| 66 } |
| 67 |
| 68 void QuotaDispatcher::DidGrantStorageQuota( |
| 69 int request_id, |
| 70 int64 granted_quota) { |
| 71 PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); |
| 72 DCHECK(request); |
| 73 request->callbacks->didGrantStorageQuota(granted_quota); |
| 74 request->callbacks = NULL; |
| 75 pending_quota_callbacks_.Remove(request_id); |
| 76 } |
| 77 |
| 78 void QuotaDispatcher::DidQueryStorageUsageAndQuota( |
| 79 int request_id, |
| 80 int64 current_usage, |
| 81 int64 current_quota) { |
| 82 PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); |
| 83 DCHECK(request); |
| 84 request->callbacks->didQueryStorageUsageAndQuota( |
| 85 current_usage, current_quota); |
| 86 request->callbacks = NULL; |
| 87 pending_quota_callbacks_.Remove(request_id); |
| 88 } |
| 89 |
| 90 void QuotaDispatcher::DidFail( |
| 91 int request_id, |
| 92 WebKit::WebStorageQuotaError error) { |
| 93 PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); |
| 94 DCHECK(request); |
| 95 request->callbacks->didFail(error); |
| 96 request->callbacks = NULL; |
| 97 pending_quota_callbacks_.Remove(request_id); |
| 98 } |
OLD | NEW |