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

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

Issue 1720093002: Revert of Mojo C++ bindings: support sync methods - part 2 (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/binding_state.h ('k') | mojo/public/cpp/bindings/lib/connector.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_CONNECTOR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/thread_checker.h" 9 #include "base/threading/thread_checker.h"
11 #include "mojo/public/c/environment/async_waiter.h" 10 #include "mojo/public/c/environment/async_waiter.h"
12 #include "mojo/public/cpp/bindings/callback.h" 11 #include "mojo/public/cpp/bindings/callback.h"
13 #include "mojo/public/cpp/bindings/message.h" 12 #include "mojo/public/cpp/bindings/message.h"
14 #include "mojo/public/cpp/environment/environment.h" 13 #include "mojo/public/cpp/environment/environment.h"
15 #include "mojo/public/cpp/system/core.h" 14 #include "mojo/public/cpp/system/core.h"
16 15
17 namespace base { 16 namespace base {
18 class Lock; 17 class Lock;
19 } 18 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void ResumeIncomingMethodCallProcessing(); 114 void ResumeIncomingMethodCallProcessing();
116 115
117 // MessageReceiver implementation: 116 // MessageReceiver implementation:
118 bool Accept(Message* message) override; 117 bool Accept(Message* message) override;
119 118
120 MessagePipeHandle handle() const { 119 MessagePipeHandle handle() const {
121 DCHECK(thread_checker_.CalledOnValidThread()); 120 DCHECK(thread_checker_.CalledOnValidThread());
122 return message_pipe_.get(); 121 return message_pipe_.get();
123 } 122 }
124 123
125 // Requests to register |message_pipe_| with SyncHandleWatcher whenever this
126 // instance is expecting incoming messages.
127 //
128 // Please note that UnregisterSyncHandleWatch() needs to be called as many
129 // times as successful RegisterSyncHandleWatch() calls in order to cancel the
130 // effect.
131 bool RegisterSyncHandleWatch();
132 void UnregisterSyncHandleWatch();
133
134 // Watches all handles registered with SyncHandleWatcher on the same thread.
135 // The method returns true when |*should_stop| is set to true; returns false
136 // when any failure occurs during the watch, including |message_pipe_| is
137 // closed.
138 bool RunSyncHandleWatch(const bool* should_stop);
139
140 // Whether currently the control flow is inside the sync handle watcher
141 // callback.
142 bool during_sync_handle_watcher_callback() const {
143 return sync_handle_watcher_callback_count_ > 0;
144 }
145
146 private: 124 private:
147 static void CallOnHandleReady(void* closure, MojoResult result); 125 static void CallOnHandleReady(void* closure, MojoResult result);
148 void OnSyncHandleWatcherHandleReady(MojoResult result); 126 void OnHandleReady(MojoResult result);
149 void OnHandleReadyInternal(MojoResult result);
150 127
151 void WaitToReadMore(); 128 void WaitToReadMore();
152 129
153 // Returns false if |this| was destroyed during message dispatch. 130 // Returns false if |this| was destroyed during message dispatch.
154 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); 131 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result);
155 132
156 // |this| can be destroyed during message dispatch. 133 // |this| can be destroyed during message dispatch.
157 void ReadAllAvailableMessages(); 134 void ReadAllAvailableMessages();
158 135
159 // If |force_pipe_reset| is true, this method replaces the existing 136 // If |force_pipe_reset| is true, this method replaces the existing
(...skipping 11 matching lines...) Expand all
171 ScopedMessagePipeHandle message_pipe_; 148 ScopedMessagePipeHandle message_pipe_;
172 MessageReceiver* incoming_receiver_; 149 MessageReceiver* incoming_receiver_;
173 150
174 MojoAsyncWaitID async_wait_id_; 151 MojoAsyncWaitID async_wait_id_;
175 bool error_; 152 bool error_;
176 bool drop_writes_; 153 bool drop_writes_;
177 bool enforce_errors_from_incoming_receiver_; 154 bool enforce_errors_from_incoming_receiver_;
178 155
179 bool paused_; 156 bool paused_;
180 157
158 // If non-null, this will be set to true when the Connector is destroyed. We
159 // use this flag to allow for the Connector to be destroyed as a side-effect
160 // of dispatching an incoming message.
161 bool* destroyed_flag_;
162
181 // If sending messages is allowed from multiple threads, |lock_| is used to 163 // If sending messages is allowed from multiple threads, |lock_| is used to
182 // protect modifications to |message_pipe_| and |drop_writes_|. 164 // protect modifications to |message_pipe_| and |drop_writes_|.
183 scoped_ptr<base::Lock> lock_; 165 scoped_ptr<base::Lock> lock_;
184 166
185 // If non-zero, |message_pipe_| should be registered with SyncHandleWatcher.
186 size_t register_sync_handle_watch_count_;
187 // Whether |message_pipe_| has been registered with SyncHandleWatcher.
188 bool registered_with_sync_handle_watcher_;
189 // If non-zero, currently the control flow is inside the sync handle watcher
190 // callback.
191 size_t sync_handle_watcher_callback_count_;
192
193 base::ThreadChecker thread_checker_; 167 base::ThreadChecker thread_checker_;
194 168
195 base::WeakPtrFactory<Connector> weak_factory_;
196
197 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); 169 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector);
198 }; 170 };
199 171
200 } // namespace internal 172 } // namespace internal
201 } // namespace mojo 173 } // namespace mojo
202 174
203 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ 175 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.h ('k') | mojo/public/cpp/bindings/lib/connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698