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

Side by Side Diff: remoting/protocol/buffered_socket_writer.cc

Issue 10066042: Refcounted types should not have public destructors, remoting/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Few fixes Created 8 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/buffered_socket_writer.h ('k') | remoting/protocol/message_reader.h » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "remoting/protocol/buffered_socket_writer.h" 5 #include "remoting/protocol/buffered_socket_writer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 27 matching lines...) Expand all
38 38
39 BufferedSocketWriterBase::BufferedSocketWriterBase( 39 BufferedSocketWriterBase::BufferedSocketWriterBase(
40 base::MessageLoopProxy* message_loop) 40 base::MessageLoopProxy* message_loop)
41 : buffer_size_(0), 41 : buffer_size_(0),
42 socket_(NULL), 42 socket_(NULL),
43 message_loop_(message_loop), 43 message_loop_(message_loop),
44 write_pending_(false), 44 write_pending_(false),
45 closed_(false) { 45 closed_(false) {
46 } 46 }
47 47
48 BufferedSocketWriterBase::~BufferedSocketWriterBase() { }
49
50 void BufferedSocketWriterBase::Init(net::Socket* socket, 48 void BufferedSocketWriterBase::Init(net::Socket* socket,
51 const WriteFailedCallback& callback) { 49 const WriteFailedCallback& callback) {
52 DCHECK(message_loop_->BelongsToCurrentThread()); 50 DCHECK(message_loop_->BelongsToCurrentThread());
53 DCHECK(socket); 51 DCHECK(socket);
54 socket_ = socket; 52 socket_ = socket;
55 write_failed_callback_ = callback; 53 write_failed_callback_ = callback;
56 } 54 }
57 55
58 bool BufferedSocketWriterBase::Write( 56 bool BufferedSocketWriterBase::Write(
59 scoped_refptr<net::IOBufferWithSize> data, const base::Closure& done_task) { 57 scoped_refptr<net::IOBufferWithSize> data, const base::Closure& done_task) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 int BufferedSocketWriterBase::GetBufferChunks() { 150 int BufferedSocketWriterBase::GetBufferChunks() {
153 base::AutoLock auto_lock(lock_); 151 base::AutoLock auto_lock(lock_);
154 return queue_.size(); 152 return queue_.size();
155 } 153 }
156 154
157 void BufferedSocketWriterBase::Close() { 155 void BufferedSocketWriterBase::Close() {
158 DCHECK(message_loop_->BelongsToCurrentThread()); 156 DCHECK(message_loop_->BelongsToCurrentThread());
159 closed_ = true; 157 closed_ = true;
160 } 158 }
161 159
160 BufferedSocketWriterBase::~BufferedSocketWriterBase() {}
161
162 void BufferedSocketWriterBase::PopQueue() { 162 void BufferedSocketWriterBase::PopQueue() {
163 // This also calls |done_task|. 163 // This also calls |done_task|.
164 delete queue_.front(); 164 delete queue_.front();
165 queue_.pop_front(); 165 queue_.pop_front();
166 } 166 }
167 167
168 BufferedSocketWriter::BufferedSocketWriter( 168 BufferedSocketWriter::BufferedSocketWriter(
169 base::MessageLoopProxy* message_loop) 169 base::MessageLoopProxy* message_loop)
170 : BufferedSocketWriterBase(message_loop) { 170 : BufferedSocketWriterBase(message_loop) {
171 } 171 }
172 172
173 BufferedSocketWriter::~BufferedSocketWriter() {
174 STLDeleteElements(&queue_);
175 }
176
177 void BufferedSocketWriter::GetNextPacket_Locked( 173 void BufferedSocketWriter::GetNextPacket_Locked(
178 net::IOBuffer** buffer, int* size) { 174 net::IOBuffer** buffer, int* size) {
179 if (!current_buf_) { 175 if (!current_buf_) {
180 if (queue_.empty()) { 176 if (queue_.empty()) {
181 *buffer = NULL; 177 *buffer = NULL;
182 return; // Nothing to write. 178 return; // Nothing to write.
183 } 179 }
184 current_buf_ = new net::DrainableIOBuffer( 180 current_buf_ = new net::DrainableIOBuffer(
185 queue_.front()->data(), queue_.front()->data()->size()); 181 queue_.front()->data(), queue_.front()->data()->size());
186 } 182 }
187 183
188 *buffer = current_buf_; 184 *buffer = current_buf_;
189 *size = current_buf_->BytesRemaining(); 185 *size = current_buf_->BytesRemaining();
190 } 186 }
191 187
192 void BufferedSocketWriter::AdvanceBufferPosition_Locked(int written) { 188 void BufferedSocketWriter::AdvanceBufferPosition_Locked(int written) {
193 buffer_size_ -= written; 189 buffer_size_ -= written;
194 current_buf_->DidConsume(written); 190 current_buf_->DidConsume(written);
195 191
196 if (current_buf_->BytesRemaining() == 0) { 192 if (current_buf_->BytesRemaining() == 0) {
197 PopQueue(); 193 PopQueue();
198 current_buf_ = NULL; 194 current_buf_ = NULL;
199 } 195 }
200 } 196 }
201 197
202 void BufferedSocketWriter::OnError_Locked(int result) { 198 void BufferedSocketWriter::OnError_Locked(int result) {
203 current_buf_ = NULL; 199 current_buf_ = NULL;
204 } 200 }
205 201
202 BufferedSocketWriter::~BufferedSocketWriter() {
203 STLDeleteElements(&queue_);
204 }
205
206 BufferedDatagramWriter::BufferedDatagramWriter( 206 BufferedDatagramWriter::BufferedDatagramWriter(
207 base::MessageLoopProxy* message_loop) 207 base::MessageLoopProxy* message_loop)
208 : BufferedSocketWriterBase(message_loop) { 208 : BufferedSocketWriterBase(message_loop) {
209 } 209 }
210 BufferedDatagramWriter::~BufferedDatagramWriter() { }
211 210
212 void BufferedDatagramWriter::GetNextPacket_Locked( 211 void BufferedDatagramWriter::GetNextPacket_Locked(
213 net::IOBuffer** buffer, int* size) { 212 net::IOBuffer** buffer, int* size) {
214 if (queue_.empty()) { 213 if (queue_.empty()) {
215 *buffer = NULL; 214 *buffer = NULL;
216 return; // Nothing to write. 215 return; // Nothing to write.
217 } 216 }
218 *buffer = queue_.front()->data(); 217 *buffer = queue_.front()->data();
219 *size = queue_.front()->data()->size(); 218 *size = queue_.front()->data()->size();
220 } 219 }
221 220
222 void BufferedDatagramWriter::AdvanceBufferPosition_Locked(int written) { 221 void BufferedDatagramWriter::AdvanceBufferPosition_Locked(int written) {
223 DCHECK_EQ(written, queue_.front()->data()->size()); 222 DCHECK_EQ(written, queue_.front()->data()->size());
224 buffer_size_ -= queue_.front()->data()->size(); 223 buffer_size_ -= queue_.front()->data()->size();
225 PopQueue(); 224 PopQueue();
226 } 225 }
227 226
228 void BufferedDatagramWriter::OnError_Locked(int result) { 227 void BufferedDatagramWriter::OnError_Locked(int result) {
229 // Nothing to do here. 228 // Nothing to do here.
230 } 229 }
231 230
231 BufferedDatagramWriter::~BufferedDatagramWriter() {}
232
232 } // namespace protocol 233 } // namespace protocol
233 } // namespace remoting 234 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/buffered_socket_writer.h ('k') | remoting/protocol/message_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698