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

Side by Side Diff: mojo/public/cpp/bindings/sync_dispatcher.h

Issue 273233002: Mojo cpp bindings: add support for validating incoming messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
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_SYNC_DISPATCHER_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_
7 7
8 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
9 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
8 #include "mojo/public/cpp/system/core.h" 10 #include "mojo/public/cpp/system/core.h"
9 11
10 namespace mojo { 12 namespace mojo {
11 13
12 class MessageReceiver; 14 class MessageReceiver;
13 15
14 // Waits for one message to arrive on the message pipe, and dispatch it to the 16 // Waits for one message to arrive on the message pipe, and dispatch it to the
15 // receiver. Returns true on success, false on failure. 17 // receiver. Returns true on success, false on failure.
18 //
19 // NOTE: The message hasn't been validated and may be malformed!
16 bool WaitForMessageAndDispatch(MessagePipeHandle handle, 20 bool WaitForMessageAndDispatch(MessagePipeHandle handle,
17 mojo::MessageReceiver* receiver); 21 mojo::MessageReceiver* receiver);
18 22
19 template<typename Interface> class SyncDispatcher { 23 template<typename Interface> class SyncDispatcher {
20 public: 24 public:
21 SyncDispatcher(ScopedMessagePipeHandle message_pipe, Interface* sink) 25 SyncDispatcher(ScopedMessagePipeHandle message_pipe, Interface* sink)
22 : message_pipe_(message_pipe.Pass()) { 26 : message_pipe_(message_pipe.Pass()) {
23 stub_.set_sink(sink); 27 stub_.set_sink(sink);
28
29 validators_.Append(new internal::MessageHeaderValidator)
darin (slow to review) 2014/05/14 06:51:51 nit: validators_ -> filters_
yzshen1 2014/05/14 08:14:03 Done. (I was thinking validators_ is a more specif
30 .Append(new typename Interface::RequestValidator_);
31 validators_.set_sink(&stub_);
24 } 32 }
25 33
26 bool WaitAndDispatchOneMessage() { 34 bool WaitAndDispatchOneMessage() {
27 return WaitForMessageAndDispatch(message_pipe_.get(), &stub_); 35 return WaitForMessageAndDispatch(message_pipe_.get(),
36 validators_.GetHead());
28 } 37 }
29 38
30 private: 39 private:
31 ScopedMessagePipeHandle message_pipe_; 40 ScopedMessagePipeHandle message_pipe_;
32 typename Interface::Stub_ stub_; 41 typename Interface::Stub_ stub_;
42 internal::FilterChain validators_;
33 }; 43 };
34 44
35 } // namespace mojo 45 } // namespace mojo
36 46
37 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_ 47 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698