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

Side by Side Diff: ppapi/proxy/plugin_resource.h

Issue 46433002: Support using TrackedCallbacks as hints to determine the handling thread of resource reply messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 7 years 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 (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_PROXY_PLUGIN_RESOURCE_H_ 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
12 #include "ipc/ipc_message.h" 13 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_sender.h" 14 #include "ipc/ipc_sender.h"
14 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/proxy/connection.h" 16 #include "ppapi/proxy/connection.h"
16 #include "ppapi/proxy/plugin_resource_callback.h" 17 #include "ppapi/proxy/plugin_resource_callback.h"
17 #include "ppapi/proxy/ppapi_message_utils.h" 18 #include "ppapi/proxy/ppapi_message_utils.h"
18 #include "ppapi/proxy/ppapi_proxy_export.h" 19 #include "ppapi/proxy/ppapi_proxy_export.h"
19 #include "ppapi/proxy/resource_message_params.h" 20 #include "ppapi/proxy/resource_message_params.h"
21 #include "ppapi/proxy/resource_reply_thread_registrar.h"
20 #include "ppapi/shared_impl/resource.h" 22 #include "ppapi/shared_impl/resource.h"
21 23 #include "ppapi/shared_impl/tracked_callback.h"
22 namespace ppapi { 24 namespace ppapi {
23 namespace proxy { 25 namespace proxy {
24 26
25 class PluginDispatcher; 27 class PluginDispatcher;
26 28
27 class PPAPI_PROXY_EXPORT PluginResource : public Resource { 29 class PPAPI_PROXY_EXPORT PluginResource : public Resource {
28 public: 30 public:
29 enum Destination { 31 enum Destination {
30 RENDERER = 0, 32 RENDERER = 0,
31 BROWSER = 1 33 BROWSER = 1
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // 2) It is *not* recommended to let |callback| hold any reference to 94 // 2) It is *not* recommended to let |callback| hold any reference to
93 // |this|, in which it will be stored. Otherwise, this object will 95 // |this|, in which it will be stored. Otherwise, this object will
94 // live forever if we fail to clean up the callback. It is safe to 96 // live forever if we fail to clean up the callback. It is safe to
95 // use base::Unretained(this) or a weak pointer, because this object 97 // use base::Unretained(this) or a weak pointer, because this object
96 // will outlive the callback. 98 // will outlive the callback.
97 template<typename ReplyMsgClass, typename CallbackType> 99 template<typename ReplyMsgClass, typename CallbackType>
98 int32_t Call(Destination dest, 100 int32_t Call(Destination dest,
99 const IPC::Message& msg, 101 const IPC::Message& msg,
100 const CallbackType& callback); 102 const CallbackType& callback);
101 103
104 // Comparing with the previous Call() method, this method takes
105 // |reply_thread_hint| as a hint to determine which thread to handle the reply
106 // message.
107 //
108 // If |reply_thread_hint| is non-blocking, the reply message will be handled
109 // on the target thread of the callback; otherwises, it will be handled on the
dmichael (off chromium) 2013/12/10 23:38:01 s/otherwises/otherwise
yzshen1 2013/12/11 00:21:49 Done.
110 // main thread.
111 //
112 // If handling a reply message will cause a TrackedCallback to be run, it is
113 // recommended to use this version of Call(). It eliminates unnecessary
114 // thread switching and therefore has better performance.
115 template<typename ReplyMsgClass, typename CallbackType>
116 int32_t Call(Destination dest,
117 const IPC::Message& msg,
118 const CallbackType& callback,
119 scoped_refptr<TrackedCallback> reply_thread_hint);
120
102 // Calls the browser/renderer with sync messages. Returns the pepper error 121 // Calls the browser/renderer with sync messages. Returns the pepper error
103 // code from the call. 122 // code from the call.
104 // |ReplyMsgClass| is the type of the reply message that is expected. If it 123 // |ReplyMsgClass| is the type of the reply message that is expected. If it
105 // carries x parameters, then the method with x out parameters should be used. 124 // carries x parameters, then the method with x out parameters should be used.
106 // An example of usage: 125 // An example of usage:
107 // 126 //
108 // // Assuming the reply message carries a string and an integer. 127 // // Assuming the reply message carries a string and an integer.
109 // std::string param_1; 128 // std::string param_1;
110 // int param_2 = 0; 129 // int param_2 = 0;
111 // int32_t result = SyncCall<PpapiPluginMsg_MyResourceType_MyReplyMessage>( 130 // int32_t result = SyncCall<PpapiPluginMsg_MyResourceType_MyReplyMessage>(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // Use GetNextSequence to retrieve the next value. 171 // Use GetNextSequence to retrieve the next value.
153 int32_t next_sequence_number_; 172 int32_t next_sequence_number_;
154 173
155 bool sent_create_to_browser_; 174 bool sent_create_to_browser_;
156 bool sent_create_to_renderer_; 175 bool sent_create_to_renderer_;
157 176
158 typedef std::map<int32_t, scoped_refptr<PluginResourceCallbackBase> > 177 typedef std::map<int32_t, scoped_refptr<PluginResourceCallbackBase> >
159 CallbackMap; 178 CallbackMap;
160 CallbackMap callbacks_; 179 CallbackMap callbacks_;
161 180
181 scoped_refptr<ResourceReplyThreadRegistrar> resource_reply_thread_registrar_;
182
162 DISALLOW_COPY_AND_ASSIGN(PluginResource); 183 DISALLOW_COPY_AND_ASSIGN(PluginResource);
163 }; 184 };
164 185
165 template<typename ReplyMsgClass, typename CallbackType> 186 template<typename ReplyMsgClass, typename CallbackType>
166 int32_t PluginResource::Call(Destination dest, 187 int32_t PluginResource::Call(Destination dest,
167 const IPC::Message& msg, 188 const IPC::Message& msg,
168 const CallbackType& callback) { 189 const CallbackType& callback) {
190 return Call<ReplyMsgClass>(dest, msg, callback, NULL);
191 }
192
193 template<typename ReplyMsgClass, typename CallbackType>
194 int32_t PluginResource::Call(
195 Destination dest,
196 const IPC::Message& msg,
197 const CallbackType& callback,
198 scoped_refptr<TrackedCallback> reply_thread_hint) {
169 TRACE_EVENT2("ppapi proxy", "PluginResource::Call", 199 TRACE_EVENT2("ppapi proxy", "PluginResource::Call",
170 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), 200 "Class", IPC_MESSAGE_ID_CLASS(msg.type()),
171 "Line", IPC_MESSAGE_ID_LINE(msg.type())); 201 "Line", IPC_MESSAGE_ID_LINE(msg.type()));
172 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++); 202 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++);
173 // Stash the |callback| in |callbacks_| identified by the sequence number of 203 // Stash the |callback| in |callbacks_| identified by the sequence number of
174 // the call. 204 // the call.
175 scoped_refptr<PluginResourceCallbackBase> plugin_callback( 205 scoped_refptr<PluginResourceCallbackBase> plugin_callback(
176 new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback)); 206 new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback));
177 callbacks_.insert(std::make_pair(params.sequence(), plugin_callback)); 207 callbacks_.insert(std::make_pair(params.sequence(), plugin_callback));
178 params.set_has_callback(); 208 params.set_has_callback();
209
210 if (resource_reply_thread_registrar_) {
211 resource_reply_thread_registrar_->Register(
212 pp_resource(), params.sequence(), reply_thread_hint);
213 }
179 SendResourceCall(dest, params, msg); 214 SendResourceCall(dest, params, msg);
180 return params.sequence(); 215 return params.sequence();
181 } 216 }
182 217
183 template <class ReplyMsgClass> 218 template <class ReplyMsgClass>
184 int32_t PluginResource::SyncCall(Destination dest, const IPC::Message& msg) { 219 int32_t PluginResource::SyncCall(Destination dest, const IPC::Message& msg) {
185 IPC::Message reply; 220 IPC::Message reply;
186 ResourceMessageReplyParams reply_params; 221 ResourceMessageReplyParams reply_params;
187 return GenericSyncCall(dest, msg, &reply, &reply_params); 222 return GenericSyncCall(dest, msg, &reply, &reply_params);
188 } 223 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 279
245 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e)) 280 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e))
246 return result; 281 return result;
247 return PP_ERROR_FAILED; 282 return PP_ERROR_FAILED;
248 } 283 }
249 284
250 } // namespace proxy 285 } // namespace proxy
251 } // namespace ppapi 286 } // namespace ppapi
252 287
253 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ 288 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698