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

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

Issue 11028104: Add template SyncCall() to PluginResource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync & resolve Created 8 years, 2 months 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/proxy/flash_resource.cc ('k') | ppapi/proxy/plugin_resource.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_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/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "ipc/ipc_message.h"
11 #include "ipc/ipc_sender.h" 13 #include "ipc/ipc_sender.h"
14 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/proxy/connection.h" 15 #include "ppapi/proxy/connection.h"
13 #include "ppapi/proxy/plugin_resource_callback.h" 16 #include "ppapi/proxy/plugin_resource_callback.h"
17 #include "ppapi/proxy/ppapi_message_utils.h"
14 #include "ppapi/proxy/ppapi_proxy_export.h" 18 #include "ppapi/proxy/ppapi_proxy_export.h"
15 #include "ppapi/shared_impl/resource.h" 19 #include "ppapi/shared_impl/resource.h"
16 20
17 namespace IPC {
18 class Message;
19 }
20
21 namespace ppapi { 21 namespace ppapi {
22 namespace proxy { 22 namespace proxy {
23 23
24 class PluginDispatcher; 24 class PluginDispatcher;
25 25
26 class PPAPI_PROXY_EXPORT PluginResource : public Resource { 26 class PPAPI_PROXY_EXPORT PluginResource : public Resource {
27 public: 27 public:
28 PluginResource(Connection connection, PP_Instance instance); 28 PluginResource(Connection connection, PP_Instance instance);
29 virtual ~PluginResource(); 29 virtual ~PluginResource();
30 30
31 // Returns true if we've previously sent a create message to the browser 31 // Returns true if we've previously sent a create message to the browser
32 // or renderer. Generally resources will use these to tell if they should 32 // or renderer. Generally resources will use these to tell if they should
33 // lazily send create messages. 33 // lazily send create messages.
34 bool sent_create_to_browser() const { return sent_create_to_browser_; } 34 bool sent_create_to_browser() const { return sent_create_to_browser_; }
35 bool sent_create_to_renderer() const { return sent_create_to_renderer_; } 35 bool sent_create_to_renderer() const { return sent_create_to_renderer_; }
36 36
37 // This handles a reply to a resource call. It works by looking up the 37 // This handles a reply to a resource call. It works by looking up the
38 // callback that was registered when CallBrowser/CallRenderer was called 38 // callback that was registered when CallBrowser/CallRenderer was called
39 // and calling it with |params| and |msg|. 39 // and calling it with |params| and |msg|.
40 virtual void OnReplyReceived(const proxy::ResourceMessageReplyParams& params, 40 virtual void OnReplyReceived(const proxy::ResourceMessageReplyParams& params,
41 const IPC::Message& msg) OVERRIDE; 41 const IPC::Message& msg) OVERRIDE;
42 protected: 42 protected:
43 enum Destination {
44 RENDERER = 0,
45 BROWSER = 1
46 };
47
48 IPC::Sender* GetSender(Destination dest) {
49 return dest == RENDERER ? connection_.renderer_sender :
50 connection_.browser_sender;
51 }
52
43 // Sends a create message to the browser or renderer for the current resource. 53 // Sends a create message to the browser or renderer for the current resource.
44 void SendCreateToBrowser(const IPC::Message& msg); 54 void SendCreateToBrowser(const IPC::Message& msg);
45 void SendCreateToRenderer(const IPC::Message& msg); 55 void SendCreateToRenderer(const IPC::Message& msg);
46 56
47 // Sends the given IPC message as a resource request to the host 57 // Sends the given IPC message as a resource request to the host
48 // corresponding to this resource object and does not expect a reply. 58 // corresponding to this resource object and does not expect a reply.
49 void PostToBrowser(const IPC::Message& msg); 59 void PostToBrowser(const IPC::Message& msg);
50 void PostToRenderer(const IPC::Message& msg); 60 void PostToRenderer(const IPC::Message& msg);
51 61
52 // Like PostToBrowser/Renderer but expects a response. |callback| is 62 // Like PostToBrowser/Renderer but expects a response. |callback| is
(...skipping 11 matching lines...) Expand all
64 // 74 //
65 // Returns the new request's sequence number which can be used to identify 75 // Returns the new request's sequence number which can be used to identify
66 // the callback. 76 // the callback.
67 // 77 //
68 // Note that all integers (including 0 and -1) are valid request IDs. 78 // Note that all integers (including 0 and -1) are valid request IDs.
69 template<typename ReplyMsgClass, typename CallbackType> 79 template<typename ReplyMsgClass, typename CallbackType>
70 int32_t CallBrowser(const IPC::Message& msg, const CallbackType& callback); 80 int32_t CallBrowser(const IPC::Message& msg, const CallbackType& callback);
71 template<typename ReplyMsgClass, typename CallbackType> 81 template<typename ReplyMsgClass, typename CallbackType>
72 int32_t CallRenderer(const IPC::Message& msg, const CallbackType& callback); 82 int32_t CallRenderer(const IPC::Message& msg, const CallbackType& callback);
73 83
74 // Call the browser/renderer with sync messages. The pepper error code from 84 // Calls the browser/renderer with sync messages. Returns the pepper error
75 // the call is returned and the reply message is stored in |reply_msg|. 85 // code from the call.
76 int32_t CallBrowserSync(const IPC::Message& msg, IPC::Message* reply_msg); 86 // |ReplyMsgClass| is the type of the reply message that is expected. If it
77 int32_t CallRendererSync(const IPC::Message& msg, IPC::Message* reply_msg); 87 // carries x parameters, then the method with x out parameters should be used.
88 // An example of usage:
89 //
90 // // Assuming the reply message carries a string and an integer.
91 // std::string param_1;
92 // int param_2 = 0;
93 // int32_t result = SyncCall<PpapiPluginMsg_MyResourceType_MyReplyMessage>(
94 // RENDERER, PpapiHostMsg_MyResourceType_MyRequestMessage(),
95 // &param_1, &param_2);
96 template <class ReplyMsgClass>
97 int32_t SyncCall(Destination dest, const IPC::Message& msg);
98 template <class ReplyMsgClass, class A>
99 int32_t SyncCall(Destination dest, const IPC::Message& msg, A* a);
100 template <class ReplyMsgClass, class A, class B>
101 int32_t SyncCall(Destination dest, const IPC::Message& msg, A* a, B* b);
102 template <class ReplyMsgClass, class A, class B, class C>
103 int32_t SyncCall(Destination dest, const IPC::Message& msg, A* a, B* b, C* c);
104 template <class ReplyMsgClass, class A, class B, class C, class D>
105 int32_t SyncCall(
106 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d);
107 template <class ReplyMsgClass, class A, class B, class C, class D, class E>
108 int32_t SyncCall(
109 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e);
78 110
79 private: 111 private:
80 // Helper function to send a |PpapiHostMsg_ResourceCall| to the given sender 112 // Helper function to send a |PpapiHostMsg_ResourceCall| to the given sender
81 // with |nested_msg| and |call_params|. 113 // with |nested_msg| and |call_params|.
82 bool SendResourceCall(IPC::Sender* sender, 114 bool SendResourceCall(IPC::Sender* sender,
83 const ResourceMessageCallParams& call_params, 115 const ResourceMessageCallParams& call_params,
84 const IPC::Message& nested_msg); 116 const IPC::Message& nested_msg);
85 117
86 // Helper function to make a Resource Call to a host with a callback. 118 // Helper function to make a Resource Call to a host with a callback.
87 template<typename ReplyMsgClass, typename CallbackType> 119 template<typename ReplyMsgClass, typename CallbackType>
88 int32_t CallHost(IPC::Sender* sender, 120 int32_t CallHost(IPC::Sender* sender,
89 const IPC::Message& msg, 121 const IPC::Message& msg,
90 const CallbackType& callback); 122 const CallbackType& callback);
91 123
124 int32_t GenericSyncCall(Destination dest,
125 const IPC::Message& msg,
126 IPC::Message* reply_msg);
127
92 Connection connection_; 128 Connection connection_;
93 129
94 int32_t next_sequence_number_; 130 int32_t next_sequence_number_;
95 131
96 bool sent_create_to_browser_; 132 bool sent_create_to_browser_;
97 bool sent_create_to_renderer_; 133 bool sent_create_to_renderer_;
98 134
99 typedef std::map<int32_t, scoped_refptr<PluginResourceCallbackBase> > 135 typedef std::map<int32_t, scoped_refptr<PluginResourceCallbackBase> >
100 CallbackMap; 136 CallbackMap;
101 CallbackMap callbacks_; 137 CallbackMap callbacks_;
(...skipping 24 matching lines...) Expand all
126 // Stash the |callback| in |callbacks_| identified by the sequence number of 162 // Stash the |callback| in |callbacks_| identified by the sequence number of
127 // the call. 163 // the call.
128 scoped_refptr<PluginResourceCallbackBase> plugin_callback( 164 scoped_refptr<PluginResourceCallbackBase> plugin_callback(
129 new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback)); 165 new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback));
130 callbacks_.insert(std::make_pair(params.sequence(), plugin_callback)); 166 callbacks_.insert(std::make_pair(params.sequence(), plugin_callback));
131 params.set_has_callback(); 167 params.set_has_callback();
132 SendResourceCall(sender, params, msg); 168 SendResourceCall(sender, params, msg);
133 return params.sequence(); 169 return params.sequence();
134 } 170 }
135 171
172 template <class ReplyMsgClass>
173 int32_t PluginResource::SyncCall(Destination dest, const IPC::Message& msg) {
174 IPC::Message reply;
175 return GenericSyncCall(dest, msg, &reply);
176 }
177
178 template <class ReplyMsgClass, class A>
179 int32_t PluginResource::SyncCall(
180 Destination dest, const IPC::Message& msg, A* a) {
181 IPC::Message reply;
182 int32_t result = GenericSyncCall(dest, msg, &reply);
183
184 if (UnpackMessage<ReplyMsgClass>(reply, a))
185 return result;
186 return PP_ERROR_FAILED;
187 }
188
189 template <class ReplyMsgClass, class A, class B>
190 int32_t PluginResource::SyncCall(
191 Destination dest, const IPC::Message& msg, A* a, B* b) {
192 IPC::Message reply;
193 int32_t result = GenericSyncCall(dest, msg, &reply);
194
195 if (UnpackMessage<ReplyMsgClass>(reply, a, b))
196 return result;
197 return PP_ERROR_FAILED;
198 }
199
200 template <class ReplyMsgClass, class A, class B, class C>
201 int32_t PluginResource::SyncCall(
202 Destination dest, const IPC::Message& msg, A* a, B* b, C* c) {
203 IPC::Message reply;
204 int32_t result = GenericSyncCall(dest, msg, &reply);
205
206 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c))
207 return result;
208 return PP_ERROR_FAILED;
209 }
210
211 template <class ReplyMsgClass, class A, class B, class C, class D>
212 int32_t PluginResource::SyncCall(
213 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d) {
214 IPC::Message reply;
215 int32_t result = GenericSyncCall(dest, msg, &reply);
216
217 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d))
218 return result;
219 return PP_ERROR_FAILED;
220 }
221
222 template <class ReplyMsgClass, class A, class B, class C, class D, class E>
223 int32_t PluginResource::SyncCall(
224 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e) {
225 IPC::Message reply;
226 int32_t result = GenericSyncCall(dest, msg, &reply);
227
228 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e))
229 return result;
230 return PP_ERROR_FAILED;
231 }
232
136 } // namespace proxy 233 } // namespace proxy
137 } // namespace ppapi 234 } // namespace ppapi
138 235
139 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ 236 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/flash_resource.cc ('k') | ppapi/proxy/plugin_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698