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

Side by Side Diff: mojo/public/cpp/bindings/lib/interface_endpoint_client.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_ENDPOINT_CLIENT_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // Returns true if this endpoint has any pending callbacks. 60 // Returns true if this endpoint has any pending callbacks.
61 bool has_pending_responders() const { 61 bool has_pending_responders() const {
62 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
63 return !async_responders_.empty() || !sync_responses_.empty(); 63 return !async_responders_.empty() || !sync_responses_.empty();
64 } 64 }
65 65
66 MultiplexRouter* router() const { return handle_.router(); } 66 MultiplexRouter* router() const { return handle_.router(); }
67 AssociatedGroup* associated_group(); 67 AssociatedGroup* associated_group();
68 uint32_t interface_id() const; 68 uint32_t interface_id() const;
69 69
70 void set_interface_name(const std::string& name) {
71 DCHECK(thread_checker_.CalledOnValidThread());
72 interface_name_ = name;
73 }
74
70 // After this call the object is in an invalid state and shouldn't be reused. 75 // After this call the object is in an invalid state and shouldn't be reused.
71 ScopedInterfaceEndpointHandle PassHandle(); 76 ScopedInterfaceEndpointHandle PassHandle();
72 77
73 // Raises an error on the underlying message pipe. It disconnects the pipe 78 // Raises an error on the underlying message pipe. It disconnects the pipe
74 // and notifies all interfaces running on this pipe. 79 // and notifies all interfaces running on this pipe.
75 void RaiseError(); 80 void RaiseError(Result error);
76 81
77 // MessageReceiverWithResponder implementation: 82 // MessageReceiverWithResponder implementation:
78 bool Accept(Message* message) override; 83 Result Accept(Message* message) override;
79 bool AcceptWithResponder(Message* message, 84 Result AcceptWithResponder(Message* message,
80 MessageReceiver* responder) override; 85 MessageReceiver* responder) override;
81 86
82 // The following methods are called by the router. They must be called 87 // The following methods are called by the router. They must be called
83 // outside of the router's lock. 88 // outside of the router's lock.
84 89
85 // NOTE: |message| must have passed message header validation. 90 // NOTE: |message| must have passed message header validation.
86 bool HandleIncomingMessage(Message* message); 91 Result HandleIncomingMessage(Message* message);
87 void NotifyError(); 92 void NotifyError();
88 93
89 private: 94 private:
90 // Maps from the id of a response to the MessageReceiver that handles the 95 // Maps from the id of a response to the MessageReceiver that handles the
91 // response. 96 // response.
92 using AsyncResponderMap = 97 using AsyncResponderMap =
93 std::map<uint64_t, std::unique_ptr<MessageReceiver>>; 98 std::map<uint64_t, std::unique_ptr<MessageReceiver>>;
94 99
95 struct SyncResponseInfo { 100 struct SyncResponseInfo {
96 public: 101 public:
(...skipping 12 matching lines...) Expand all
109 using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>; 114 using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>;
110 115
111 // Used as the sink for |payload_validator_| and forwards messages to 116 // Used as the sink for |payload_validator_| and forwards messages to
112 // HandleValidatedMessage(). 117 // HandleValidatedMessage().
113 class HandleIncomingMessageThunk : public MessageReceiver { 118 class HandleIncomingMessageThunk : public MessageReceiver {
114 public: 119 public:
115 explicit HandleIncomingMessageThunk(InterfaceEndpointClient* owner); 120 explicit HandleIncomingMessageThunk(InterfaceEndpointClient* owner);
116 ~HandleIncomingMessageThunk() override; 121 ~HandleIncomingMessageThunk() override;
117 122
118 // MessageReceiver implementation: 123 // MessageReceiver implementation:
119 bool Accept(Message* message) override; 124 Result Accept(Message* message) override;
120 125
121 private: 126 private:
122 InterfaceEndpointClient* const owner_; 127 InterfaceEndpointClient* const owner_;
123 128
124 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); 129 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk);
125 }; 130 };
126 131
127 bool HandleValidatedMessage(Message* message); 132 Result HandleValidatedMessage(Message* message);
128 133
129 ScopedInterfaceEndpointHandle handle_; 134 ScopedInterfaceEndpointHandle handle_;
130 std::unique_ptr<AssociatedGroup> associated_group_; 135 std::unique_ptr<AssociatedGroup> associated_group_;
131 InterfaceEndpointController* controller_; 136 InterfaceEndpointController* controller_;
132 137
133 MessageReceiverWithResponderStatus* const incoming_receiver_; 138 MessageReceiverWithResponderStatus* const incoming_receiver_;
134 std::unique_ptr<MessageFilter> payload_validator_; 139 std::unique_ptr<MessageFilter> payload_validator_;
135 HandleIncomingMessageThunk thunk_; 140 HandleIncomingMessageThunk thunk_;
136 141
137 AsyncResponderMap async_responders_; 142 AsyncResponderMap async_responders_;
138 SyncResponseMap sync_responses_; 143 SyncResponseMap sync_responses_;
139 144
140 uint64_t next_request_id_; 145 uint64_t next_request_id_;
141 146
142 Closure error_handler_; 147 Closure error_handler_;
143 bool encountered_error_; 148 bool encountered_error_;
144 149
150 // The name of the interface which is bound by this client. Used only for
151 // debugging purposes.
152 std::string interface_name_;
153
145 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 154 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
146 155
147 base::ThreadChecker thread_checker_; 156 base::ThreadChecker thread_checker_;
148 157
149 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; 158 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_;
150 159
151 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); 160 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient);
152 }; 161 };
153 162
154 } // namespace internal 163 } // namespace internal
155 } // namespace mojo 164 } // namespace mojo
156 165
157 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ 166 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698