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

Side by Side Diff: content/browser/byte_stream.cc

Issue 21839002: Clean up on byte_stream (mainly style and includes) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rdsmith's comments Created 7 years, 4 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 | « content/browser/byte_stream.h ('k') | content/browser/byte_stream_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/byte_stream.h" 5 #include "content/browser/byte_stream.h"
6 6
7 #include <deque>
8 #include <set>
9 #include <utility>
10
7 #include "base/bind.h" 11 #include "base/bind.h"
8 #include "base/location.h" 12 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
12 15
13 namespace content { 16 namespace content {
14 namespace { 17 namespace {
15 18
16 typedef std::deque<std::pair<scoped_refptr<net::IOBuffer>, size_t> > 19 typedef std::deque<std::pair<scoped_refptr<net::IOBuffer>, size_t> >
17 ContentVector; 20 ContentVector;
18 21
19 class ByteStreamReaderImpl; 22 class ByteStreamReaderImpl;
20 23
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 (total_known_size_used + bytes_consumed > total_buffer_size_) && 259 (total_known_size_used + bytes_consumed > total_buffer_size_) &&
257 !space_available_callback_.is_null()) 260 !space_available_callback_.is_null())
258 space_available_callback_.Run(); 261 space_available_callback_.Run();
259 } 262 }
260 263
261 void ByteStreamWriterImpl::PostToPeer(bool complete, int status) { 264 void ByteStreamWriterImpl::PostToPeer(bool complete, int status) {
262 DCHECK(my_task_runner_->RunsTasksOnCurrentThread()); 265 DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
263 // Valid contexts in which to call. 266 // Valid contexts in which to call.
264 DCHECK(complete || 0 != input_contents_size_); 267 DCHECK(complete || 0 != input_contents_size_);
265 268
266 scoped_ptr<ContentVector> transfer_buffer(new ContentVector); 269 scoped_ptr<ContentVector> transfer_buffer;
267 size_t buffer_size = 0; 270 size_t buffer_size = 0;
268 if (0 != input_contents_size_) { 271 if (0 != input_contents_size_) {
269 transfer_buffer.reset(new ContentVector); 272 transfer_buffer.reset(new ContentVector);
270 transfer_buffer->swap(input_contents_); 273 transfer_buffer->swap(input_contents_);
271 buffer_size = input_contents_size_; 274 buffer_size = input_contents_size_;
272 output_size_used_ += input_contents_size_; 275 output_size_used_ += input_contents_size_;
273 input_contents_size_ = 0; 276 input_contents_size_ = 0;
274 } 277 }
275 peer_task_runner_->PostTask( 278 peer_task_runner_->PostTask(
276 FROM_HERE, base::Bind( 279 FROM_HERE, base::Bind(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 scoped_ptr<ContentVector> transfer_buffer, 366 scoped_ptr<ContentVector> transfer_buffer,
364 size_t buffer_size, 367 size_t buffer_size,
365 bool source_complete, 368 bool source_complete,
366 int status) { 369 int status) {
367 DCHECK(my_task_runner_->RunsTasksOnCurrentThread()); 370 DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
368 371
369 bool was_empty = available_contents_.empty(); 372 bool was_empty = available_contents_.empty();
370 373
371 if (transfer_buffer) { 374 if (transfer_buffer) {
372 available_contents_.insert(available_contents_.end(), 375 available_contents_.insert(available_contents_.end(),
373 transfer_buffer->begin(), 376 transfer_buffer->begin(),
374 transfer_buffer->end()); 377 transfer_buffer->end());
375 } 378 }
376 379
377 if (source_complete) { 380 if (source_complete) {
378 received_status_ = true; 381 received_status_ = true;
379 status_ = status; 382 status_ = status;
380 } 383 }
381 384
382 // Callback on transition from empty to non-empty, or 385 // Callback on transition from empty to non-empty, or
383 // source complete. 386 // source complete.
384 if (((was_empty && !available_contents_.empty()) || 387 if (((was_empty && !available_contents_.empty()) ||
(...skipping 16 matching lines...) Expand all
401 FROM_HERE, base::Bind( 404 FROM_HERE, base::Bind(
402 &ByteStreamWriterImpl::UpdateWindow, 405 &ByteStreamWriterImpl::UpdateWindow,
403 peer_lifetime_flag_, 406 peer_lifetime_flag_,
404 peer_, 407 peer_,
405 unreported_consumed_bytes_)); 408 unreported_consumed_bytes_));
406 unreported_consumed_bytes_ = 0; 409 unreported_consumed_bytes_ = 0;
407 } 410 }
408 411
409 } // namespace 412 } // namespace
410 413
411
412 const int ByteStreamWriter::kFractionBufferBeforeSending = 3; 414 const int ByteStreamWriter::kFractionBufferBeforeSending = 3;
413 const int ByteStreamReader::kFractionReadBeforeWindowUpdate = 3; 415 const int ByteStreamReader::kFractionReadBeforeWindowUpdate = 3;
414 416
415 ByteStreamReader::~ByteStreamReader() { } 417 ByteStreamReader::~ByteStreamReader() { }
416 418
417 ByteStreamWriter::~ByteStreamWriter() { } 419 ByteStreamWriter::~ByteStreamWriter() { }
418 420
419 void CreateByteStream( 421 void CreateByteStream(
420 scoped_refptr<base::SequencedTaskRunner> input_task_runner, 422 scoped_refptr<base::SequencedTaskRunner> input_task_runner,
421 scoped_refptr<base::SequencedTaskRunner> output_task_runner, 423 scoped_refptr<base::SequencedTaskRunner> output_task_runner,
422 size_t buffer_size, 424 size_t buffer_size,
423 scoped_ptr<ByteStreamWriter>* input, 425 scoped_ptr<ByteStreamWriter>* input,
424 scoped_ptr<ByteStreamReader>* output) { 426 scoped_ptr<ByteStreamReader>* output) {
425 scoped_refptr<LifetimeFlag> input_flag(new LifetimeFlag()); 427 scoped_refptr<LifetimeFlag> input_flag(new LifetimeFlag());
426 scoped_refptr<LifetimeFlag> output_flag(new LifetimeFlag()); 428 scoped_refptr<LifetimeFlag> output_flag(new LifetimeFlag());
427 429
428 ByteStreamWriterImpl* in = new ByteStreamWriterImpl( 430 ByteStreamWriterImpl* in = new ByteStreamWriterImpl(
429 input_task_runner, input_flag, buffer_size); 431 input_task_runner, input_flag, buffer_size);
430 ByteStreamReaderImpl* out = new ByteStreamReaderImpl( 432 ByteStreamReaderImpl* out = new ByteStreamReaderImpl(
431 output_task_runner, output_flag, buffer_size); 433 output_task_runner, output_flag, buffer_size);
432 434
433 in->SetPeer(out, output_task_runner, output_flag); 435 in->SetPeer(out, output_task_runner, output_flag);
434 out->SetPeer(in, input_task_runner, input_flag); 436 out->SetPeer(in, input_task_runner, input_flag);
435 input->reset(in); 437 input->reset(in);
436 output->reset(out); 438 output->reset(out);
437 } 439 }
438 440
439 } // namespace content 441 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/byte_stream.h ('k') | content/browser/byte_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698