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: mojo/public/cpp/bindings/message.h

Issue 2358133002: Turn //mojo/public/cpp/bindings and //mojo/public/cpp/system into components (Closed)
Patch Set: Fix wording Created 4 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <limits> 11 #include <limits>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/compiler_specific.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "mojo/public/cpp/bindings/bindings_export.h"
18 #include "mojo/public/cpp/bindings/lib/message_buffer.h" 20 #include "mojo/public/cpp/bindings/lib/message_buffer.h"
19 #include "mojo/public/cpp/bindings/lib/message_internal.h" 21 #include "mojo/public/cpp/bindings/lib/message_internal.h"
20 #include "mojo/public/cpp/system/message.h" 22 #include "mojo/public/cpp/system/message.h"
21 23
22 namespace mojo { 24 namespace mojo {
23 25
24 using ReportBadMessageCallback = base::Callback<void(const std::string& error)>; 26 using ReportBadMessageCallback = base::Callback<void(const std::string& error)>;
25 27
26 // Message is a holder for the data and handles to be sent over a MessagePipe. 28 // Message is a holder for the data and handles to be sent over a MessagePipe.
27 // Message owns its data and handles, but a consumer of Message is free to 29 // Message owns its data and handles, but a consumer of Message is free to
28 // mutate the data and handles. The message's data is comprised of a header 30 // mutate the data and handles. The message's data is comprised of a header
29 // followed by payload. 31 // followed by payload.
30 class Message { 32 class MOJO_CPP_BINDINGS_EXPORT Message {
31 public: 33 public:
32 static const uint32_t kFlagExpectsResponse = 1 << 0; 34 static const uint32_t kFlagExpectsResponse = 1 << 0;
33 static const uint32_t kFlagIsResponse = 1 << 1; 35 static const uint32_t kFlagIsResponse = 1 << 1;
34 static const uint32_t kFlagIsSync = 1 << 2; 36 static const uint32_t kFlagIsSync = 1 << 2;
35 37
36 Message(); 38 Message();
37 Message(Message&& other); 39 Message(Message&& other);
38 40
39 ~Message(); 41 ~Message();
40 42
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // |responder| and will delete it after calling |responder->Accept| or upon 195 // |responder| and will delete it after calling |responder->Accept| or upon
194 // its own destruction. 196 // its own destruction.
195 // 197 //
196 // TODO(yzshen): consider changing |responder| to 198 // TODO(yzshen): consider changing |responder| to
197 // std::unique_ptr<MessageReceiver>. 199 // std::unique_ptr<MessageReceiver>.
198 virtual bool AcceptWithResponder(Message* message, 200 virtual bool AcceptWithResponder(Message* message,
199 MessageReceiverWithStatus* responder) 201 MessageReceiverWithStatus* responder)
200 WARN_UNUSED_RESULT = 0; 202 WARN_UNUSED_RESULT = 0;
201 }; 203 };
202 204
203 class PassThroughFilter : public MessageReceiver { 205 class MOJO_CPP_BINDINGS_EXPORT PassThroughFilter
206 : NON_EXPORTED_BASE(public MessageReceiver) {
204 public: 207 public:
205 PassThroughFilter(); 208 PassThroughFilter();
206 ~PassThroughFilter() override; 209 ~PassThroughFilter() override;
207 210
208 // MessageReceiver: 211 // MessageReceiver:
209 bool Accept(Message* message) override; 212 bool Accept(Message* message) override;
210 213
211 private: 214 private:
212 DISALLOW_COPY_AND_ASSIGN(PassThroughFilter); 215 DISALLOW_COPY_AND_ASSIGN(PassThroughFilter);
213 }; 216 };
214 217
215 namespace internal { 218 namespace internal {
216 class SyncMessageResponseSetup; 219 class SyncMessageResponseSetup;
217 } 220 }
218 221
219 // An object which should be constructed on the stack immediately before making 222 // An object which should be constructed on the stack immediately before making
220 // a sync request for which the caller wishes to perform custom validation of 223 // a sync request for which the caller wishes to perform custom validation of
221 // the response value(s). It is illegal to make more than one sync call during 224 // the response value(s). It is illegal to make more than one sync call during
222 // the lifetime of the topmost SyncMessageResponseContext, but it is legal to 225 // the lifetime of the topmost SyncMessageResponseContext, but it is legal to
223 // nest contexts to support reentrancy. 226 // nest contexts to support reentrancy.
224 // 227 //
225 // Usage should look something like: 228 // Usage should look something like:
226 // 229 //
227 // SyncMessageResponseContext response_context; 230 // SyncMessageResponseContext response_context;
228 // foo_interface->SomeSyncCall(&response_value); 231 // foo_interface->SomeSyncCall(&response_value);
229 // if (response_value.IsBad()) 232 // if (response_value.IsBad())
230 // response_context.ReportBadMessage("Bad response_value!"); 233 // response_context.ReportBadMessage("Bad response_value!");
231 // 234 //
232 class SyncMessageResponseContext { 235 class MOJO_CPP_BINDINGS_EXPORT SyncMessageResponseContext {
233 public: 236 public:
234 SyncMessageResponseContext(); 237 SyncMessageResponseContext();
235 ~SyncMessageResponseContext(); 238 ~SyncMessageResponseContext();
236 239
237 static SyncMessageResponseContext* current(); 240 static SyncMessageResponseContext* current();
238 241
239 void ReportBadMessage(const std::string& error); 242 void ReportBadMessage(const std::string& error);
240 243
241 const ReportBadMessageCallback& GetBadMessageCallback(); 244 const ReportBadMessageCallback& GetBadMessageCallback();
242 245
(...skipping 14 matching lines...) Expand all
257 // dispatched, otherwise returns an error code if something went wrong. 260 // dispatched, otherwise returns an error code if something went wrong.
258 // 261 //
259 // NOTE: The message hasn't been validated and may be malformed! 262 // NOTE: The message hasn't been validated and may be malformed!
260 MojoResult ReadMessage(MessagePipeHandle handle, Message* message); 263 MojoResult ReadMessage(MessagePipeHandle handle, Message* message);
261 264
262 // Reports the currently dispatching Message as bad. Note that this is only 265 // Reports the currently dispatching Message as bad. Note that this is only
263 // legal to call from directly within the stack frame of a message dispatch. If 266 // legal to call from directly within the stack frame of a message dispatch. If
264 // you need to do asynchronous work before you can determine the legitimacy of 267 // you need to do asynchronous work before you can determine the legitimacy of
265 // a message, use TakeBadMessageCallback() and retain its result until you're 268 // a message, use TakeBadMessageCallback() and retain its result until you're
266 // ready to invoke or discard it. 269 // ready to invoke or discard it.
270 MOJO_CPP_BINDINGS_EXPORT
267 void ReportBadMessage(const std::string& error); 271 void ReportBadMessage(const std::string& error);
268 272
269 // Acquires a callback which may be run to report the currently dispatching 273 // Acquires a callback which may be run to report the currently dispatching
270 // Message as bad. Note that this is only legal to call from directly within the 274 // Message as bad. Note that this is only legal to call from directly within the
271 // stack frame of a message dispatch, but the returned callback may be called 275 // stack frame of a message dispatch, but the returned callback may be called
272 // exactly once any time thereafter to report the message as bad. This may only 276 // exactly once any time thereafter to report the message as bad. This may only
273 // be called once per message. 277 // be called once per message.
278 MOJO_CPP_BINDINGS_EXPORT
274 ReportBadMessageCallback GetBadMessageCallback(); 279 ReportBadMessageCallback GetBadMessageCallback();
275 280
276 } // namespace mojo 281 } // namespace mojo
277 282
278 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ 283 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | mojo/public/cpp/bindings/message_header_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698