Index: content/child/quota_dispatcher.cc |
diff --git a/content/child/quota_dispatcher.cc b/content/child/quota_dispatcher.cc |
index 69bec35f44d512c9db5d88c947f5e93eee6c4fad..4dd7431bc4615eb7b0f91e5c8a7531ed94067db2 100644 |
--- a/content/child/quota_dispatcher.cc |
+++ b/content/child/quota_dispatcher.cc |
@@ -5,7 +5,11 @@ |
#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/quota_message_filter.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 +22,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. |
@@ -46,7 +56,11 @@ class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { |
} // namespace |
-QuotaDispatcher::QuotaDispatcher() { |
+QuotaDispatcher::QuotaDispatcher(ThreadSafeSender* thread_safe_sender, |
+ QuotaMessageFilter* quota_message_filter) |
+ : thread_safe_sender_(thread_safe_sender), |
+ quota_message_filter_(quota_message_filter) { |
+ g_quota_dispatcher_tls.Pointer()->Set(this); |
} |
QuotaDispatcher::~QuotaDispatcher() { |
@@ -55,9 +69,28 @@ QuotaDispatcher::~QuotaDispatcher() { |
iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort); |
iter.Advance(); |
} |
+ |
+ g_quota_dispatcher_tls.Pointer()->Set(NULL); |
+} |
+ |
+QuotaDispatcher* QuotaDispatcher::ThreadSpecificInstance( |
+ ThreadSafeSender* thread_safe_sender, |
+ QuotaMessageFilter* quota_message_filter) { |
+ if (g_quota_dispatcher_tls.Pointer()->Get()) |
+ return g_quota_dispatcher_tls.Pointer()->Get(); |
+ |
+ QuotaDispatcher* dispatcher = new QuotaDispatcher( |
+ thread_safe_sender, quota_message_filter); |
+ 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 +100,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,7 +109,9 @@ void QuotaDispatcher::QueryStorageUsageAndQuota( |
Callback* callback) { |
DCHECK(callback); |
int request_id = pending_quota_callbacks_.Add(callback); |
- ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
+ int thread_id = WorkerTaskRunner::Instance()->CurrentWorkerId(); |
+ quota_message_filter_->RegisterRequestID(request_id, thread_id); |
+ thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
request_id, origin_url, type)); |
} |
@@ -88,7 +123,10 @@ void QuotaDispatcher::RequestStorageQuota( |
Callback* callback) { |
DCHECK(callback); |
int request_id = pending_quota_callbacks_.Add(callback); |
- ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
+ int thread_id = WorkerTaskRunner::Instance()->CurrentWorkerId(); |
+ DCHECK(thread_id == 0); |
+ quota_message_filter_->RegisterRequestID(request_id, thread_id); |
+ thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota( |
render_view_id, request_id, origin_url, type, requested_size)); |
} |