OLD | NEW |
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/edk/system/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/uio.h> | 8 #include <sys/uio.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <deque> | 12 #include <deque> |
| 13 #include <memory> |
13 | 14 |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
19 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
20 #include "mojo/edk/embedder/platform_channel_utils_posix.h" | 21 #include "mojo/edk/embedder/platform_channel_utils_posix.h" |
21 #include "mojo/edk/embedder/platform_handle.h" | 22 #include "mojo/edk/embedder/platform_handle.h" |
22 #include "mojo/edk/embedder/platform_handle_vector.h" | 23 #include "mojo/edk/embedder/platform_handle_vector.h" |
(...skipping 25 matching lines...) Expand all Loading... |
48 const MessageInTransit::View& message_view) override; | 49 const MessageInTransit::View& message_view) override; |
49 IOResult Read(size_t* bytes_read) override; | 50 IOResult Read(size_t* bytes_read) override; |
50 IOResult ScheduleRead() override; | 51 IOResult ScheduleRead() override; |
51 embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( | 52 embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( |
52 size_t num_platform_handles, | 53 size_t num_platform_handles, |
53 const void* platform_handle_table) override; | 54 const void* platform_handle_table) override; |
54 IOResult WriteNoLock(size_t* platform_handles_written, | 55 IOResult WriteNoLock(size_t* platform_handles_written, |
55 size_t* bytes_written) override; | 56 size_t* bytes_written) override; |
56 IOResult ScheduleWriteNoLock() override; | 57 IOResult ScheduleWriteNoLock() override; |
57 void OnInit() override; | 58 void OnInit() override; |
58 void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, | 59 void OnShutdownNoLock(std::unique_ptr<ReadBuffer> read_buffer, |
59 scoped_ptr<WriteBuffer> write_buffer) override; | 60 std::unique_ptr<WriteBuffer> write_buffer) override; |
60 | 61 |
61 // |base::MessageLoopForIO::Watcher| implementation: | 62 // |base::MessageLoopForIO::Watcher| implementation: |
62 void OnFileCanReadWithoutBlocking(int fd) override; | 63 void OnFileCanReadWithoutBlocking(int fd) override; |
63 void OnFileCanWriteWithoutBlocking(int fd) override; | 64 void OnFileCanWriteWithoutBlocking(int fd) override; |
64 | 65 |
65 // Implements most of |Read()| (except for a bit of clean-up): | 66 // Implements most of |Read()| (except for a bit of clean-up): |
66 IOResult ReadImpl(size_t* bytes_read); | 67 IOResult ReadImpl(size_t* bytes_read); |
67 | 68 |
68 // Watches for |fd_| to become writable. Must be called on the I/O thread. | 69 // Watches for |fd_| to become writable. Must be called on the I/O thread. |
69 void WaitToWrite(); | 70 void WaitToWrite(); |
70 | 71 |
71 embedder::ScopedPlatformHandle fd_; | 72 embedder::ScopedPlatformHandle fd_; |
72 | 73 |
73 // The following members are only used on the I/O thread: | 74 // The following members are only used on the I/O thread: |
74 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> read_watcher_; | 75 std::unique_ptr<base::MessageLoopForIO::FileDescriptorWatcher> read_watcher_; |
75 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> write_watcher_; | 76 std::unique_ptr<base::MessageLoopForIO::FileDescriptorWatcher> write_watcher_; |
76 | 77 |
77 bool pending_read_; | 78 bool pending_read_; |
78 | 79 |
79 std::deque<embedder::PlatformHandle> read_platform_handles_; | 80 std::deque<embedder::PlatformHandle> read_platform_handles_; |
80 | 81 |
81 bool pending_write_ MOJO_GUARDED_BY(write_mutex()); | 82 bool pending_write_ MOJO_GUARDED_BY(write_mutex()); |
82 | 83 |
83 // This is used for posting tasks from write threads to the I/O thread. The | 84 // This is used for posting tasks from write threads to the I/O thread. The |
84 // weak pointers it produces are only used/invalidated on the I/O thread. | 85 // weak pointers it produces are only used/invalidated on the I/O thread. |
85 base::WeakPtrFactory<RawChannelPosix> weak_ptr_factory_ | 86 base::WeakPtrFactory<RawChannelPosix> weak_ptr_factory_ |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 321 |
321 // I don't know how this can fail (unless |fd_| is bad, in which case it's a | 322 // I don't know how this can fail (unless |fd_| is bad, in which case it's a |
322 // bug in our code). I also don't know if |WatchFileDescriptor()| actually | 323 // bug in our code). I also don't know if |WatchFileDescriptor()| actually |
323 // fails cleanly. | 324 // fails cleanly. |
324 CHECK(message_loop_for_io()->WatchFileDescriptor( | 325 CHECK(message_loop_for_io()->WatchFileDescriptor( |
325 fd_.get().fd, true, base::MessageLoopForIO::WATCH_READ, | 326 fd_.get().fd, true, base::MessageLoopForIO::WATCH_READ, |
326 read_watcher_.get(), this)); | 327 read_watcher_.get(), this)); |
327 } | 328 } |
328 | 329 |
329 void RawChannelPosix::OnShutdownNoLock( | 330 void RawChannelPosix::OnShutdownNoLock( |
330 scoped_ptr<ReadBuffer> /*read_buffer*/, | 331 std::unique_ptr<ReadBuffer> /*read_buffer*/, |
331 scoped_ptr<WriteBuffer> /*write_buffer*/) { | 332 std::unique_ptr<WriteBuffer> /*write_buffer*/) { |
332 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); | 333 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); |
333 write_mutex().AssertHeld(); | 334 write_mutex().AssertHeld(); |
334 | 335 |
335 read_watcher_.reset(); // This will stop watching (if necessary). | 336 read_watcher_.reset(); // This will stop watching (if necessary). |
336 write_watcher_.reset(); // This will stop watching (if necessary). | 337 write_watcher_.reset(); // This will stop watching (if necessary). |
337 | 338 |
338 pending_read_ = false; | 339 pending_read_ = false; |
339 pending_write_ = false; | 340 pending_write_ = false; |
340 | 341 |
341 DCHECK(fd_.is_valid()); | 342 DCHECK(fd_.is_valid()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 469 |
469 // Static factory method declared in raw_channel.h. | 470 // Static factory method declared in raw_channel.h. |
470 // static | 471 // static |
471 scoped_ptr<RawChannel> RawChannel::Create( | 472 scoped_ptr<RawChannel> RawChannel::Create( |
472 embedder::ScopedPlatformHandle handle) { | 473 embedder::ScopedPlatformHandle handle) { |
473 return make_scoped_ptr(new RawChannelPosix(handle.Pass())); | 474 return make_scoped_ptr(new RawChannelPosix(handle.Pass())); |
474 } | 475 } |
475 | 476 |
476 } // namespace system | 477 } // namespace system |
477 } // namespace mojo | 478 } // namespace mojo |
OLD | NEW |