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

Side by Side Diff: ipc/ipc_message_templates.h

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: incorporated mmemke's comment Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 IPC_IPC_MESSAGE_TEMPLATES_H_ 5 #ifndef IPC_IPC_MESSAGE_TEMPLATES_H_
6 #define IPC_IPC_MESSAGE_TEMPLATES_H_ 6 #define IPC_IPC_MESSAGE_TEMPLATES_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 template <typename ObjT, typename P, typename... Args, typename... Ts> 45 template <typename ObjT, typename P, typename... Args, typename... Ts>
46 typename std::enable_if<sizeof...(Args) == sizeof...(Ts)>::type 46 typename std::enable_if<sizeof...(Args) == sizeof...(Ts)>::type
47 DispatchToMethod(ObjT* obj, 47 DispatchToMethod(ObjT* obj,
48 void (ObjT::*method)(P*, Args...), 48 void (ObjT::*method)(P*, Args...),
49 P* parameter, 49 P* parameter,
50 const std::tuple<Ts...>& tuple) { 50 const std::tuple<Ts...>& tuple) {
51 DispatchToMethodImpl(obj, method, parameter, tuple, 51 DispatchToMethodImpl(obj, method, parameter, tuple,
52 base::MakeIndexSequence<sizeof...(Ts)>()); 52 base::MakeIndexSequence<sizeof...(Ts)>());
53 } 53 }
54 54
55 // This function is for all the sync IPCs that don't pass an extra parameter
56 // using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
57 template <typename ObjT,
58 typename Method,
59 typename P,
60 typename Tuple,
61 typename ReplyParam>
62 void DispatchToSyncMethod(ObjT* obj,
63 Method method,
64 P*,
65 const Tuple& tuple,
66 ReplyParam* reply) {
67 base::DispatchToMethod(obj, method, tuple, reply);
68 }
69
70 template <typename ObjT,
71 typename Method,
72 typename P,
73 typename InTuple,
74 typename OutTuple,
75 size_t... InNs,
76 size_t... OutNs>
77 inline void DispatchToSyncMethodImpl(const ObjT& obj,
78 Method method,
79 P* parameter,
80 InTuple&& in,
81 OutTuple* out,
82 base::IndexSequence<InNs...>,
83 base::IndexSequence<OutNs...>) {
84 (obj->*method)(parameter, base::get<InNs>(std::forward<InTuple>(in))...,
85 &std::get<OutNs>(*out)...);
86 }
87
88 // The following function is for sync IPCs which have a dispatcher with an
89 // extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
90 template <typename ObjT,
91 typename P,
92 typename... Args,
93 typename... InParam,
94 typename... OutParam>
95 typename std::enable_if<sizeof...(Args) ==
96 sizeof...(InParam) + sizeof...(OutParam)>::type
97 DispatchToSyncMethod(ObjT* obj,
98 void (ObjT::*method)(P*, Args...),
99 P* parameter,
100 const std::tuple<InParam...>& in,
101 std::tuple<OutParam...>* out) {
102 DispatchToSyncMethodImpl(obj, method, parameter, in, out,
103 base::MakeIndexSequence<sizeof...(InParam)>(),
104 base::MakeIndexSequence<sizeof...(OutParam)>());
105 }
106
55 enum class MessageKind { 107 enum class MessageKind {
56 CONTROL, 108 CONTROL,
57 ROUTED, 109 ROUTED,
58 }; 110 };
59 111
60 // Routing is a helper struct so MessageT's private common constructor has a 112 // Routing is a helper struct so MessageT's private common constructor has a
61 // different type signature than the public "int32_t routing_id" one. 113 // different type signature than the public "int32_t routing_id" one.
62 struct Routing { 114 struct Routing {
63 explicit Routing(int32_t id) : id(id) {} 115 explicit Routing(int32_t id) : id(id) {}
64 int32_t id; 116 int32_t id;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 T* obj, 215 T* obj,
164 S* sender, 216 S* sender,
165 P* parameter, 217 P* parameter,
166 Method func) { 218 Method func) {
167 TRACE_EVENT0("ipc", Meta::kName); 219 TRACE_EVENT0("ipc", Meta::kName);
168 SendParam send_params; 220 SendParam send_params;
169 bool ok = ReadSendParam(msg, &send_params); 221 bool ok = ReadSendParam(msg, &send_params);
170 Message* reply = SyncMessage::GenerateReply(msg); 222 Message* reply = SyncMessage::GenerateReply(msg);
171 if (ok) { 223 if (ok) {
172 ReplyParam reply_params; 224 ReplyParam reply_params;
173 base::DispatchToMethod(obj, func, send_params, &reply_params); 225 DispatchToSyncMethod(obj, func, parameter, send_params, &reply_params);
174 WriteParam(reply, reply_params); 226 WriteParam(reply, reply_params);
175 LogReplyParamsToMessage(reply_params, msg); 227 LogReplyParamsToMessage(reply_params, msg);
176 } else { 228 } else {
177 NOTREACHED() << "Error deserializing message " << msg->type(); 229 NOTREACHED() << "Error deserializing message " << msg->type();
178 reply->set_reply_error(); 230 reply->set_reply_error();
179 } 231 }
180 sender->Send(reply); 232 sender->Send(reply);
181 return ok; 233 return ok;
182 } 234 }
183 235
184 template <class T, class P, class Method> 236 template <class T, class P, class Method>
185 static bool DispatchDelayReply(const Message* msg, 237 static bool DispatchDelayReply(const Message* msg,
186 T* obj, 238 T* obj,
187 P* parameter, 239 P* parameter,
188 Method func) { 240 Method func) {
189 TRACE_EVENT0("ipc", Meta::kName); 241 TRACE_EVENT0("ipc", Meta::kName);
190 SendParam send_params; 242 SendParam send_params;
191 bool ok = ReadSendParam(msg, &send_params); 243 bool ok = ReadSendParam(msg, &send_params);
192 Message* reply = SyncMessage::GenerateReply(msg); 244 Message* reply = SyncMessage::GenerateReply(msg);
193 if (ok) { 245 if (ok) {
194 std::tuple<Message&> t = std::tie(*reply); 246 std::tuple<Message&> t = std::tie(*reply);
195 ConnectMessageAndReply(msg, reply); 247 ConnectMessageAndReply(msg, reply);
196 base::DispatchToMethod(obj, func, send_params, &t); 248 DispatchToSyncMethod(obj, func, parameter, send_params, &t);
197 } else { 249 } else {
198 NOTREACHED() << "Error deserializing message " << msg->type(); 250 NOTREACHED() << "Error deserializing message " << msg->type();
199 reply->set_reply_error(); 251 reply->set_reply_error();
200 obj->Send(reply); 252 obj->Send(reply);
201 } 253 }
202 return ok; 254 return ok;
203 } 255 }
204 256
205 private: 257 private:
206 MessageT(Routing routing, const Ins&... ins, Outs*... outs); 258 MessageT(Routing routing, const Ins&... ins, Outs*... outs);
207 }; 259 };
208 260
209 } // namespace IPC 261 } // namespace IPC
210 262
211 #if defined(IPC_MESSAGE_IMPL) 263 #if defined(IPC_MESSAGE_IMPL)
212 #include "ipc/ipc_message_templates_impl.h" 264 #include "ipc/ipc_message_templates_impl.h"
213 #endif 265 #endif
214 266
215 #endif // IPC_IPC_MESSAGE_TEMPLATES_H_ 267 #endif // IPC_IPC_MESSAGE_TEMPLATES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698