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

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: fix tests 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 template<typename ReplyMsgClass, typename CallbackType>
105 int32_t Call(Destination dest,
106 const IPC::Message& msg,
107 const CallbackType& callback,
108 scoped_refptr<TrackedCallback> reply_thread_hint);
109
102 // Calls the browser/renderer with sync messages. Returns the pepper error 110 // Calls the browser/renderer with sync messages. Returns the pepper error
103 // code from the call. 111 // code from the call.
104 // |ReplyMsgClass| is the type of the reply message that is expected. If it 112 // |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. 113 // carries x parameters, then the method with x out parameters should be used.
106 // An example of usage: 114 // An example of usage:
107 // 115 //
108 // // Assuming the reply message carries a string and an integer. 116 // // Assuming the reply message carries a string and an integer.
109 // std::string param_1; 117 // std::string param_1;
110 // int param_2 = 0; 118 // int param_2 = 0;
111 // int32_t result = SyncCall<PpapiPluginMsg_MyResourceType_MyReplyMessage>( 119 // 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. 160 // Use GetNextSequence to retrieve the next value.
153 int32_t next_sequence_number_; 161 int32_t next_sequence_number_;
154 162
155 bool sent_create_to_browser_; 163 bool sent_create_to_browser_;
156 bool sent_create_to_renderer_; 164 bool sent_create_to_renderer_;
157 165
158 typedef std::map<int32_t, scoped_refptr<PluginResourceCallbackBase> > 166 typedef std::map<int32_t, scoped_refptr<PluginResourceCallbackBase> >
159 CallbackMap; 167 CallbackMap;
160 CallbackMap callbacks_; 168 CallbackMap callbacks_;
161 169
170 scoped_refptr<ResourceReplyThreadRegistrar> resource_reply_thread_registrar_;
171
162 DISALLOW_COPY_AND_ASSIGN(PluginResource); 172 DISALLOW_COPY_AND_ASSIGN(PluginResource);
163 }; 173 };
164 174
165 template<typename ReplyMsgClass, typename CallbackType> 175 template<typename ReplyMsgClass, typename CallbackType>
166 int32_t PluginResource::Call(Destination dest, 176 int32_t PluginResource::Call(Destination dest,
167 const IPC::Message& msg, 177 const IPC::Message& msg,
168 const CallbackType& callback) { 178 const CallbackType& callback) {
179 return Call<ReplyMsgClass>(dest, msg, callback, NULL);
180 }
181
182 template<typename ReplyMsgClass, typename CallbackType>
183 int32_t PluginResource::Call(
184 Destination dest,
185 const IPC::Message& msg,
186 const CallbackType& callback,
187 scoped_refptr<TrackedCallback> reply_thread_hint) {
169 TRACE_EVENT2("ppapi proxy", "PluginResource::Call", 188 TRACE_EVENT2("ppapi proxy", "PluginResource::Call",
170 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), 189 "Class", IPC_MESSAGE_ID_CLASS(msg.type()),
171 "Line", IPC_MESSAGE_ID_LINE(msg.type())); 190 "Line", IPC_MESSAGE_ID_LINE(msg.type()));
172 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++); 191 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++);
173 // Stash the |callback| in |callbacks_| identified by the sequence number of 192 // Stash the |callback| in |callbacks_| identified by the sequence number of
174 // the call. 193 // the call.
175 scoped_refptr<PluginResourceCallbackBase> plugin_callback( 194 scoped_refptr<PluginResourceCallbackBase> plugin_callback(
176 new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback)); 195 new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback));
177 callbacks_.insert(std::make_pair(params.sequence(), plugin_callback)); 196 callbacks_.insert(std::make_pair(params.sequence(), plugin_callback));
178 params.set_has_callback(); 197 params.set_has_callback();
198
199 if (resource_reply_thread_registrar_) {
200 resource_reply_thread_registrar_->Register(
201 pp_resource(), params.sequence(), reply_thread_hint);
202 }
179 SendResourceCall(dest, params, msg); 203 SendResourceCall(dest, params, msg);
180 return params.sequence(); 204 return params.sequence();
181 } 205 }
182 206
183 template <class ReplyMsgClass> 207 template <class ReplyMsgClass>
184 int32_t PluginResource::SyncCall(Destination dest, const IPC::Message& msg) { 208 int32_t PluginResource::SyncCall(Destination dest, const IPC::Message& msg) {
185 IPC::Message reply; 209 IPC::Message reply;
186 ResourceMessageReplyParams reply_params; 210 ResourceMessageReplyParams reply_params;
187 return GenericSyncCall(dest, msg, &reply, &reply_params); 211 return GenericSyncCall(dest, msg, &reply, &reply_params);
188 } 212 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 268
245 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e)) 269 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e))
246 return result; 270 return result;
247 return PP_ERROR_FAILED; 271 return PP_ERROR_FAILED;
248 } 272 }
249 273
250 } // namespace proxy 274 } // namespace proxy
251 } // namespace ppapi 275 } // namespace ppapi
252 276
253 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ 277 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698