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

Side by Side Diff: mojo/edk/system/channel_posix.cc

Issue 2888053002: Rename TaskRunner::RunsTasksOnCurrentThread() in //extensions, //headless, //mojo (Closed)
Patch Set: rebase Created 3 years, 7 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 | « headless/public/util/generic_url_request_job.cc ('k') | mojo/edk/system/channel_win.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 io_task_runner_(io_task_runner) 96 io_task_runner_(io_task_runner)
97 #if defined(OS_MACOSX) 97 #if defined(OS_MACOSX)
98 , 98 ,
99 handles_to_close_(new PlatformHandleVector) 99 handles_to_close_(new PlatformHandleVector)
100 #endif 100 #endif
101 { 101 {
102 CHECK(handle_.is_valid()); 102 CHECK(handle_.is_valid());
103 } 103 }
104 104
105 void Start() override { 105 void Start() override {
106 if (io_task_runner_->RunsTasksOnCurrentThread()) { 106 if (io_task_runner_->RunsTasksInCurrentSequence()) {
107 StartOnIOThread(); 107 StartOnIOThread();
108 } else { 108 } else {
109 io_task_runner_->PostTask( 109 io_task_runner_->PostTask(
110 FROM_HERE, base::Bind(&ChannelPosix::StartOnIOThread, this)); 110 FROM_HERE, base::Bind(&ChannelPosix::StartOnIOThread, this));
111 } 111 }
112 } 112 }
113 113
114 void ShutDownImpl() override { 114 void ShutDownImpl() override {
115 // Always shut down asynchronously when called through the public interface. 115 // Always shut down asynchronously when called through the public interface.
116 io_task_runner_->PostTask( 116 io_task_runner_->PostTask(
(...skipping 15 matching lines...) Expand all
132 } 132 }
133 if (write_error) { 133 if (write_error) {
134 // Do not synchronously invoke OnError(). Write() may have been called by 134 // Do not synchronously invoke OnError(). Write() may have been called by
135 // the delegate and we don't want to re-enter it. 135 // the delegate and we don't want to re-enter it.
136 io_task_runner_->PostTask(FROM_HERE, 136 io_task_runner_->PostTask(FROM_HERE,
137 base::Bind(&ChannelPosix::OnError, this)); 137 base::Bind(&ChannelPosix::OnError, this));
138 } 138 }
139 } 139 }
140 140
141 void LeakHandle() override { 141 void LeakHandle() override {
142 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 142 DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
143 leak_handle_ = true; 143 leak_handle_ = true;
144 } 144 }
145 145
146 bool GetReadPlatformHandles( 146 bool GetReadPlatformHandles(
147 size_t num_handles, 147 size_t num_handles,
148 const void* extra_header, 148 const void* extra_header,
149 size_t extra_header_size, 149 size_t extra_header_size,
150 ScopedPlatformHandleVectorPtr* handles) override { 150 ScopedPlatformHandleVectorPtr* handles) override {
151 if (num_handles > std::numeric_limits<uint16_t>::max()) 151 if (num_handles > std::numeric_limits<uint16_t>::max())
152 return false; 152 return false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 void WaitForWriteOnIOThread() { 232 void WaitForWriteOnIOThread() {
233 base::AutoLock lock(write_lock_); 233 base::AutoLock lock(write_lock_);
234 WaitForWriteOnIOThreadNoLock(); 234 WaitForWriteOnIOThreadNoLock();
235 } 235 }
236 236
237 void WaitForWriteOnIOThreadNoLock() { 237 void WaitForWriteOnIOThreadNoLock() {
238 if (pending_write_) 238 if (pending_write_)
239 return; 239 return;
240 if (!write_watcher_) 240 if (!write_watcher_)
241 return; 241 return;
242 if (io_task_runner_->RunsTasksOnCurrentThread()) { 242 if (io_task_runner_->RunsTasksInCurrentSequence()) {
243 pending_write_ = true; 243 pending_write_ = true;
244 base::MessageLoopForIO::current()->WatchFileDescriptor( 244 base::MessageLoopForIO::current()->WatchFileDescriptor(
245 handle_.get().handle, false /* persistent */, 245 handle_.get().handle, false /* persistent */,
246 base::MessageLoopForIO::WATCH_WRITE, write_watcher_.get(), this); 246 base::MessageLoopForIO::WATCH_WRITE, write_watcher_.get(), this);
247 } else { 247 } else {
248 io_task_runner_->PostTask( 248 io_task_runner_->PostTask(
249 FROM_HERE, base::Bind(&ChannelPosix::WaitForWriteOnIOThread, this)); 249 FROM_HERE, base::Bind(&ChannelPosix::WaitForWriteOnIOThread, this));
250 } 250 }
251 } 251 }
252 252
253 void ShutDownOnIOThread() { 253 void ShutDownOnIOThread() {
254 base::MessageLoop::current()->RemoveDestructionObserver(this); 254 base::MessageLoop::current()->RemoveDestructionObserver(this);
255 255
256 read_watcher_.reset(); 256 read_watcher_.reset();
257 write_watcher_.reset(); 257 write_watcher_.reset();
258 if (leak_handle_) 258 if (leak_handle_)
259 ignore_result(handle_.release()); 259 ignore_result(handle_.release());
260 handle_.reset(); 260 handle_.reset();
261 #if defined(OS_MACOSX) 261 #if defined(OS_MACOSX)
262 handles_to_close_.reset(); 262 handles_to_close_.reset();
263 #endif 263 #endif
264 264
265 // May destroy the |this| if it was the last reference. 265 // May destroy the |this| if it was the last reference.
266 self_ = nullptr; 266 self_ = nullptr;
267 } 267 }
268 268
269 // base::MessageLoop::DestructionObserver: 269 // base::MessageLoop::DestructionObserver:
270 void WillDestroyCurrentMessageLoop() override { 270 void WillDestroyCurrentMessageLoop() override {
271 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 271 DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
272 if (self_) 272 if (self_)
273 ShutDownOnIOThread(); 273 ShutDownOnIOThread();
274 } 274 }
275 275
276 // base::MessageLoopForIO::Watcher: 276 // base::MessageLoopForIO::Watcher:
277 void OnFileCanReadWithoutBlocking(int fd) override { 277 void OnFileCanReadWithoutBlocking(int fd) override {
278 CHECK_EQ(fd, handle_.get().handle); 278 CHECK_EQ(fd, handle_.get().handle);
279 if (handle_.get().needs_connection) { 279 if (handle_.get().needs_connection) {
280 #if !defined(OS_NACL) 280 #if !defined(OS_NACL)
281 read_watcher_.reset(); 281 read_watcher_.reset();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 scoped_refptr<Channel> Channel::Create( 563 scoped_refptr<Channel> Channel::Create(
564 Delegate* delegate, 564 Delegate* delegate,
565 ConnectionParams connection_params, 565 ConnectionParams connection_params,
566 scoped_refptr<base::TaskRunner> io_task_runner) { 566 scoped_refptr<base::TaskRunner> io_task_runner) {
567 return new ChannelPosix(delegate, std::move(connection_params), 567 return new ChannelPosix(delegate, std::move(connection_params),
568 io_task_runner); 568 io_task_runner);
569 } 569 }
570 570
571 } // namespace edk 571 } // namespace edk
572 } // namespace mojo 572 } // namespace mojo
OLDNEW
« no previous file with comments | « headless/public/util/generic_url_request_job.cc ('k') | mojo/edk/system/channel_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698