Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(712)

Side by Side Diff: content/child/quota_message_filter.cc

Issue 63843002: Add ChildMessageFilter, a base class for renderer/worker cross-thread MessageFilter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RemoveFilter fix Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/child/quota_message_filter.h" 5 #include "content/child/quota_message_filter.h"
6 6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 7 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/pickle.h"
11 #include "content/child/quota_dispatcher.h" 8 #include "content/child/quota_dispatcher.h"
12 #include "content/child/thread_safe_sender.h" 9 #include "content/child/thread_safe_sender.h"
10 #include "content/child/worker_thread_task_runner.h"
13 #include "content/common/quota_messages.h" 11 #include "content/common/quota_messages.h"
14 #include "webkit/child/worker_task_runner.h"
15
16 using webkit_glue::WorkerTaskRunner;
17 12
18 namespace content { 13 namespace content {
19 14
20 QuotaMessageFilter::QuotaMessageFilter( 15 QuotaMessageFilter::QuotaMessageFilter(
21 ThreadSafeSender* thread_safe_sender) 16 ThreadSafeSender* thread_safe_sender)
22 : main_thread_loop_proxy_(base::MessageLoopProxy::current()), 17 : main_thread_loop_proxy_(base::MessageLoopProxy::current()),
23 thread_safe_sender_(thread_safe_sender), 18 thread_safe_sender_(thread_safe_sender),
24 next_request_id_(0) { 19 next_request_id_(0) {
25 } 20 }
26 21
27 bool QuotaMessageFilter::OnMessageReceived(const IPC::Message& msg) { 22 QuotaMessageFilter::~QuotaMessageFilter() {}
28 if (IPC_MESSAGE_CLASS(msg) != QuotaMsgStart)
29 return false;
30 int request_id = -1;
31 bool result = PickleIterator(msg).ReadInt(&request_id);
32 DCHECK(result);
33 base::Closure closure = base::Bind(
34 &QuotaMessageFilter::DispatchMessage, this, msg);
35 int thread_id = 0;
36 {
37 base::AutoLock lock(request_id_map_lock_);
38 RequestIdToThreadId::iterator found = request_id_map_.find(request_id);
39 if (found != request_id_map_.end()) {
40 thread_id = found->second;
41 request_id_map_.erase(found);
42 }
43 }
44 if (!thread_id) {
45 main_thread_loop_proxy_->PostTask(FROM_HERE, closure);
46 return true;
47 }
48 WorkerTaskRunner::Instance()->PostTask(thread_id, closure);
49 return true;
50 }
51 23
52 int QuotaMessageFilter::GenerateRequestID(int thread_id) { 24 int QuotaMessageFilter::GenerateRequestID(int thread_id) {
53 base::AutoLock lock(request_id_map_lock_); 25 base::AutoLock lock(request_id_map_lock_);
54 request_id_map_[next_request_id_] = thread_id; 26 request_id_map_[next_request_id_] = thread_id;
55 return next_request_id_++; 27 return next_request_id_++;
56 } 28 }
57 29
58 void QuotaMessageFilter::ClearThreadRequests(int thread_id) { 30 void QuotaMessageFilter::ClearThreadRequests(int thread_id) {
59 base::AutoLock lock(request_id_map_lock_); 31 base::AutoLock lock(request_id_map_lock_);
60 for (RequestIdToThreadId::iterator iter = request_id_map_.begin(); 32 for (RequestIdToThreadId::iterator iter = request_id_map_.begin();
61 iter != request_id_map_.end();) { 33 iter != request_id_map_.end();) {
62 if (iter->second == thread_id) 34 if (iter->second == thread_id)
63 request_id_map_.erase(iter++); 35 request_id_map_.erase(iter++);
64 else 36 else
65 iter++; 37 iter++;
66 } 38 }
67 } 39 }
68 40
69 QuotaMessageFilter::~QuotaMessageFilter() {} 41 base::TaskRunner* QuotaMessageFilter::OverrideTaskRunnerForMessage(
42 const IPC::Message& msg) {
43 if (IPC_MESSAGE_CLASS(msg) != QuotaMsgStart)
44 return NULL;
70 45
71 void QuotaMessageFilter::DispatchMessage(const IPC::Message& msg) { 46 int request_id = -1, thread_id = 0;
47 const bool success = PickleIterator(msg).ReadInt(&request_id);
48 DCHECK(success);
49
50 {
51 base::AutoLock lock(request_id_map_lock_);
52 RequestIdToThreadId::iterator found = request_id_map_.find(request_id);
53 if (found != request_id_map_.end()) {
54 thread_id = found->second;
55 request_id_map_.erase(found);
56 }
57 }
58
59 if (!thread_id)
60 return main_thread_loop_proxy_.get();
61 return new WorkerThreadTaskRunner(thread_id);
62 }
63
64 bool QuotaMessageFilter::OnMessageReceived(const IPC::Message& msg) {
65 if (IPC_MESSAGE_CLASS(msg) != QuotaMsgStart)
66 return false;
72 QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender_.get(), this) 67 QuotaDispatcher::ThreadSpecificInstance(thread_safe_sender_.get(), this)
73 ->OnMessageReceived(msg); 68 ->OnMessageReceived(msg);
69 return true;
74 } 70 }
75 71
76 } // namespace content 72 } // namespace content
OLDNEW
« no previous file with comments | « content/child/quota_message_filter.h ('k') | content/child/service_worker/service_worker_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698