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

Side by Side Diff: mojo/public/cpp/bindings/lib/validator_chain.h

Issue 273233002: Mojo cpp bindings: add support for validating incoming messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase onto the InterfacePtr change 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATOR_CHAIN_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATOR_CHAIN_H_
7
8 #include <assert.h>
9
10 #include <vector>
11
12 #include "mojo/public/cpp/bindings/lib/message_validator.h"
13 #include "mojo/public/cpp/bindings/message.h"
14 #include "mojo/public/cpp/bindings/no_interface.h"
15 #include "mojo/public/cpp/system/macros.h"
16
17 namespace mojo {
18 namespace internal {
19
20 class ValidatorChain {
21 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(ValidatorChain, RValue)
22
23 public:
24 // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
25 // this object is alive. If |sink| is NULL, set_sink() has to be called to set
26 // a valid sink before this object can be used to validate messages.
27 explicit ValidatorChain(MessageReceiver* sink = NULL);
28
29 // Move-only constructor and operator=.
30 ValidatorChain(RValue other);
31 ValidatorChain& operator=(RValue other);
32
33 ~ValidatorChain();
34
35 // Takes ownership of |validator|.
36 ValidatorChain& Append(MessageValidator* validator);
37 ValidatorChain& Append(NoValidator* validator);
38
39 // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
40 // this object is alive.
41 void set_sink(MessageReceiver* sink) {
42 assert(!sink_);
43 sink_ = sink;
44 }
45
46 // Returns a receiver to accept messages for validation. Messages reach
47 // |sink_| only if they pass all the validators in the chain.
48 MessageReceiver* GetHead();
49
50 private:
51 // Owned by this object.
52 std::vector<MessageValidator*> validators_;
53
54 MessageReceiver* sink_;
55 };
56
57 } // namespace internal
58 } // namespace mojo
59
60 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATOR_CHAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698