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

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

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: Created 4 years, 3 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>
11 #include <memory> 11 #include <memory>
12 #include <queue> 12 #include <queue>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
20 #include "mojo/public/cpp/bindings/connector.h" 20 #include "mojo/public/cpp/bindings/connector.h"
21 #include "mojo/public/cpp/bindings/filter_chain.h" 21 #include "mojo/public/cpp/bindings/filter_chain.h"
22 #include "mojo/public/cpp/bindings/lib/control_message_handler.h"
23 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
22 #include "mojo/public/cpp/bindings/message.h" 24 #include "mojo/public/cpp/bindings/message.h"
23 25
24 namespace mojo { 26 namespace mojo {
25 namespace internal { 27 namespace internal {
26 28
27 // TODO(yzshen): Consider removing this class and use MultiplexRouter in all 29 // TODO(yzshen): Consider removing this class and use MultiplexRouter in all
28 // cases. crbug.com/594244 30 // cases. crbug.com/594244
29 class Router : public MessageReceiverWithResponder { 31 class Router : public MessageReceiverWithResponder {
30 public: 32 public:
31 Router(ScopedMessagePipeHandle message_pipe, 33 Router(ScopedMessagePipeHandle message_pipe,
32 FilterChain filters, 34 FilterChain filters,
33 bool expects_sync_requests, 35 bool expects_sync_requests,
34 scoped_refptr<base::SingleThreadTaskRunner> runner); 36 scoped_refptr<base::SingleThreadTaskRunner> runner,
37 int interface_version);
35 ~Router() override; 38 ~Router() override;
36 39
37 // Sets the receiver to handle messages read from the message pipe that do 40 // Sets the receiver to handle messages read from the message pipe that do
38 // not have the Message::kFlagIsResponse flag set. 41 // not have the Message::kFlagIsResponse flag set.
39 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) { 42 void set_incoming_receiver(MessageReceiverWithResponderStatus* receiver) {
40 incoming_receiver_ = receiver; 43 incoming_receiver_ = receiver;
41 } 44 }
42 45
43 // Sets the error handler to receive notifications when an error is 46 // Sets the error handler to receive notifications when an error is
44 // encountered while reading from the pipe or waiting to read from the pipe. 47 // encountered while reading from the pipe or waiting to read from the pipe.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 void EnableTestingMode(); 114 void EnableTestingMode();
112 115
113 MessagePipeHandle handle() const { return connector_.handle(); } 116 MessagePipeHandle handle() const { return connector_.handle(); }
114 117
115 // Returns true if this Router has any pending callbacks. 118 // Returns true if this Router has any pending callbacks.
116 bool has_pending_responders() const { 119 bool has_pending_responders() const {
117 DCHECK(thread_checker_.CalledOnValidThread()); 120 DCHECK(thread_checker_.CalledOnValidThread());
118 return !async_responders_.empty() || !sync_responses_.empty(); 121 return !async_responders_.empty() || !sync_responses_.empty();
119 } 122 }
120 123
124 ControlMessageProxy* control_message_proxy() {
125 return &control_message_proxy_;
126 }
127
121 private: 128 private:
122 // Maps from the id of a response to the MessageReceiver that handles the 129 // Maps from the id of a response to the MessageReceiver that handles the
123 // response. 130 // response.
124 using AsyncResponderMap = 131 using AsyncResponderMap =
125 std::map<uint64_t, std::unique_ptr<MessageReceiver>>; 132 std::map<uint64_t, std::unique_ptr<MessageReceiver>>;
126 133
127 struct SyncResponseInfo { 134 struct SyncResponseInfo {
128 public: 135 public:
129 explicit SyncResponseInfo(bool* in_response_received); 136 explicit SyncResponseInfo(bool* in_response_received);
130 ~SyncResponseInfo(); 137 ~SyncResponseInfo();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 AsyncResponderMap async_responders_; 172 AsyncResponderMap async_responders_;
166 SyncResponseMap sync_responses_; 173 SyncResponseMap sync_responses_;
167 uint64_t next_request_id_; 174 uint64_t next_request_id_;
168 bool testing_mode_; 175 bool testing_mode_;
169 std::queue<Message> pending_messages_; 176 std::queue<Message> pending_messages_;
170 // Whether a task has been posted to trigger processing of 177 // Whether a task has been posted to trigger processing of
171 // |pending_messages_|. 178 // |pending_messages_|.
172 bool pending_task_for_messages_; 179 bool pending_task_for_messages_;
173 bool encountered_error_; 180 bool encountered_error_;
174 base::Closure error_handler_; 181 base::Closure error_handler_;
182 ControlMessageProxy control_message_proxy_;
183 ControlMessageHandler control_message_handler_;
175 base::ThreadChecker thread_checker_; 184 base::ThreadChecker thread_checker_;
176 base::WeakPtrFactory<Router> weak_factory_; 185 base::WeakPtrFactory<Router> weak_factory_;
177 }; 186 };
178 187
179 } // namespace internal 188 } // namespace internal
180 } // namespace mojo 189 } // namespace mojo
181 190
182 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ 191 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698