Chromium Code Reviews| 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() { | |
| 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_DidHandleRequestStorageQuota, | |
| 36 DidHandleRequestStorageQuota) | |
| 37 IPC_MESSAGE_HANDLER(QuotaMsg_DidHandleQueryUsageAndQuotaQuery, | |
| 38 DidHandleUsageAndQuotaQuery); | |
|
ericu
2011/04/08 03:31:18
DidHandleRequestUsageAndQuota?
kinuko
2011/04/08 09:02:53
Renamed to DidGrantStorageQuota and introduced Did
| |
| 39 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 40 IPC_END_MESSAGE_MAP() | |
| 41 return handled; | |
| 42 } | |
| 43 | |
| 44 void QuotaDispatcher::QueryStorageUsageAndQuota( | |
| 45 const GURL& origin_url, | |
| 46 WebKit::WebStorageQuotaType type, | |
| 47 WebKit::WebStorageQuotaCallbacks* callbacks) { | |
| 48 DCHECK(callbacks); | |
| 49 int request_id = pending_quota_callbacks_.Add( | |
| 50 new PendingQuotaCallbacks(callbacks)); | |
| 51 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( | |
| 52 request_id, origin_url, type)); | |
| 53 } | |
| 54 | |
| 55 void QuotaDispatcher::RequestStorageQuota( | |
| 56 const GURL& origin_url, | |
| 57 WebKit::WebStorageQuotaType type, | |
| 58 unsigned long long requested_size, | |
| 59 WebKit::WebStorageQuotaCallbacks* callbacks) { | |
| 60 DCHECK(callbacks); | |
| 61 int request_id = pending_quota_callbacks_.Add( | |
| 62 new PendingQuotaCallbacks(callbacks)); | |
| 63 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( | |
| 64 request_id, origin_url, type, requested_size)); | |
| 65 } | |
| 66 | |
| 67 void QuotaDispatcher::DidHandleRequestStorageQuota( | |
| 68 int request_id, | |
| 69 WebKit::WebStorageQuotaError error, | |
| 70 int64 granted_quota) { | |
| 71 PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); | |
| 72 DCHECK(request); | |
| 73 if (error == WebKit::WebStorageQuotaErrorOk) | |
| 74 request->callbacks->wasGrantedStorageQuota(granted_quota); | |
| 75 else | |
| 76 request->callbacks->didFail(error); | |
| 77 request->callbacks = NULL; | |
| 78 pending_quota_callbacks_.Remove(request_id); | |
| 79 } | |
| 80 | |
| 81 void QuotaDispatcher::DidHandleUsageAndQuotaQuery( | |
| 82 int request_id, | |
| 83 WebKit::WebStorageQuotaError error, | |
| 84 int64 current_usage, | |
| 85 int64 current_quota) { | |
| 86 PendingQuotaCallbacks* request = pending_quota_callbacks_.Lookup(request_id); | |
| 87 DCHECK(request); | |
| 88 if (error == WebKit::WebStorageQuotaErrorOk) | |
| 89 request->callbacks->didQueryStorageUsageAndQuota( | |
| 90 current_usage, current_quota); | |
| 91 else | |
| 92 request->callbacks->didFail(error); | |
| 93 request->callbacks = NULL; | |
| 94 pending_quota_callbacks_.Remove(request_id); | |
| 95 } | |
| OLD | NEW |