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

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

Issue 1701423002: Mojo C++ bindings: support sync methods - part 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/message_internal.h ('k') | mojo/public/cpp/bindings/lib/router.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
14 #include "mojo/public/cpp/bindings/callback.h" 15 #include "mojo/public/cpp/bindings/callback.h"
15 #include "mojo/public/cpp/bindings/lib/connector.h" 16 #include "mojo/public/cpp/bindings/lib/connector.h"
16 #include "mojo/public/cpp/bindings/lib/filter_chain.h" 17 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
17 #include "mojo/public/cpp/bindings/lib/shared_data.h"
18 #include "mojo/public/cpp/environment/environment.h" 18 #include "mojo/public/cpp/environment/environment.h"
19 19
20 namespace mojo { 20 namespace mojo {
21 namespace internal { 21 namespace internal {
22 22
23 class Router : public MessageReceiverWithResponder { 23 class Router : public MessageReceiverWithResponder {
24 public: 24 public:
25 Router(ScopedMessagePipeHandle message_pipe, 25 Router(ScopedMessagePipeHandle message_pipe,
26 FilterChain filters, 26 FilterChain filters,
27 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()); 27 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // - the object is more tolerant of unrecognized response messages; 97 // - the object is more tolerant of unrecognized response messages;
98 // - the connector continues working after seeing errors from its incoming 98 // - the connector continues working after seeing errors from its incoming
99 // receiver. 99 // receiver.
100 void EnableTestingMode(); 100 void EnableTestingMode();
101 101
102 MessagePipeHandle handle() const { return connector_.handle(); } 102 MessagePipeHandle handle() const { return connector_.handle(); }
103 103
104 // Returns true if this Router has any pending callbacks. 104 // Returns true if this Router has any pending callbacks.
105 bool has_pending_responders() const { 105 bool has_pending_responders() const {
106 DCHECK(thread_checker_.CalledOnValidThread()); 106 DCHECK(thread_checker_.CalledOnValidThread());
107 return !responders_.empty(); 107 return !async_responders_.empty() || !sync_responders_.empty();
108 } 108 }
109 109
110 private: 110 private:
111 // Maps from the id of a response to the MessageReceiver that handles the
112 // response.
111 typedef std::map<uint64_t, MessageReceiver*> ResponderMap; 113 typedef std::map<uint64_t, MessageReceiver*> ResponderMap;
112 114
113 class HandleIncomingMessageThunk : public MessageReceiver { 115 class HandleIncomingMessageThunk : public MessageReceiver {
114 public: 116 public:
115 HandleIncomingMessageThunk(Router* router); 117 HandleIncomingMessageThunk(Router* router);
116 ~HandleIncomingMessageThunk() override; 118 ~HandleIncomingMessageThunk() override;
117 119
118 // MessageReceiver implementation: 120 // MessageReceiver implementation:
119 bool Accept(Message* message) override; 121 bool Accept(Message* message) override;
120 122
121 private: 123 private:
122 Router* router_; 124 Router* router_;
123 }; 125 };
124 126
125 bool HandleIncomingMessage(Message* message); 127 bool HandleIncomingMessage(Message* message);
126 128
127 HandleIncomingMessageThunk thunk_; 129 HandleIncomingMessageThunk thunk_;
128 FilterChain filters_; 130 FilterChain filters_;
129 Connector connector_; 131 Connector connector_;
130 SharedData<Router*> weak_self_;
131 MessageReceiverWithResponderStatus* incoming_receiver_; 132 MessageReceiverWithResponderStatus* incoming_receiver_;
132 // Maps from the id of a response to the MessageReceiver that handles the 133 ResponderMap async_responders_;
133 // response. 134 ResponderMap sync_responders_;
134 ResponderMap responders_;
135 uint64_t next_request_id_; 135 uint64_t next_request_id_;
136 bool testing_mode_; 136 bool testing_mode_;
137 base::ThreadChecker thread_checker_; 137 base::ThreadChecker thread_checker_;
138 base::WeakPtrFactory<Router> weak_factory_;
138 }; 139 };
139 140
140 } // namespace internal 141 } // namespace internal
141 } // namespace mojo 142 } // namespace mojo
142 143
143 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_ 144 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ROUTER_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/message_internal.h ('k') | mojo/public/cpp/bindings/lib/router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698