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

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>
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
19 #include "mojo/public/cpp/bindings/callback.h" 19 #include "mojo/public/cpp/bindings/callback.h"
20 #include "mojo/public/cpp/bindings/error.h"
20 #include "mojo/public/cpp/bindings/message.h" 21 #include "mojo/public/cpp/bindings/message.h"
21 #include "mojo/public/cpp/bindings/message_filter.h" 22 #include "mojo/public/cpp/bindings/message_filter.h"
22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 23 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
23 24
24 namespace mojo { 25 namespace mojo {
25 26
26 class AssociatedGroup; 27 class AssociatedGroup;
27 28
28 namespace internal { 29 namespace internal {
29 30
(...skipping 30 matching lines...) Expand all
60 // Returns true if this endpoint has any pending callbacks. 61 // Returns true if this endpoint has any pending callbacks.
61 bool has_pending_responders() const { 62 bool has_pending_responders() const {
62 DCHECK(thread_checker_.CalledOnValidThread()); 63 DCHECK(thread_checker_.CalledOnValidThread());
63 return !async_responders_.empty() || !sync_responses_.empty(); 64 return !async_responders_.empty() || !sync_responses_.empty();
64 } 65 }
65 66
66 MultiplexRouter* router() const { return handle_.router(); } 67 MultiplexRouter* router() const { return handle_.router(); }
67 AssociatedGroup* associated_group(); 68 AssociatedGroup* associated_group();
68 uint32_t interface_id() const; 69 uint32_t interface_id() const;
69 70
71 void set_interface_name(const std::string& name) {
72 DCHECK(thread_checker_.CalledOnValidThread());
73 interface_name_ = name;
74 }
75
70 // After this call the object is in an invalid state and shouldn't be reused. 76 // After this call the object is in an invalid state and shouldn't be reused.
71 ScopedInterfaceEndpointHandle PassHandle(); 77 ScopedInterfaceEndpointHandle PassHandle();
72 78
73 // Raises an error on the underlying message pipe. It disconnects the pipe 79 // Raises an error on the underlying message pipe. It disconnects the pipe
74 // and notifies all interfaces running on this pipe. 80 // and notifies all interfaces running on this pipe.
75 void RaiseError(); 81 void RaiseError(Error error);
76 82
77 // MessageReceiverWithResponder implementation: 83 // MessageReceiverWithResponder implementation:
78 bool Accept(Message* message) override; 84 bool Accept(Message* message, Error* error) override;
79 bool AcceptWithResponder(Message* message, 85 bool AcceptWithResponder(Message* message,
80 MessageReceiver* responder) override; 86 MessageReceiver* responder,
87 Error* error) override;
81 88
82 // The following methods are called by the router. They must be called 89 // The following methods are called by the router. They must be called
83 // outside of the router's lock. 90 // outside of the router's lock. If this returns false, |*error| contains more
91 // information about the failure reason.
84 92
85 // NOTE: |message| must have passed message header validation. 93 // NOTE: |message| must have passed message header validation.
86 bool HandleIncomingMessage(Message* message); 94 bool HandleIncomingMessage(Message* message, Error* error);
87 void NotifyError(); 95 void NotifyError();
88 96
89 private: 97 private:
90 // Maps from the id of a response to the MessageReceiver that handles the 98 // Maps from the id of a response to the MessageReceiver that handles the
91 // response. 99 // response.
92 using AsyncResponderMap = 100 using AsyncResponderMap =
93 std::map<uint64_t, std::unique_ptr<MessageReceiver>>; 101 std::map<uint64_t, std::unique_ptr<MessageReceiver>>;
94 102
95 struct SyncResponseInfo { 103 struct SyncResponseInfo {
96 public: 104 public:
(...skipping 12 matching lines...) Expand all
109 using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>; 117 using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>;
110 118
111 // Used as the sink for |payload_validator_| and forwards messages to 119 // Used as the sink for |payload_validator_| and forwards messages to
112 // HandleValidatedMessage(). 120 // HandleValidatedMessage().
113 class HandleIncomingMessageThunk : public MessageReceiver { 121 class HandleIncomingMessageThunk : public MessageReceiver {
114 public: 122 public:
115 explicit HandleIncomingMessageThunk(InterfaceEndpointClient* owner); 123 explicit HandleIncomingMessageThunk(InterfaceEndpointClient* owner);
116 ~HandleIncomingMessageThunk() override; 124 ~HandleIncomingMessageThunk() override;
117 125
118 // MessageReceiver implementation: 126 // MessageReceiver implementation:
119 bool Accept(Message* message) override; 127 bool Accept(Message* message, Error* error) override;
120 128
121 private: 129 private:
122 InterfaceEndpointClient* const owner_; 130 InterfaceEndpointClient* const owner_;
123 131
124 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); 132 DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk);
125 }; 133 };
126 134
127 bool HandleValidatedMessage(Message* message); 135 bool HandleValidatedMessage(Message* message, Error* error);
128 136
129 ScopedInterfaceEndpointHandle handle_; 137 ScopedInterfaceEndpointHandle handle_;
130 std::unique_ptr<AssociatedGroup> associated_group_; 138 std::unique_ptr<AssociatedGroup> associated_group_;
131 InterfaceEndpointController* controller_; 139 InterfaceEndpointController* controller_;
132 140
133 MessageReceiverWithResponderStatus* const incoming_receiver_; 141 MessageReceiverWithResponderStatus* const incoming_receiver_;
134 std::unique_ptr<MessageFilter> payload_validator_; 142 std::unique_ptr<MessageFilter> payload_validator_;
135 HandleIncomingMessageThunk thunk_; 143 HandleIncomingMessageThunk thunk_;
136 144
137 AsyncResponderMap async_responders_; 145 AsyncResponderMap async_responders_;
138 SyncResponseMap sync_responses_; 146 SyncResponseMap sync_responses_;
139 147
140 uint64_t next_request_id_; 148 uint64_t next_request_id_;
141 149
142 Closure error_handler_; 150 Closure error_handler_;
143 bool encountered_error_; 151 bool encountered_error_;
144 152
153 // The name of the interface which is bound by this client. Used only for
154 // debugging purposes.
155 std::string interface_name_;
156
145 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 157 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
146 158
147 base::ThreadChecker thread_checker_; 159 base::ThreadChecker thread_checker_;
148 160
149 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_; 161 base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_;
150 162
151 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); 163 DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient);
152 }; 164 };
153 165
154 } // namespace internal 166 } // namespace internal
155 } // namespace mojo 167 } // namespace mojo
156 168
157 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_ 169 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_ENDPOINT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698