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 "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba
cks.h" |
| 11 |
| 12 using WebKit::WebStorageQuotaCallbacks; |
| 13 using WebKit::WebStorageQuotaError; |
| 14 using WebKit::WebStorageQuotaType; |
| 15 |
| 16 QuotaDispatcher::QuotaDispatcher() { |
| 17 } |
| 18 |
| 19 QuotaDispatcher::~QuotaDispatcher() { |
| 20 IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_); |
| 21 while (!iter.IsAtEnd()) { |
| 22 iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 23 iter.Advance(); |
| 24 } |
| 25 } |
| 26 |
| 27 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 28 bool handled = true; |
| 29 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
| 30 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, |
| 31 DidGrantStorageQuota) |
| 32 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, |
| 33 DidQueryStorageUsageAndQuota); |
| 34 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() |
| 37 return handled; |
| 38 } |
| 39 |
| 40 void QuotaDispatcher::QueryStorageUsageAndQuota( |
| 41 const GURL& origin_url, |
| 42 WebStorageQuotaType type, |
| 43 WebStorageQuotaCallbacks* callbacks) { |
| 44 DCHECK(callbacks); |
| 45 int request_id = pending_quota_callbacks_.Add(callbacks); |
| 46 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
| 47 request_id, origin_url, type)); |
| 48 } |
| 49 |
| 50 void QuotaDispatcher::RequestStorageQuota( |
| 51 const GURL& origin_url, |
| 52 WebStorageQuotaType type, |
| 53 unsigned long long requested_size, |
| 54 WebStorageQuotaCallbacks* callbacks) { |
| 55 DCHECK(callbacks); |
| 56 int request_id = pending_quota_callbacks_.Add(callbacks); |
| 57 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
| 58 request_id, origin_url, type, requested_size)); |
| 59 } |
| 60 |
| 61 void QuotaDispatcher::DidGrantStorageQuota( |
| 62 int request_id, |
| 63 int64 granted_quota) { |
| 64 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( |
| 65 request_id); |
| 66 DCHECK(callbacks); |
| 67 callbacks->didGrantStorageQuota(granted_quota); |
| 68 pending_quota_callbacks_.Remove(request_id); |
| 69 } |
| 70 |
| 71 void QuotaDispatcher::DidQueryStorageUsageAndQuota( |
| 72 int request_id, |
| 73 int64 current_usage, |
| 74 int64 current_quota) { |
| 75 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( |
| 76 request_id); |
| 77 DCHECK(callbacks); |
| 78 callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota); |
| 79 pending_quota_callbacks_.Remove(request_id); |
| 80 } |
| 81 |
| 82 void QuotaDispatcher::DidFail( |
| 83 int request_id, |
| 84 WebStorageQuotaError error) { |
| 85 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( |
| 86 request_id); |
| 87 DCHECK(callbacks); |
| 88 callbacks->didFail(error); |
| 89 pending_quota_callbacks_.Remove(request_id); |
| 90 } |
OLD | NEW |