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

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

Issue 53153002: Pepper: always delete ResourceMessageFilter objects on the creation thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ppapi/host/resource_message_filter.h" 5 #include "ppapi/host/resource_message_filter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/task_runner.h" 10 #include "base/task_runner.h"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/host/ppapi_host.h" 13 #include "ppapi/host/ppapi_host.h"
14 #include "ppapi/host/resource_host.h" 14 #include "ppapi/host/resource_host.h"
15 15
16 namespace ppapi { 16 namespace ppapi {
17 namespace host { 17 namespace host {
18 18
19 ResourceMessageFilter::ResourceMessageFilter() 19 namespace internal {
20 : reply_thread_message_loop_proxy_( 20
21 // static
22 void ResourceMessageFilterDeleteTraits::Destruct(
23 const ResourceMessageFilter* filter) {
24 filter->InternalDestruct();
25 }
26
27 } // namespace internal
28
29 ResourceMessageFilter::ResourceMessageFilter(DeletionThread deletion_thread)
30 : deletion_message_loop_proxy_(
31 deletion_thread == DELETE_ON_CREATION_THREAD ?
32 base::MessageLoop::current()->message_loop_proxy() : NULL),
33 reply_thread_message_loop_proxy_(
21 base::MessageLoop::current()->message_loop_proxy()), 34 base::MessageLoop::current()->message_loop_proxy()),
22 resource_host_(NULL) {}
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) { 35 resource_host_(NULL) {
28 } 36 }
29 37
38 ResourceMessageFilter::ResourceMessageFilter(
39 DeletionThread deletion_thread,
40 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy)
41 : deletion_message_loop_proxy_(
42 deletion_thread == DELETE_ON_CREATION_THREAD ?
43 base::MessageLoop::current()->message_loop_proxy() : NULL),
44 reply_thread_message_loop_proxy_(reply_thread_message_loop_proxy),
45 resource_host_(NULL) {
46 }
47
30 ResourceMessageFilter::~ResourceMessageFilter() { 48 ResourceMessageFilter::~ResourceMessageFilter() {
31 } 49 }
32 50
33 void ResourceMessageFilter::OnFilterAdded(ResourceHost* resource_host) { 51 void ResourceMessageFilter::OnFilterAdded(ResourceHost* resource_host) {
34 resource_host_ = resource_host; 52 resource_host_ = resource_host;
35 } 53 }
36 54
37 void ResourceMessageFilter::OnFilterDestroyed() { 55 void ResourceMessageFilter::OnFilterDestroyed() {
38 resource_host_ = NULL; 56 resource_host_ = NULL;
39 } 57 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 scoped_refptr<base::TaskRunner> 90 scoped_refptr<base::TaskRunner>
73 ResourceMessageFilter::OverrideTaskRunnerForMessage(const IPC::Message& msg) { 91 ResourceMessageFilter::OverrideTaskRunnerForMessage(const IPC::Message& msg) {
74 return NULL; 92 return NULL;
75 } 93 }
76 94
77 void ResourceMessageFilter::DispatchMessage(const IPC::Message& msg, 95 void ResourceMessageFilter::DispatchMessage(const IPC::Message& msg,
78 HostMessageContext context) { 96 HostMessageContext context) {
79 RunMessageHandlerAndReply(msg, &context); 97 RunMessageHandlerAndReply(msg, &context);
80 } 98 }
81 99
100 void ResourceMessageFilter::InternalDestruct() const {
101 if (deletion_message_loop_proxy_ &&
102 !deletion_message_loop_proxy_->BelongsToCurrentThread()) {
103 // During shutdown the object may not be deleted, but it should be okay to
104 // leak in that case.
105 deletion_message_loop_proxy_->DeleteSoon(FROM_HERE, this);
dmichael (off chromium) 2013/10/30 22:05:42 Would there be any harm in just always deleting it
yzshen1 2013/10/30 22:11:55 It is not harmful for all the existing message fil
dmichael (off chromium) 2013/10/31 16:14:59 I see what you mean, but I would lean in favor of
yzshen1 2013/10/31 21:28:04 Yeah. Sounds good. I have made the change.
106 } else {
107 delete this;
108 }
109 }
110
82 } // namespace host 111 } // namespace host
83 } // namespace ppapi 112 } // 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