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

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

Issue 11359097: Refactored the PPB_Flash_File_ModuleLocal/FileRef to the new ppapi resource model (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
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 : io_message_loop_proxy_(MessageLoop::current()->message_loop_proxy()),
20 resource_host_(NULL) {
21 }
22
23 ResourceMessageFilter::ResourceMessageFilter(
24 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy)
25 : io_message_loop_proxy_(io_message_loop_proxy),
26 resource_host_(NULL) {
27 }
28
29 ResourceMessageFilter::~ResourceMessageFilter() {
30 }
31
32 void ResourceMessageFilter::OnFilterAdded(ResourceHost* resource_host) {
33 resource_host_ = resource_host;
34 }
35
36 void ResourceMessageFilter::OnFilterDestroyed() {
37 resource_host_ = NULL;
38 }
39
40 bool ResourceMessageFilter::HandleMessage(const IPC::Message& msg,
41 HostMessageContext* context) {
42 scoped_refptr<base::TaskRunner> runner = OverrideTaskRunnerForMessage(msg);
43 if (runner) {
44 // TODO(raymes): We need to make a copy so the context can be used on other
45 // threads. It would be better to have a thread-safe refcounted context.
46 HostMessageContext context_copy = *context;
47 runner->PostTask(FROM_HERE, base::Bind(
48 &ResourceMessageFilter::DispatchMessage, this, msg, context_copy));
49 return true;
50 }
51
52 return false;
53 }
54
55 void ResourceMessageFilter::SendReply(const ReplyMessageContext& context,
56 const IPC::Message& msg) {
57 if (!io_message_loop_proxy_->BelongsToCurrentThread()) {
58 io_message_loop_proxy_->PostTask(FROM_HERE,
59 base::Bind(&ResourceMessageFilter::SendReply, this, context, msg));
60 return;
61 }
62 if (resource_host_)
63 resource_host_->SendReply(context, msg);
64 }
65
66 scoped_refptr<base::TaskRunner>
67 ResourceMessageFilter::OverrideTaskRunnerForMessage(const IPC::Message& msg) {
68 return NULL;
69 }
70
71 void ResourceMessageFilter::DispatchMessage(const IPC::Message& msg,
72 HostMessageContext context) {
73 RunMessageHandlerAndReply(msg, &context);
74 }
75
76 } // namespace host
77 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698