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

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

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 | « no previous file | ppapi/host/resource_message_filter.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 #ifndef PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ 5 #ifndef PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_
6 #define PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ 6 #define PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "ppapi/c/pp_stdint.h" 9 #include "ppapi/c/pp_stdint.h"
10 #include "ppapi/host/host_message_context.h" 10 #include "ppapi/host/host_message_context.h"
11 #include "ppapi/host/ppapi_host_export.h" 11 #include "ppapi/host/ppapi_host_export.h"
12 #include "ppapi/host/resource_message_handler.h" 12 #include "ppapi/host/resource_message_handler.h"
13 13
14 namespace base { 14 namespace base {
15 class MessageLoopProxy; 15 class MessageLoopProxy;
16 class TaskRunner; 16 class TaskRunner;
17 } 17 }
18 18
19 namespace IPC { 19 namespace IPC {
20 class Message; 20 class Message;
21 } 21 }
22 22
23 namespace ppapi { 23 namespace ppapi {
24 namespace host { 24 namespace host {
25 25
26 class ResourceHost; 26 class ResourceHost;
27 class ResourceMessageFilter;
28
29 namespace internal {
30
31 struct PPAPI_HOST_EXPORT ResourceMessageFilterDeleteTraits {
32 static void Destruct(const ResourceMessageFilter* filter);
33 };
34
35 } // namespace internal
27 36
28 // This is the base class of resource message filters that can handle resource 37 // This is the base class of resource message filters that can handle resource
29 // messages on another thread. ResourceHosts can handle most messages 38 // messages on another thread. ResourceHosts can handle most messages
30 // directly, but if they need to handle something on a different thread it is 39 // directly, but if they need to handle something on a different thread it is
31 // inconvenient. This class makes handling that case easier. This class is 40 // inconvenient. This class makes handling that case easier. This class is
32 // similar to a BrowserMessageFilter but for resource messages. Note that the 41 // similar to a BrowserMessageFilter but for resource messages. Note that the
33 // liftetime of a ResourceHost is managed by a PpapiHost and may be destroyed 42 // liftetime of a ResourceHost is managed by a PpapiHost and may be destroyed
34 // before or while your message is being processed on another thread. 43 // before or while your message is being processed on another thread.
35 // If this is the case, the message handler will always be called but a reply 44 // If this is the case, the message handler will always be called but a reply
36 // may not be sent back to the host. 45 // may not be sent back to the host.
(...skipping 21 matching lines...) Expand all
58 // private: 67 // private:
59 // int32_t OnMyMessage(ppapi::host::HostMessageContext* context, ...) { 68 // int32_t OnMyMessage(ppapi::host::HostMessageContext* context, ...) {
60 // // Will be run on the UI thread. 69 // // Will be run on the UI thread.
61 // } 70 // }
62 // } 71 // }
63 // 72 //
64 // The filter should then be added in the resource host using: 73 // The filter should then be added in the resource host using:
65 // AddFilter(make_scoped_refptr(new MyMessageFilter)); 74 // AddFilter(make_scoped_refptr(new MyMessageFilter));
66 class PPAPI_HOST_EXPORT ResourceMessageFilter 75 class PPAPI_HOST_EXPORT ResourceMessageFilter
67 : public ResourceMessageHandler, 76 : public ResourceMessageHandler,
68 public base::RefCountedThreadSafe<ResourceMessageFilter> { 77 public base::RefCountedThreadSafe<
78 ResourceMessageFilter, internal::ResourceMessageFilterDeleteTraits> {
69 public: 79 public:
70 // This object must be constructed on the same thread that a reply message 80 // This object must be constructed on the same thread that a reply message
71 // should be sent, i.e. the IO thread when constructed in the browser process 81 // should be sent, i.e. the IO thread when constructed in the browser process
72 // or the main thread when constructed in the renderer process. Since 82 // or the main thread when constructed in the renderer process. Since
73 // ResourceMessageFilters are usually constructed in the constructor of the 83 // ResourceMessageFilters are usually constructed in the constructor of the
74 // owning ResourceHost, this will almost always be the case anyway. 84 // owning ResourceHost, this will almost always be the case anyway.
85 // The object will be deleted on the creation thread.
75 ResourceMessageFilter(); 86 ResourceMessageFilter();
76 // Test constructor. Allows you to specify the message loop which will be used 87 // Test constructor. Allows you to specify the message loop which will be used
77 // to dispatch replies on. 88 // to dispatch replies on.
78 ResourceMessageFilter( 89 ResourceMessageFilter(
79 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy); 90 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy);
80 91
81 // Called when a filter is added to a ResourceHost. 92 // Called when a filter is added to a ResourceHost.
82 void OnFilterAdded(ResourceHost* resource_host); 93 void OnFilterAdded(ResourceHost* resource_host);
83 // Called when a filter is removed from a ResourceHost. 94 // Called when a filter is removed from a ResourceHost.
84 void OnFilterDestroyed(); 95 void OnFilterDestroyed();
85 96
86 // This will dispatch the message handler on the target thread. It returns 97 // This will dispatch the message handler on the target thread. It returns
87 // true if the message was handled by this filter and false otherwise. 98 // true if the message was handled by this filter and false otherwise.
88 virtual bool HandleMessage(const IPC::Message& msg, 99 virtual bool HandleMessage(const IPC::Message& msg,
89 HostMessageContext* context) OVERRIDE; 100 HostMessageContext* context) OVERRIDE;
90 101
91 // This can be called from any thread. 102 // This can be called from any thread.
92 virtual void SendReply(const ReplyMessageContext& context, 103 virtual void SendReply(const ReplyMessageContext& context,
93 const IPC::Message& msg) OVERRIDE; 104 const IPC::Message& msg) OVERRIDE;
94 105
95 protected: 106 protected:
96 friend class base::RefCountedThreadSafe<ResourceMessageFilter>;
97 virtual ~ResourceMessageFilter(); 107 virtual ~ResourceMessageFilter();
98 108
99 // If you want the message to be handled on another thread, return a non-null 109 // If you want the message to be handled on another thread, return a non-null
100 // task runner which will target tasks accordingly. 110 // task runner which will target tasks accordingly.
101 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( 111 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
102 const IPC::Message& message); 112 const IPC::Message& message);
103 113
104 private: 114 private:
115 friend class base::DeleteHelper<ResourceMessageFilter>;
116 friend class base::RefCountedThreadSafe<
117 ResourceMessageFilter, internal::ResourceMessageFilterDeleteTraits>;
118 friend struct internal::ResourceMessageFilterDeleteTraits;
119
105 // This method is posted to the target thread and runs the message handler. 120 // This method is posted to the target thread and runs the message handler.
106 void DispatchMessage(const IPC::Message& msg, 121 void DispatchMessage(const IPC::Message& msg,
107 HostMessageContext context); 122 HostMessageContext context);
108 123
124 scoped_refptr<base::MessageLoopProxy> deletion_message_loop_proxy_;
125
109 // Message loop to send resource message replies on. This will be the message 126 // Message loop to send resource message replies on. This will be the message
110 // loop proxy of the IO thread for the browser process or the main thread for 127 // loop proxy of the IO thread for the browser process or the main thread for
111 // the renderer process. 128 // the renderer process.
112 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy_; 129 scoped_refptr<base::MessageLoopProxy> reply_thread_message_loop_proxy_;
113 130
114 // Non-owning pointer to the resource host owning this filter. Should only be 131 // Non-owning pointer to the resource host owning this filter. Should only be
115 // accessed from the thread which sends messages to the plugin resource (i.e. 132 // accessed from the thread which sends messages to the plugin resource (i.e.
116 // the IO thread for the browser process or the main thread for the renderer). 133 // the IO thread for the browser process or the main thread for the renderer).
117 // This will be NULL upon creation of the filter and is set to the owning 134 // This will be NULL upon creation of the filter and is set to the owning
118 // ResourceHost when |OnFilterAdded| is called. When the owning ResourceHost 135 // ResourceHost when |OnFilterAdded| is called. When the owning ResourceHost
119 // is destroyed, |OnFilterDestroyed| is called and this will be set to NULL. 136 // is destroyed, |OnFilterDestroyed| is called and this will be set to NULL.
120 ResourceHost* resource_host_; 137 ResourceHost* resource_host_;
121 138
122 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); 139 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter);
123 }; 140 };
124 141
125 } // namespace host 142 } // namespace host
126 } // namespace ppapi 143 } // namespace ppapi
127 144
128 #endif // PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_ 145 #endif // PPAPI_HOST_RESOURCE_MESSAGE_FILTER_H_
OLDNEW
« no previous file with comments | « no previous file | ppapi/host/resource_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698