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

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

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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_LIB_ROUTER_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 21 matching lines...) Expand all
32 bool expects_sync_requests, 32 bool expects_sync_requests,
33 scoped_refptr<base::SingleThreadTaskRunner> runner); 33 scoped_refptr<base::SingleThreadTaskRunner> runner);
34 ~Router() override; 34 ~Router() override;
35 35
36 // Sets the receiver to handle messages read from the message pipe that do 36 // Sets the receiver to handle messages read from the message pipe that do
37 // not have the kMessageIsResponse flag set. 37 // not have the kMessageIsResponse flag set.
38 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { 38 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) {
39 incoming_receiver_ = receiver; 39 incoming_receiver_ = receiver;
40 } 40 }
41 41
42 // Sets the interface name for this Router. Used only for debugging.
43 void set_interface_name(const std::string& name) {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 interface_name_ = name;
46 }
47
42 // Sets the error handler to receive notifications when an error is 48 // Sets the error handler to receive notifications when an error is
43 // encountered while reading from the pipe or waiting to read from the pipe. 49 // encountered while reading from the pipe or waiting to read from the pipe.
44 void set_connection_error_handler(const Closure& error_handler) { 50 void set_connection_error_handler(const Closure& error_handler) {
45 error_handler_ = error_handler; 51 error_handler_ = error_handler;
46 } 52 }
47 53
48 // Returns true if an error was encountered while reading from the pipe or 54 // Returns true if an error was encountered while reading from the pipe or
49 // waiting to read from the pipe. 55 // waiting to read from the pipe.
50 bool encountered_error() const { 56 bool encountered_error() const {
51 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 12 matching lines...) Expand all
64 void CloseMessagePipe() { 70 void CloseMessagePipe() {
65 DCHECK(thread_checker_.CalledOnValidThread()); 71 DCHECK(thread_checker_.CalledOnValidThread());
66 connector_.CloseMessagePipe(); 72 connector_.CloseMessagePipe();
67 } 73 }
68 74
69 ScopedMessagePipeHandle PassMessagePipe() { 75 ScopedMessagePipeHandle PassMessagePipe() {
70 DCHECK(thread_checker_.CalledOnValidThread()); 76 DCHECK(thread_checker_.CalledOnValidThread());
71 return connector_.PassMessagePipe(); 77 return connector_.PassMessagePipe();
72 } 78 }
73 79
74 void RaiseError() { 80 void RaiseError(Result error) {
75 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
76 connector_.RaiseError(); 82 connector_.RaiseError(std::move(error));
77 } 83 }
78 84
79 // MessageReceiver implementation: 85 // MessageReceiver implementation:
80 bool Accept(Message* message) override; 86 Result Accept(Message* message) override;
81 bool AcceptWithResponder(Message* message, 87 Result AcceptWithResponder(Message* message,
82 MessageReceiver* responder) override; 88 MessageReceiver* responder) override;
83 89
84 // Blocks the current thread until the first incoming method call, i.e., 90 // Blocks the current thread until the first incoming method call, i.e.,
85 // either a call to a client method or a callback method, or |deadline|. 91 // either a call to a client method or a callback method, or |deadline|.
86 bool WaitForIncomingMessage(MojoDeadline deadline) { 92 bool WaitForIncomingMessage(MojoDeadline deadline) {
87 DCHECK(thread_checker_.CalledOnValidThread()); 93 DCHECK(thread_checker_.CalledOnValidThread());
88 return connector_.WaitForIncomingMessage(deadline); 94 return connector_.WaitForIncomingMessage(deadline);
89 } 95 }
90 96
91 // See Binding for details of pause/resume. 97 // See Binding for details of pause/resume.
92 void PauseIncomingMethodCallProcessing() { 98 void PauseIncomingMethodCallProcessing() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 }; 140 };
135 141
136 using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>; 142 using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>;
137 143
138 class HandleIncomingMessageThunk : public MessageReceiver { 144 class HandleIncomingMessageThunk : public MessageReceiver {
139 public: 145 public:
140 HandleIncomingMessageThunk(Router* router); 146 HandleIncomingMessageThunk(Router* router);
141 ~HandleIncomingMessageThunk() override; 147 ~HandleIncomingMessageThunk() override;
142 148
143 // MessageReceiver implementation: 149 // MessageReceiver implementation:
144 bool Accept(Message* message) override; 150 Result Accept(Message* message) override;
145 151
146 private: 152 private:
147 Router* router_; 153 Router* router_;
148 }; 154 };
149 155
150 bool HandleIncomingMessage(Message* message); 156 Result HandleIncomingMessage(Message* message);
151 void HandleQueuedMessages(); 157 void HandleQueuedMessages();
152 bool HandleMessageInternal(Message* message); 158 Result HandleMessageInternal(Message* message);
153 159
154 void OnConnectionError(); 160 void OnConnectionError();
155 161
156 HandleIncomingMessageThunk thunk_; 162 HandleIncomingMessageThunk thunk_;
157 FilterChain filters_; 163 FilterChain filters_;
158 Connector connector_; 164 Connector connector_;
159 MessageReceiverWithResponderStatus* incoming_receiver_; 165 MessageReceiverWithResponderStatus* incoming_receiver_;
160 AsyncResponderMap async_responders_; 166 AsyncResponderMap async_responders_;
161 SyncResponseMap sync_responses_; 167 SyncResponseMap sync_responses_;
162 uint64_t next_request_id_; 168 uint64_t next_request_id_;
163 bool testing_mode_; 169 bool testing_mode_;
170 std::string interface_name_;
164 std::queue<std::unique_ptr<Message>> pending_messages_; 171 std::queue<std::unique_ptr<Message>> pending_messages_;
165 // Whether a task has been posted to trigger processing of 172 // Whether a task has been posted to trigger processing of
166 // |pending_messages_|. 173 // |pending_messages_|.
167 bool pending_task_for_messages_; 174 bool pending_task_for_messages_;
168 bool encountered_error_; 175 bool encountered_error_;
169 Closure error_handler_; 176 Closure error_handler_;
170 base::ThreadChecker thread_checker_; 177 base::ThreadChecker thread_checker_;
171 base::WeakPtrFactory<Router> weak_factory_; 178 base::WeakPtrFactory<Router> weak_factory_;
172 }; 179 };
173 180
174 } // namespace internal 181 } // namespace internal
175 } // namespace mojo 182 } // namespace mojo
176 183
177 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ 184 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698