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

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

Issue 2744943002: Mojo: Move waiting APIs to public library (Closed)
Patch Set: . Created 3 years, 9 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 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 #include "mojo/public/cpp/bindings/connector.h" 5 #include "mojo/public/cpp/bindings/connector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "mojo/public/cpp/bindings/lib/may_auto_lock.h" 15 #include "mojo/public/cpp/bindings/lib/may_auto_lock.h"
16 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" 16 #include "mojo/public/cpp/bindings/sync_handle_watcher.h"
17 #include "mojo/public/cpp/system/wait.h"
17 18
18 namespace mojo { 19 namespace mojo {
19 20
20 Connector::Connector(ScopedMessagePipeHandle message_pipe, 21 Connector::Connector(ScopedMessagePipeHandle message_pipe,
21 ConnectorConfig config, 22 ConnectorConfig config,
22 scoped_refptr<base::SingleThreadTaskRunner> runner) 23 scoped_refptr<base::SingleThreadTaskRunner> runner)
23 : message_pipe_(std::move(message_pipe)), 24 : message_pipe_(std::move(message_pipe)),
24 task_runner_(std::move(runner)), 25 task_runner_(std::move(runner)),
25 weak_factory_(this) { 26 weak_factory_(this) {
26 if (config == MULTI_THREADED_SEND) 27 if (config == MULTI_THREADED_SEND)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 71 }
71 72
72 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { 73 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) {
73 DCHECK(thread_checker_.CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
74 75
75 if (error_) 76 if (error_)
76 return false; 77 return false;
77 78
78 ResumeIncomingMethodCallProcessing(); 79 ResumeIncomingMethodCallProcessing();
79 80
80 MojoResult rv = 81 // TODO(rockot): Use a timed Wait here. Nobody uses anything but 0 or
81 Wait(message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, deadline, nullptr); 82 // INDEFINITE deadlines at present, so we only support those.
82 if (rv == MOJO_RESULT_SHOULD_WAIT || rv == MOJO_RESULT_DEADLINE_EXCEEDED) 83 DCHECK(deadline == 0 || deadline == MOJO_DEADLINE_INDEFINITE);
84
85 MojoResult rv = MOJO_RESULT_UNKNOWN;
86 if (deadline == 0 && !message_pipe_->QuerySignalsState().readable()) {
83 return false; 87 return false;
84 if (rv != MOJO_RESULT_OK) { 88 } else if (deadline == MOJO_DEADLINE_INDEFINITE) {
yzshen1 2017/03/17 17:10:27 nit: no need to use "else" here.
Ken Rockot(use gerrit already) 2017/03/17 17:58:51 Done
85 // Users that call WaitForIncomingMessage() should expect their code to be 89 rv = Wait(message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE);
86 // re-entered, so we call the error handler synchronously. 90 if (rv != MOJO_RESULT_OK) {
87 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); 91 // Users that call WaitForIncomingMessage() should expect their code to be
88 return false; 92 // re-entered, so we call the error handler synchronously.
93 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false);
94 return false;
95 }
89 } 96 }
97
90 ignore_result(ReadSingleMessage(&rv)); 98 ignore_result(ReadSingleMessage(&rv));
91 return (rv == MOJO_RESULT_OK); 99 return (rv == MOJO_RESULT_OK);
92 } 100 }
93 101
94 void Connector::PauseIncomingMethodCallProcessing() { 102 void Connector::PauseIncomingMethodCallProcessing() {
95 DCHECK(thread_checker_.CalledOnValidThread()); 103 DCHECK(thread_checker_.CalledOnValidThread());
96 104
97 if (paused_) 105 if (paused_)
98 return; 106 return;
99 107
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 void Connector::EnsureSyncWatcherExists() { 378 void Connector::EnsureSyncWatcherExists() {
371 if (sync_watcher_) 379 if (sync_watcher_)
372 return; 380 return;
373 sync_watcher_.reset(new SyncHandleWatcher( 381 sync_watcher_.reset(new SyncHandleWatcher(
374 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, 382 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE,
375 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, 383 base::Bind(&Connector::OnSyncHandleWatcherHandleReady,
376 base::Unretained(this)))); 384 base::Unretained(this))));
377 } 385 }
378 386
379 } // namespace mojo 387 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698