OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 size_t RawChannel::WriteBuffer::GetTotalBytesToWrite() const { | 85 size_t RawChannel::WriteBuffer::GetTotalBytesToWrite() const { |
86 if (message_queue_.empty()) | 86 if (message_queue_.empty()) |
87 return 0; | 87 return 0; |
88 | 88 |
89 MessageInTransit* message = message_queue_.front(); | 89 MessageInTransit* message = message_queue_.front(); |
90 DCHECK_LT(offset_, message->total_size()); | 90 DCHECK_LT(offset_, message->total_size()); |
91 return message->total_size() - offset_; | 91 return message->total_size() - offset_; |
92 } | 92 } |
93 | 93 |
94 RawChannel::RawChannel(Delegate* delegate, | 94 RawChannel::RawChannel() |
95 base::MessageLoopForIO* message_loop_for_io) | 95 : delegate_(NULL), |
96 : delegate_(delegate), | 96 message_loop_for_io_(NULL), |
97 message_loop_for_io_(message_loop_for_io), | |
98 read_stopped_(false), | 97 read_stopped_(false), |
99 write_stopped_(false), | 98 write_stopped_(false), |
100 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
101 } | 100 } |
102 | 101 |
103 RawChannel::~RawChannel() { | 102 RawChannel::~RawChannel() { |
104 DCHECK(!read_buffer_); | 103 DCHECK(!read_buffer_); |
105 DCHECK(!write_buffer_); | 104 DCHECK(!write_buffer_); |
106 | 105 |
107 // No need to take the |write_lock_| here -- if there are still weak pointers | 106 // No need to take the |write_lock_| here -- if there are still weak pointers |
108 // outstanding, then we're hosed anyway (since we wouldn't be able to | 107 // outstanding, then we're hosed anyway (since we wouldn't be able to |
109 // invalidate them cleanly, since we might not be on the I/O thread). | 108 // invalidate them cleanly, since we might not be on the I/O thread). |
110 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); | 109 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); |
111 } | 110 } |
112 | 111 |
113 bool RawChannel::Init() { | 112 bool RawChannel::Init(Delegate* delegate) { |
114 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io_); | 113 DCHECK(delegate); |
| 114 |
| 115 DCHECK(!delegate_); |
| 116 delegate_ = delegate; |
| 117 |
| 118 CHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_IO); |
| 119 DCHECK(!message_loop_for_io_); |
| 120 message_loop_for_io_ = |
| 121 static_cast<base::MessageLoopForIO*>(base::MessageLoop::current()); |
115 | 122 |
116 // No need to take the lock. No one should be using us yet. | 123 // No need to take the lock. No one should be using us yet. |
117 DCHECK(!read_buffer_); | 124 DCHECK(!read_buffer_); |
118 read_buffer_.reset(new ReadBuffer); | 125 read_buffer_.reset(new ReadBuffer); |
119 DCHECK(!write_buffer_); | 126 DCHECK(!write_buffer_); |
120 write_buffer_.reset(new WriteBuffer); | 127 write_buffer_.reset(new WriteBuffer); |
121 | 128 |
122 if (!OnInit()) | 129 if (!OnInit()) |
123 return false; | 130 return false; |
124 | 131 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 350 } |
344 | 351 |
345 write_stopped_ = true; | 352 write_stopped_ = true; |
346 STLDeleteElements(&write_buffer_->message_queue_); | 353 STLDeleteElements(&write_buffer_->message_queue_); |
347 write_buffer_->offset_ = 0; | 354 write_buffer_->offset_ = 0; |
348 return false; | 355 return false; |
349 } | 356 } |
350 | 357 |
351 } // namespace system | 358 } // namespace system |
352 } // namespace mojo | 359 } // namespace mojo |
OLD | NEW |