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

Side by Side Diff: mojo/public/cpp/bindings/lib/interface_ptr_internal.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
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_LIB_INTERFACE_PTR_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 9
10 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
10 #include "mojo/public/cpp/bindings/lib/router.h" 11 #include "mojo/public/cpp/bindings/lib/router.h"
12 #include "mojo/public/cpp/bindings/lib/validator_chain.h"
11 13
12 namespace mojo { 14 namespace mojo {
13 namespace internal { 15 namespace internal {
14 16
15 template <typename Interface> 17 template <typename Interface>
16 class InterfacePtrState { 18 class InterfacePtrState {
17 public: 19 public:
18 InterfacePtrState() : instance_(NULL), client_(NULL), router_(NULL) {} 20 InterfacePtrState() : instance_(NULL), client_(NULL), router_(NULL) {}
19 21
20 ~InterfacePtrState() { 22 ~InterfacePtrState() {
(...skipping 19 matching lines...) Expand all
40 std::swap(other->instance_, instance_); 42 std::swap(other->instance_, instance_);
41 std::swap(other->client_, client_); 43 std::swap(other->client_, client_);
42 std::swap(other->router_, router_); 44 std::swap(other->router_, router_);
43 } 45 }
44 46
45 void ConfigureProxy(ScopedMessagePipeHandle handle, 47 void ConfigureProxy(ScopedMessagePipeHandle handle,
46 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { 48 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
47 assert(!instance_); 49 assert(!instance_);
48 assert(!router_); 50 assert(!router_);
49 51
50 router_ = new Router(handle.Pass(), waiter); 52 internal::ValidatorChain validators;
darin (slow to review) 2014/05/12 17:28:26 nit: already in the internal namespace
yzshen1 2014/05/12 21:59:58 Done.
53 validators.Append(new internal::MessageHeaderValidator)
54 .Append(new typename Interface::Client_::RequestValidator_)
55 .Append(new typename Interface::ResponseValidator_);
56
57 router_ = new Router(handle.Pass(), validators.Pass(), waiter);
51 ProxyWithStub* proxy = new ProxyWithStub(router_); 58 ProxyWithStub* proxy = new ProxyWithStub(router_);
52 router_->set_incoming_receiver(&proxy->stub); 59 router_->set_incoming_receiver(&proxy->stub);
53 60
54 instance_ = proxy; 61 instance_ = proxy;
55 } 62 }
56 63
57 void ConfigureStub(ScopedMessagePipeHandle handle, 64 void ConfigureStub(ScopedMessagePipeHandle handle,
yzshen1 2014/05/12 16:35:25 I think this code is not used anymore, is it?
darin (slow to review) 2014/05/12 17:28:26 Whoops, yes. I meant to delete that function and t
yzshen1 2014/05/12 21:59:58 Done.
58 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { 65 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) {
59 assert(instance_); // Should have already been set! 66 assert(instance_); // Should have already been set!
60 assert(!router_); 67 assert(!router_);
61 68
62 // Stub for binding to state_.instance 69 // Stub for binding to state_.instance
63 // Proxy for communicating to the client on the other end of the pipe. 70 // Proxy for communicating to the client on the other end of the pipe.
64 71
65 router_ = new Router(handle.Pass(), waiter); 72 internal::ValidatorChain validators;
73 validators.Append(new internal::MessageHeaderValidator)
74 .Append(new typename Interface::RequestValidator_)
75 .Append(new typename Interface::Client_::ResponseValidator_);
76
77 router_ = new Router(handle.Pass(), validators.Pass(), waiter);
66 ClientProxyWithStub* proxy = new ClientProxyWithStub(router_); 78 ClientProxyWithStub* proxy = new ClientProxyWithStub(router_);
67 proxy->stub.set_sink(instance_); 79 proxy->stub.set_sink(instance_);
68 router_->set_incoming_receiver(&proxy->stub); 80 router_->set_incoming_receiver(&proxy->stub);
69 81
70 instance_->SetClient(proxy); 82 instance_->SetClient(proxy);
71 client_ = proxy; 83 client_ = proxy;
72 } 84 }
73 85
74 private: 86 private:
75 class ProxyWithStub : public Interface::Proxy_ { 87 class ProxyWithStub : public Interface::Proxy_ {
(...skipping 23 matching lines...) Expand all
99 typename Interface::Client_* client_; 111 typename Interface::Client_* client_;
100 Router* router_; 112 Router* router_;
101 113
102 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); 114 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState);
103 }; 115 };
104 116
105 } // namespace internal 117 } // namespace internal
106 } // namespace mojo 118 } // namespace mojo
107 119
108 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ 120 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698