Chromium Code Reviews| 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 "base/basictypes.h" | |
| 7 #include "content/common/child_thread.h" | 8 #include "content/common/child_thread.h" |
| 8 #include "content/common/quota_messages.h" | 9 #include "content/common/quota_messages.h" |
| 9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba cks.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba cks.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h " | |
| 13 | |
| 14 using quota::QuotaStatusCode; | |
| 15 using quota::StorageType; | |
| 11 | 16 |
| 12 using WebKit::WebStorageQuotaCallbacks; | 17 using WebKit::WebStorageQuotaCallbacks; |
| 13 using WebKit::WebStorageQuotaError; | 18 using WebKit::WebStorageQuotaError; |
| 14 using WebKit::WebStorageQuotaType; | 19 using WebKit::WebStorageQuotaType; |
| 15 | 20 |
| 21 namespace { | |
|
brettw
2011/07/27 15:32:08
Blank line after this.
kinuko
2011/07/28 13:21:32
Done.
| |
| 22 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. | |
| 23 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { | |
| 24 public: | |
| 25 WebStorageQuotaDispatcherCallback(WebKit::WebStorageQuotaCallbacks* c) | |
| 26 : callbacks_(c) { | |
|
brettw
2011/07/27 15:32:08
Two more spaces before the :
kinuko
2011/07/28 13:21:32
Done.
| |
| 27 DCHECK(callbacks_); | |
| 28 } | |
| 29 virtual ~WebStorageQuotaDispatcherCallback() {} | |
| 30 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { | |
| 31 callbacks_->didQueryStorageUsageAndQuota(usage, quota); | |
| 32 } | |
| 33 virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE { | |
| 34 callbacks_->didGrantStorageQuota(granted_quota); | |
| 35 } | |
| 36 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE { | |
| 37 callbacks_->didFail(static_cast<WebStorageQuotaError>(error)); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 // Not owned (self-destructed). | |
| 42 WebKit::WebStorageQuotaCallbacks* callbacks_; | |
| 43 }; | |
| 44 } // anonymous namespace | |
|
brettw
2011/07/27 15:32:08
Bank line before this, no "anonymous"
kinuko
2011/07/28 13:21:32
Done.
| |
| 45 | |
| 16 QuotaDispatcher::QuotaDispatcher() { | 46 QuotaDispatcher::QuotaDispatcher() { |
| 17 } | 47 } |
| 18 | 48 |
| 19 QuotaDispatcher::~QuotaDispatcher() { | 49 QuotaDispatcher::~QuotaDispatcher() { |
| 20 IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_); | 50 IDMap<Callback, IDMapOwnPointer>::iterator iter(&pending_quota_callbacks_); |
| 21 while (!iter.IsAtEnd()) { | 51 while (!iter.IsAtEnd()) { |
| 22 iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort); | 52 iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort); |
| 23 iter.Advance(); | 53 iter.Advance(); |
| 24 } | 54 } |
| 25 } | 55 } |
| 26 | 56 |
| 27 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { | 57 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 28 bool handled = true; | 58 bool handled = true; |
| 29 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) | 59 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
| 30 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, | 60 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, |
| 31 DidGrantStorageQuota) | 61 DidGrantStorageQuota) |
| 32 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, | 62 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, |
| 33 DidQueryStorageUsageAndQuota); | 63 DidQueryStorageUsageAndQuota); |
| 34 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); | 64 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | 65 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() | 66 IPC_END_MESSAGE_MAP() |
| 37 return handled; | 67 return handled; |
| 38 } | 68 } |
| 39 | 69 |
| 40 void QuotaDispatcher::QueryStorageUsageAndQuota( | 70 void QuotaDispatcher::QueryStorageUsageAndQuota( |
| 41 const GURL& origin_url, | 71 const GURL& origin_url, |
| 42 WebStorageQuotaType type, | 72 StorageType type, |
| 43 WebStorageQuotaCallbacks* callbacks) { | 73 Callback* callback) { |
| 44 DCHECK(callbacks); | 74 DCHECK(callback); |
| 45 int request_id = pending_quota_callbacks_.Add(callbacks); | 75 int request_id = pending_quota_callbacks_.Add(callback); |
| 46 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( | 76 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
| 47 request_id, origin_url, type)); | 77 request_id, origin_url, type)); |
| 48 } | 78 } |
| 49 | 79 |
| 50 void QuotaDispatcher::RequestStorageQuota( | 80 void QuotaDispatcher::RequestStorageQuota( |
| 51 int render_view_id, | 81 int render_view_id, |
| 52 const GURL& origin_url, | 82 const GURL& origin_url, |
| 53 WebStorageQuotaType type, | 83 StorageType type, |
| 54 unsigned long long requested_size, | 84 int64 requested_size, |
| 55 WebStorageQuotaCallbacks* callbacks) { | 85 Callback* callback) { |
| 56 DCHECK(callbacks); | 86 DCHECK(callback); |
| 57 int request_id = pending_quota_callbacks_.Add(callbacks); | 87 int request_id = pending_quota_callbacks_.Add(callback); |
| 58 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( | 88 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
| 59 render_view_id, request_id, origin_url, type, requested_size)); | 89 render_view_id, request_id, origin_url, type, requested_size)); |
| 60 } | 90 } |
| 61 | 91 |
| 92 // static | |
| 93 QuotaDispatcher::Callback* | |
| 94 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( | |
| 95 WebKit::WebStorageQuotaCallbacks* callbacks) { | |
| 96 return new WebStorageQuotaDispatcherCallback(callbacks); | |
| 97 } | |
| 98 | |
| 62 void QuotaDispatcher::DidGrantStorageQuota( | 99 void QuotaDispatcher::DidGrantStorageQuota( |
| 63 int request_id, | 100 int request_id, |
| 64 int64 granted_quota) { | 101 int64 granted_quota) { |
| 65 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( | 102 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 66 request_id); | 103 DCHECK(callback); |
| 67 DCHECK(callbacks); | 104 callback->DidGrantStorageQuota(granted_quota); |
| 68 callbacks->didGrantStorageQuota(granted_quota); | |
| 69 pending_quota_callbacks_.Remove(request_id); | 105 pending_quota_callbacks_.Remove(request_id); |
| 70 } | 106 } |
| 71 | 107 |
| 72 void QuotaDispatcher::DidQueryStorageUsageAndQuota( | 108 void QuotaDispatcher::DidQueryStorageUsageAndQuota( |
| 73 int request_id, | 109 int request_id, |
| 74 int64 current_usage, | 110 int64 current_usage, |
| 75 int64 current_quota) { | 111 int64 current_quota) { |
| 76 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( | 112 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 77 request_id); | 113 DCHECK(callback); |
| 78 DCHECK(callbacks); | 114 callback->DidQueryStorageUsageAndQuota(current_usage, current_quota); |
| 79 callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota); | |
| 80 pending_quota_callbacks_.Remove(request_id); | 115 pending_quota_callbacks_.Remove(request_id); |
| 81 } | 116 } |
| 82 | 117 |
| 83 void QuotaDispatcher::DidFail( | 118 void QuotaDispatcher::DidFail( |
| 84 int request_id, | 119 int request_id, |
| 85 WebStorageQuotaError error) { | 120 QuotaStatusCode error) { |
| 86 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( | 121 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 87 request_id); | 122 DCHECK(callback); |
| 88 DCHECK(callbacks); | 123 callback->DidFail(error); |
| 89 callbacks->didFail(error); | |
| 90 pending_quota_callbacks_.Remove(request_id); | 124 pending_quota_callbacks_.Remove(request_id); |
| 91 } | 125 } |
| 126 | |
| 127 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \ | |
| 128 int(quota::kStorageTypeTemporary), mismatching_enums); | |
| 129 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \ | |
| 130 int(quota::kStorageTypePersistent), mismatching_enums); | |
| 131 | |
| 132 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \ | |
| 133 int(quota::kQuotaErrorNotSupported), mismatching_enums); | |
| 134 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \ | |
| 135 int(quota::kQuotaErrorAbort), mismatching_enums); | |
| OLD | NEW |