Index: content/child/quota_dispatcher.cc |
diff --git a/content/child/quota_dispatcher.cc b/content/child/quota_dispatcher.cc |
index 69bec35f44d512c9db5d88c947f5e93eee6c4fad..77dead498d1c077c4982fa57662c727486c849d3 100644 |
--- a/content/child/quota_dispatcher.cc |
+++ b/content/child/quota_dispatcher.cc |
@@ -5,7 +5,10 @@ |
#include "content/child/quota_dispatcher.h" |
#include "base/basictypes.h" |
+#include "base/lazy_instance.h" |
+#include "base/threading/thread_local.h" |
#include "content/child/child_thread.h" |
+#include "content/child/thread_safe_sender.h" |
#include "content/common/quota_messages.h" |
#include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" |
#include "third_party/WebKit/public/web/WebStorageQuotaType.h" |
@@ -18,7 +21,13 @@ using WebKit::WebStorageQuotaCallbacks; |
using WebKit::WebStorageQuotaError; |
using WebKit::WebStorageQuotaType; |
+using webkit_glue::WorkerTaskRunner; |
+ |
namespace content { |
+ |
+static base::LazyInstance<base::ThreadLocalPointer<QuotaDispatcher> >::Leaky |
+ g_quota_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
+ |
namespace { |
// QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. |
@@ -44,9 +53,15 @@ class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { |
WebKit::WebStorageQuotaCallbacks* callbacks_; |
}; |
+int CurrentWorkerId() { |
+ return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
jam
2013/07/26 04:57:30
nit: adding this function for 2 calls before doesn
kinuko
2013/07/29 04:31:55
Done.
|
+} |
+ |
} // namespace |
-QuotaDispatcher::QuotaDispatcher() { |
+QuotaDispatcher::QuotaDispatcher(ThreadSafeSender* thread_safe_sender) |
+ : thread_safe_sender_(thread_safe_sender) { |
+ g_quota_dispatcher_tls.Pointer()->Set(this); |
} |
QuotaDispatcher::~QuotaDispatcher() { |
@@ -55,9 +70,26 @@ QuotaDispatcher::~QuotaDispatcher() { |
iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort); |
iter.Advance(); |
} |
+ |
+ g_quota_dispatcher_tls.Pointer()->Set(NULL); |
+} |
+ |
+QuotaDispatcher* QuotaDispatcher::ThreadSpecificInstance( |
+ ThreadSafeSender* thread_safe_sender) { |
+ if (g_quota_dispatcher_tls.Pointer()->Get()) |
+ return g_quota_dispatcher_tls.Pointer()->Get(); |
+ |
+ QuotaDispatcher* dispatcher = new QuotaDispatcher(thread_safe_sender); |
+ if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
+ WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); |
+ return dispatcher; |
+} |
+ |
+void QuotaDispatcher::OnWorkerRunLoopStopped() { |
+ delete this; |
} |
-bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
+void QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, |
@@ -67,7 +99,7 @@ bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
- return handled; |
+ DCHECK(handled) << "Unhandled message:" << msg.type(); |
} |
void QuotaDispatcher::QueryStorageUsageAndQuota( |
@@ -76,8 +108,8 @@ void QuotaDispatcher::QueryStorageUsageAndQuota( |
Callback* callback) { |
DCHECK(callback); |
int request_id = pending_quota_callbacks_.Add(callback); |
- ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
- request_id, origin_url, type)); |
+ thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
+ CurrentWorkerId(), request_id, origin_url, type)); |
} |
void QuotaDispatcher::RequestStorageQuota( |
@@ -87,8 +119,9 @@ void QuotaDispatcher::RequestStorageQuota( |
int64 requested_size, |
Callback* callback) { |
DCHECK(callback); |
+ DCHECK(CurrentWorkerId() == 0); |
int request_id = pending_quota_callbacks_.Add(callback); |
- ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
+ thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota( |
render_view_id, request_id, origin_url, type, requested_size)); |
} |
@@ -100,6 +133,7 @@ QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( |
} |
void QuotaDispatcher::DidGrantStorageQuota( |
+ int ipc_thread_id, |
int request_id, |
int64 granted_quota) { |
Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
@@ -109,6 +143,7 @@ void QuotaDispatcher::DidGrantStorageQuota( |
} |
void QuotaDispatcher::DidQueryStorageUsageAndQuota( |
+ int ipc_thread_id, |
int request_id, |
int64 current_usage, |
int64 current_quota) { |
@@ -119,6 +154,7 @@ void QuotaDispatcher::DidQueryStorageUsageAndQuota( |
} |
void QuotaDispatcher::DidFail( |
+ int ipc_thread_id, |
int request_id, |
QuotaStatusCode error) { |
Callback* callback = pending_quota_callbacks_.Lookup(request_id); |