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

Side by Side Diff: ppapi/host/resource_message_filter.cc

Issue 11410029: Added a ResourceMessageFilter for handling resource messages on another thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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
« no previous file with comments | « ppapi/host/resource_message_filter.h ('k') | ppapi/host/resource_message_filter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/host/resource_message_filter.h"
6
7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h"
9 #include "base/task_runner.h"
10 #include "ipc/ipc_message.h"
11 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/host/resource_host.h"
14
15 namespace ppapi {
16 namespace host {
17
18 ResourceMessageFilter::ResourceMessageFilter()
19 : reply_thread_message_loop_proxy_(
20 MessageLoop::current()->message_loop_proxy()),
21 resource_host_(NULL) {
22 }
23
24 ResourceMessageFilter::ResourceMessageFilter(
25 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy)
26 : reply_thread_message_loop_proxy_(reply_thread_message_loop_proxy),
27 resource_host_(NULL) {
28 }
29
30 ResourceMessageFilter::~ResourceMessageFilter() {
31 }
32
33 void ResourceMessageFilter::OnFilterAdded(ResourceHost* resource_host) {
34 resource_host_ = resource_host;
35 }
36
37 void ResourceMessageFilter::OnFilterDestroyed() {
38 resource_host_ = NULL;
39 }
40
41 bool ResourceMessageFilter::HandleMessage(const IPC::Message& msg,
42 HostMessageContext* context) {
43 scoped_refptr<base::TaskRunner> runner = OverrideTaskRunnerForMessage(msg);
44 if (runner) {
45 // TODO(raymes): We need to make a copy so the context can be used on other
46 // threads. It would be better to have a thread-safe refcounted context.
47 HostMessageContext context_copy = *context;
48 runner->PostTask(FROM_HERE, base::Bind(
49 &ResourceMessageFilter::DispatchMessage, this, msg, context_copy));
50 return true;
51 }
52
53 return false;
54 }
55
56 void ResourceMessageFilter::SendReply(const ReplyMessageContext& context,
57 const IPC::Message& msg) {
58 if (!reply_thread_message_loop_proxy_->BelongsToCurrentThread()) {
59 reply_thread_message_loop_proxy_->PostTask(FROM_HERE,
60 base::Bind(&ResourceMessageFilter::SendReply, this, context, msg));
61 return;
62 }
63 if (resource_host_)
64 resource_host_->SendReply(context, msg);
65 }
66
67 scoped_refptr<base::TaskRunner>
68 ResourceMessageFilter::OverrideTaskRunnerForMessage(const IPC::Message& msg) {
69 return NULL;
70 }
71
72 void ResourceMessageFilter::DispatchMessage(const IPC::Message& msg,
73 HostMessageContext context) {
74 RunMessageHandlerAndReply(msg, &context);
75 }
76
77 } // namespace host
78 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/host/resource_message_filter.h ('k') | ppapi/host/resource_message_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698