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/system/raw_channel.h" | 5 #include "mojo/system/raw_channel.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <sys/uio.h> | 10 #include <sys/uio.h> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "mojo/embedder/platform_handle.h" | 26 #include "mojo/embedder/platform_handle.h" |
27 | 27 |
28 namespace mojo { | 28 namespace mojo { |
29 namespace system { | 29 namespace system { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 class RawChannelPosix : public RawChannel, | 33 class RawChannelPosix : public RawChannel, |
34 public base::MessageLoopForIO::Watcher { | 34 public base::MessageLoopForIO::Watcher { |
35 public: | 35 public: |
36 RawChannelPosix(embedder::ScopedPlatformHandle handle, | 36 RawChannelPosix(embedder::ScopedPlatformHandle handle); |
37 Delegate* delegate, | |
38 base::MessageLoopForIO* message_loop_for_io); | |
39 virtual ~RawChannelPosix(); | 37 virtual ~RawChannelPosix(); |
40 | 38 |
41 private: | 39 private: |
42 // |RawChannel| implementation: | 40 // |RawChannel| implementation: |
43 virtual IOResult Read(size_t* bytes_read) OVERRIDE; | 41 virtual IOResult Read(size_t* bytes_read) OVERRIDE; |
44 virtual IOResult ScheduleRead() OVERRIDE; | 42 virtual IOResult ScheduleRead() OVERRIDE; |
45 virtual IOResult WriteNoLock(size_t* bytes_written) OVERRIDE; | 43 virtual IOResult WriteNoLock(size_t* bytes_written) OVERRIDE; |
46 virtual IOResult ScheduleWriteNoLock() OVERRIDE; | 44 virtual IOResult ScheduleWriteNoLock() OVERRIDE; |
47 virtual bool OnInit() OVERRIDE; | 45 virtual bool OnInit() OVERRIDE; |
48 virtual void OnShutdownNoLock( | 46 virtual void OnShutdownNoLock( |
(...skipping 20 matching lines...) Expand all Loading... |
69 bool pending_write_; | 67 bool pending_write_; |
70 | 68 |
71 // This is used for posting tasks from write threads to the I/O thread. It | 69 // This is used for posting tasks from write threads to the I/O thread. It |
72 // must only be accessed under |write_lock_|. The weak pointers it produces | 70 // must only be accessed under |write_lock_|. The weak pointers it produces |
73 // are only used/invalidated on the I/O thread. | 71 // are only used/invalidated on the I/O thread. |
74 base::WeakPtrFactory<RawChannelPosix> weak_ptr_factory_; | 72 base::WeakPtrFactory<RawChannelPosix> weak_ptr_factory_; |
75 | 73 |
76 DISALLOW_COPY_AND_ASSIGN(RawChannelPosix); | 74 DISALLOW_COPY_AND_ASSIGN(RawChannelPosix); |
77 }; | 75 }; |
78 | 76 |
79 RawChannelPosix::RawChannelPosix(embedder::ScopedPlatformHandle handle, | 77 RawChannelPosix::RawChannelPosix(embedder::ScopedPlatformHandle handle) |
80 Delegate* delegate, | 78 : fd_(handle.Pass()), |
81 base::MessageLoopForIO* message_loop_for_io) | |
82 : RawChannel(delegate, message_loop_for_io), | |
83 fd_(handle.Pass()), | |
84 pending_read_(false), | 79 pending_read_(false), |
85 pending_write_(false), | 80 pending_write_(false), |
86 weak_ptr_factory_(this) { | 81 weak_ptr_factory_(this) { |
87 DCHECK(fd_.is_valid()); | 82 DCHECK(fd_.is_valid()); |
88 } | 83 } |
89 | 84 |
90 RawChannelPosix::~RawChannelPosix() { | 85 RawChannelPosix::~RawChannelPosix() { |
91 DCHECK(!pending_read_); | 86 DCHECK(!pending_read_); |
92 DCHECK(!pending_write_); | 87 DCHECK(!pending_write_); |
93 | 88 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 OnWriteCompleted(false, 0); | 323 OnWriteCompleted(false, 0); |
329 } | 324 } |
330 } | 325 } |
331 | 326 |
332 } // namespace | 327 } // namespace |
333 | 328 |
334 // ----------------------------------------------------------------------------- | 329 // ----------------------------------------------------------------------------- |
335 | 330 |
336 // Static factory method declared in raw_channel.h. | 331 // Static factory method declared in raw_channel.h. |
337 // static | 332 // static |
338 RawChannel* RawChannel::Create(embedder::ScopedPlatformHandle handle, | 333 scoped_ptr<RawChannel> RawChannel::Create( |
339 Delegate* delegate, | 334 embedder::ScopedPlatformHandle handle) { |
340 base::MessageLoopForIO* message_loop_for_io) { | 335 return scoped_ptr<RawChannel>(new RawChannelPosix(handle.Pass())); |
341 return new RawChannelPosix(handle.Pass(), delegate, message_loop_for_io); | |
342 } | 336 } |
343 | 337 |
344 } // namespace system | 338 } // namespace system |
345 } // namespace mojo | 339 } // namespace mojo |
OLD | NEW |