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

Side by Side Diff: ipc/mojo/async_handle_waiter.cc

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 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 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 #include "ipc/mojo/async_handle_waiter.h" 5 #include "ipc/mojo/async_handle_waiter.h"
6 6
7 #include "base/atomic_ref_count.h" 7 #include "base/atomic_ref_count.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12
13 #if defined(USE_CHROME_EDK)
14 #include "mojo/edk/embedder/embedder.h"
15 #else
12 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" 16 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
17 #endif
13 18
14 namespace IPC { 19 namespace IPC {
15 namespace internal { 20 namespace internal {
16 21
17 class AsyncHandleWaiterContextTraits { 22 class AsyncHandleWaiterContextTraits {
18 public: 23 public:
19 static void Destruct(const AsyncHandleWaiter::Context* context); 24 static void Destruct(const AsyncHandleWaiter::Context* context);
20 }; 25 };
21 26
22 // The thread-safe part of |AsyncHandleWaiter|. 27 // The thread-safe part of |AsyncHandleWaiter|.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 84
80 // IOObserver implementation: 85 // IOObserver implementation:
81 86
82 void WillProcessIOEvent() override { 87 void WillProcessIOEvent() override {
83 DCHECK(io_loop_level_ != 0 || !should_invoke_callback_); 88 DCHECK(io_loop_level_ != 0 || !should_invoke_callback_);
84 DCHECK_GE(io_loop_level_, 0); 89 DCHECK_GE(io_loop_level_, 0);
85 io_loop_level_++; 90 io_loop_level_++;
86 } 91 }
87 92
88 void DidProcessIOEvent() override { 93 void DidProcessIOEvent() override {
94 // This object could have been constructed in another's class's
95 // DidProcessIOEvent.
96 if (io_loop_level_== 0)
97 return;
98
89 DCHECK_GE(io_loop_level_, 1); 99 DCHECK_GE(io_loop_level_, 1);
90 100
91 // Leaving a nested loop. 101 // Leaving a nested loop.
92 if (io_loop_level_ > 1) { 102 if (io_loop_level_ > 1) {
93 io_loop_level_--; 103 io_loop_level_--;
94 return; 104 return;
95 } 105 }
96 106
97 // The zero |waiter_| indicates that |this| have lost the owner and can be 107 // The zero |waiter_| indicates that |this| have lost the owner and can be
98 // under destruction. So we cannot wrap it with a |scoped_refptr| anymore. 108 // under destruction. So we cannot wrap it with a |scoped_refptr| anymore.
(...skipping 30 matching lines...) Expand all
129 : callback_(callback), 139 : callback_(callback),
130 weak_factory_(this) { 140 weak_factory_(this) {
131 context_ = new Context(weak_factory_.GetWeakPtr()); 141 context_ = new Context(weak_factory_.GetWeakPtr());
132 } 142 }
133 143
134 AsyncHandleWaiter::~AsyncHandleWaiter() { 144 AsyncHandleWaiter::~AsyncHandleWaiter() {
135 } 145 }
136 146
137 MojoResult AsyncHandleWaiter::Wait(MojoHandle handle, 147 MojoResult AsyncHandleWaiter::Wait(MojoHandle handle,
138 MojoHandleSignals signals) { 148 MojoHandleSignals signals) {
149 #if defined(USE_CHROME_EDK)
150 return mojo::edk::AsyncWait(
151 handle, signals, base::Bind(&Context::HandleIsReady, context_));
152 #else
139 return mojo::embedder::AsyncWait( 153 return mojo::embedder::AsyncWait(
140 handle, signals, base::Bind(&Context::HandleIsReady, context_)); 154 handle, signals, base::Bind(&Context::HandleIsReady, context_));
155 #endif
141 } 156 }
142 157
143 void AsyncHandleWaiter::InvokeCallback(MojoResult result) { 158 void AsyncHandleWaiter::InvokeCallback(MojoResult result) {
144 callback_.Run(result); 159 callback_.Run(result);
145 } 160 }
146 161
147 base::MessageLoopForIO::IOObserver* AsyncHandleWaiter::GetIOObserverForTest() { 162 base::MessageLoopForIO::IOObserver* AsyncHandleWaiter::GetIOObserverForTest() {
148 return context_.get(); 163 return context_.get();
149 } 164 }
150 165
151 base::Callback<void(MojoResult)> AsyncHandleWaiter::GetWaitCallbackForTest() { 166 base::Callback<void(MojoResult)> AsyncHandleWaiter::GetWaitCallbackForTest() {
152 return base::Bind(&Context::HandleIsReady, context_); 167 return base::Bind(&Context::HandleIsReady, context_);
153 } 168 }
154 169
155 // static 170 // static
156 void AsyncHandleWaiterContextTraits::Destruct( 171 void AsyncHandleWaiterContextTraits::Destruct(
157 const AsyncHandleWaiter::Context* context) { 172 const AsyncHandleWaiter::Context* context) {
158 context->io_runner_->PostTask( 173 context->io_runner_->PostTask(
159 FROM_HERE, 174 FROM_HERE,
160 base::Bind(&base::DeletePointer<const AsyncHandleWaiter::Context>, 175 base::Bind(&base::DeletePointer<const AsyncHandleWaiter::Context>,
161 base::Unretained(context))); 176 base::Unretained(context)));
162 } 177 }
163 178
164 } // namespace internal 179 } // namespace internal
165 } // namespace IPC 180 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698