Index: trunk/src/content/child/quota_dispatcher.cc |
=================================================================== |
--- trunk/src/content/child/quota_dispatcher.cc (revision 214172) |
+++ trunk/src/content/child/quota_dispatcher.cc (working copy) |
@@ -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::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 +54,17 @@ |
WebKit::WebStorageQuotaCallbacks* callbacks_; |
}; |
+int CurrentWorkerId() { |
+ return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
+} |
+ |
} // 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 +73,28 @@ |
iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort); |
iter.Advance(); |
} |
+ |
+ g_quota_dispatcher_tls.Pointer()->Set(NULL); |
} |
-bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
+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; |
+} |
+ |
+void QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) |
IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, |
@@ -67,7 +104,7 @@ |
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 +113,8 @@ |
Callback* callback) { |
DCHECK(callback); |
int request_id = pending_quota_callbacks_.Add(callback); |
- ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
+ quota_message_filter_->RegisterRequestID(request_id, CurrentWorkerId()); |
+ thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
request_id, origin_url, type)); |
} |
@@ -87,8 +125,10 @@ |
int64 requested_size, |
Callback* callback) { |
DCHECK(callback); |
+ DCHECK(CurrentWorkerId() == 0); |
int request_id = pending_quota_callbacks_.Add(callback); |
- ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( |
+ quota_message_filter_->RegisterRequestID(request_id, CurrentWorkerId()); |
+ thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota( |
render_view_id, request_id, origin_url, type, requested_size)); |
} |