| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/quota_dispatcher.h" | 5 #include "content/common/quota_dispatcher.h" |
| 6 | 6 |
| 7 #include "content/common/child_thread.h" | 7 #include "content/common/child_thread.h" |
| 8 #include "content/common/quota_messages.h" | 8 #include "content/common/quota_messages.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba
cks.h" | |
| 11 | 10 |
| 12 using WebKit::WebStorageQuotaCallbacks; | 11 using quota::QuotaClient; |
| 13 using WebKit::WebStorageQuotaError; | 12 using quota::QuotaStatusCode; |
| 14 using WebKit::WebStorageQuotaType; | 13 using quota::StorageType; |
| 15 | 14 |
| 16 QuotaDispatcher::QuotaDispatcher() { | 15 QuotaDispatcher::QuotaDispatcher() { |
| 17 } | 16 } |
| 18 | 17 |
| 19 QuotaDispatcher::~QuotaDispatcher() { | 18 QuotaDispatcher::~QuotaDispatcher() { |
| 20 IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_); | 19 IDMap<Callback, IDMapOwnPointer>::iterator iter(&pending_quota_callbacks_); |
| 21 while (!iter.IsAtEnd()) { | 20 while (!iter.IsAtEnd()) { |
| 22 iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort); | 21 iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort); |
| 23 iter.Advance(); | 22 iter.Advance(); |
| 24 } | 23 } |
| 25 } | 24 } |
| 26 | 25 |
| 27 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { | 26 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 28 bool handled = true; | 27 bool handled = true; |
| 29 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) | 28 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
| 30 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, | 29 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, |
| 31 DidGrantStorageQuota) | 30 DidGrantStorageQuota) |
| 32 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, | 31 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, |
| 33 DidQueryStorageUsageAndQuota); | 32 DidQueryStorageUsageAndQuota); |
| 34 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); | 33 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | 34 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() | 35 IPC_END_MESSAGE_MAP() |
| 37 return handled; | 36 return handled; |
| 38 } | 37 } |
| 39 | 38 |
| 40 void QuotaDispatcher::QueryStorageUsageAndQuota( | 39 void QuotaDispatcher::QueryStorageUsageAndQuota( |
| 41 const GURL& origin_url, | 40 const GURL& origin_url, |
| 42 WebStorageQuotaType type, | 41 StorageType type, |
| 43 WebStorageQuotaCallbacks* callbacks) { | 42 Callback* callback) { |
| 44 DCHECK(callbacks); | 43 DCHECK(callback); |
| 45 int request_id = pending_quota_callbacks_.Add(callbacks); | 44 int request_id = pending_quota_callbacks_.Add(callback); |
| 46 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( | 45 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
| 47 request_id, origin_url, type)); | 46 request_id, origin_url, type)); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void QuotaDispatcher::RequestStorageQuota( | 49 void QuotaDispatcher::RequestStorageQuota( |
| 51 int render_view_id, | 50 int render_view_id, |
| 52 const GURL& origin_url, | 51 const GURL& origin_url, |
| 53 WebStorageQuotaType type, | 52 StorageType type, |
| 54 unsigned long long requested_size, | 53 int64 requested_size, |
| 55 WebStorageQuotaCallbacks* callbacks) { | 54 Callback* callback) { |
| 56 DCHECK(callbacks); | 55 DCHECK(callback); |
| 57 int request_id = pending_quota_callbacks_.Add(callbacks); | 56 int request_id = pending_quota_callbacks_.Add(callback); |
| 58 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( | 57 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
| 59 render_view_id, request_id, origin_url, type, requested_size)); | 58 render_view_id, request_id, origin_url, type, requested_size)); |
| 60 } | 59 } |
| 61 | 60 |
| 61 void QuotaDispatcher::NotifyStorageModified( |
| 62 QuotaClient::ID client_id, const GURL& origin_url, |
| 63 StorageType type, int64 delta) { |
| 64 ChildThread::current()->Send(new QuotaHostMsg_NotifyStorageModified( |
| 65 client_id, origin_url, type, delta)); |
| 66 } |
| 67 |
| 62 void QuotaDispatcher::DidGrantStorageQuota( | 68 void QuotaDispatcher::DidGrantStorageQuota( |
| 63 int request_id, | 69 int request_id, |
| 64 int64 granted_quota) { | 70 int64 granted_quota) { |
| 65 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( | 71 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 66 request_id); | 72 DCHECK(callback); |
| 67 DCHECK(callbacks); | 73 callback->DidGrantStorageQuota(granted_quota); |
| 68 callbacks->didGrantStorageQuota(granted_quota); | |
| 69 pending_quota_callbacks_.Remove(request_id); | 74 pending_quota_callbacks_.Remove(request_id); |
| 70 } | 75 } |
| 71 | 76 |
| 72 void QuotaDispatcher::DidQueryStorageUsageAndQuota( | 77 void QuotaDispatcher::DidQueryStorageUsageAndQuota( |
| 73 int request_id, | 78 int request_id, |
| 74 int64 current_usage, | 79 int64 current_usage, |
| 75 int64 current_quota) { | 80 int64 current_quota) { |
| 76 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( | 81 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 77 request_id); | 82 DCHECK(callback); |
| 78 DCHECK(callbacks); | 83 callback->DidQueryStorageUsageAndQuota(current_usage, current_quota); |
| 79 callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota); | |
| 80 pending_quota_callbacks_.Remove(request_id); | 84 pending_quota_callbacks_.Remove(request_id); |
| 81 } | 85 } |
| 82 | 86 |
| 83 void QuotaDispatcher::DidFail( | 87 void QuotaDispatcher::DidFail( |
| 84 int request_id, | 88 int request_id, |
| 85 WebStorageQuotaError error) { | 89 QuotaStatusCode error) { |
| 86 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( | 90 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 87 request_id); | 91 DCHECK(callback); |
| 88 DCHECK(callbacks); | 92 callback->DidFail(error); |
| 89 callbacks->didFail(error); | |
| 90 pending_quota_callbacks_.Remove(request_id); | 93 pending_quota_callbacks_.Remove(request_id); |
| 91 } | 94 } |
| OLD | NEW |