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

Side by Side Diff: mojo/system/raw_channel_posix.cc

Issue 137063010: Mojo: Move platform handle/channel stuff in system to embedder namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/raw_channel.h ('k') | mojo/system/raw_channel_posix_unittest.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 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 <string.h> 8 #include <string.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 17 matching lines...) Expand all
28 namespace mojo { 28 namespace mojo {
29 namespace system { 29 namespace system {
30 30
31 namespace { 31 namespace {
32 32
33 const size_t kReadSize = 4096; 33 const size_t kReadSize = 4096;
34 34
35 class RawChannelPosix : public RawChannel, 35 class RawChannelPosix : public RawChannel,
36 public base::MessageLoopForIO::Watcher { 36 public base::MessageLoopForIO::Watcher {
37 public: 37 public:
38 RawChannelPosix(ScopedPlatformHandle handle, 38 RawChannelPosix(embedder::ScopedPlatformHandle handle,
39 Delegate* delegate, 39 Delegate* delegate,
40 base::MessageLoop* message_loop); 40 base::MessageLoop* message_loop);
41 virtual ~RawChannelPosix(); 41 virtual ~RawChannelPosix();
42 42
43 // |RawChannel| implementation: 43 // |RawChannel| implementation:
44 virtual bool Init() OVERRIDE; 44 virtual bool Init() OVERRIDE;
45 virtual void Shutdown() OVERRIDE; 45 virtual void Shutdown() OVERRIDE;
46 virtual bool WriteMessage(MessageInTransit* message) OVERRIDE; 46 virtual bool WriteMessage(MessageInTransit* message) OVERRIDE;
47 47
48 private: 48 private:
(...skipping 16 matching lines...) Expand all
65 65
66 // Cancels all pending writes and destroys the contents of 66 // Cancels all pending writes and destroys the contents of
67 // |write_message_queue_|. Should only be called if |is_dead_| is false; sets 67 // |write_message_queue_|. Should only be called if |is_dead_| is false; sets
68 // |is_dead_| to true. Must be called under |write_lock_|. 68 // |is_dead_| to true. Must be called under |write_lock_|.
69 void CancelPendingWritesNoLock(); 69 void CancelPendingWritesNoLock();
70 70
71 base::MessageLoopForIO* message_loop_for_io() { 71 base::MessageLoopForIO* message_loop_for_io() {
72 return static_cast<base::MessageLoopForIO*>(message_loop()); 72 return static_cast<base::MessageLoopForIO*>(message_loop());
73 } 73 }
74 74
75 ScopedPlatformHandle fd_; 75 embedder::ScopedPlatformHandle fd_;
76 76
77 // Only used on the I/O thread: 77 // Only used on the I/O thread:
78 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> read_watcher_; 78 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> read_watcher_;
79 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> write_watcher_; 79 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> write_watcher_;
80 80
81 // We store data from |read()|s in |read_buffer_|. The start of |read_buffer_| 81 // We store data from |read()|s in |read_buffer_|. The start of |read_buffer_|
82 // is always aligned with a message boundary (we will copy memory to ensure 82 // is always aligned with a message boundary (we will copy memory to ensure
83 // this), but |read_buffer_| may be larger than the actual number of bytes we 83 // this), but |read_buffer_| may be larger than the actual number of bytes we
84 // have. 84 // have.
85 std::vector<char> read_buffer_; 85 std::vector<char> read_buffer_;
86 size_t read_buffer_num_valid_bytes_; 86 size_t read_buffer_num_valid_bytes_;
87 87
88 base::Lock write_lock_; // Protects the following members. 88 base::Lock write_lock_; // Protects the following members.
89 bool is_dead_; 89 bool is_dead_;
90 std::deque<MessageInTransit*> write_message_queue_; 90 std::deque<MessageInTransit*> write_message_queue_;
91 size_t write_message_offset_; 91 size_t write_message_offset_;
92 // This is used for posting tasks from write threads to the I/O thread. It 92 // This is used for posting tasks from write threads to the I/O thread. It
93 // must only be accessed under |write_lock_|. The weak pointers it produces 93 // must only be accessed under |write_lock_|. The weak pointers it produces
94 // are only used/invalidated on the I/O thread. 94 // are only used/invalidated on the I/O thread.
95 base::WeakPtrFactory<RawChannelPosix> weak_ptr_factory_; 95 base::WeakPtrFactory<RawChannelPosix> weak_ptr_factory_;
96 96
97 DISALLOW_COPY_AND_ASSIGN(RawChannelPosix); 97 DISALLOW_COPY_AND_ASSIGN(RawChannelPosix);
98 }; 98 };
99 99
100 RawChannelPosix::RawChannelPosix(ScopedPlatformHandle handle, 100 RawChannelPosix::RawChannelPosix(embedder::ScopedPlatformHandle handle,
101 Delegate* delegate, 101 Delegate* delegate,
102 base::MessageLoop* message_loop) 102 base::MessageLoop* message_loop)
103 : RawChannel(delegate, message_loop), 103 : RawChannel(delegate, message_loop),
104 fd_(handle.Pass()), 104 fd_(handle.Pass()),
105 read_buffer_num_valid_bytes_(0), 105 read_buffer_num_valid_bytes_(0),
106 is_dead_(false), 106 is_dead_(false),
107 write_message_offset_(0), 107 write_message_offset_(0),
108 weak_ptr_factory_(this) { 108 weak_ptr_factory_(this) {
109 CHECK_EQ(RawChannel::message_loop()->type(), base::MessageLoop::TYPE_IO); 109 CHECK_EQ(RawChannel::message_loop()->type(), base::MessageLoop::TYPE_IO);
110 DCHECK(fd_.is_valid()); 110 DCHECK(fd_.is_valid());
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 393 }
394 write_message_queue_.clear(); 394 write_message_queue_.clear();
395 } 395 }
396 396
397 } // namespace 397 } // namespace
398 398
399 // ----------------------------------------------------------------------------- 399 // -----------------------------------------------------------------------------
400 400
401 // Static factory method declared in raw_channel.h. 401 // Static factory method declared in raw_channel.h.
402 // static 402 // static
403 RawChannel* RawChannel::Create(ScopedPlatformHandle handle, 403 RawChannel* RawChannel::Create(embedder::ScopedPlatformHandle handle,
404 Delegate* delegate, 404 Delegate* delegate,
405 base::MessageLoop* message_loop) { 405 base::MessageLoop* message_loop) {
406 return new RawChannelPosix(handle.Pass(), delegate, message_loop); 406 return new RawChannelPosix(handle.Pass(), delegate, message_loop);
407 } 407 }
408 408
409 } // namespace system 409 } // namespace system
410 } // namespace mojo 410 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel.h ('k') | mojo/system/raw_channel_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698