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

Side by Side Diff: content/browser/streams/stream.cc

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/browser/streams/stream.h" 5 #include "content/browser/streams/stream.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/message_loop_proxy.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "content/browser/streams/stream_handle_impl.h" 12 #include "content/browser/streams/stream_handle_impl.h"
12 #include "content/browser/streams/stream_read_observer.h" 13 #include "content/browser/streams/stream_read_observer.h"
13 #include "content/browser/streams/stream_registry.h" 14 #include "content/browser/streams/stream_registry.h"
14 #include "content/browser/streams/stream_write_observer.h" 15 #include "content/browser/streams/stream_write_observer.h"
15 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
16 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
17 18
18 namespace { 19 namespace {
19 // Start throttling the connection at about 1MB. 20 // Start throttling the connection at about 1MB.
20 const size_t kDeferSizeThreshold = 40 * 32768; 21 const size_t kDeferSizeThreshold = 40 * 32768;
21 } 22 }
22 23
23 namespace content { 24 namespace content {
24 25
25 Stream::Stream(StreamRegistry* registry, 26 Stream::Stream(StreamRegistry* registry,
26 StreamWriteObserver* write_observer, 27 StreamWriteObserver* write_observer,
27 const GURL& url) 28 const GURL& url)
28 : can_add_data_(true), 29 : can_add_data_(true),
29 url_(url), 30 url_(url),
30 data_length_(0), 31 data_length_(0),
31 data_bytes_read_(0), 32 data_bytes_read_(0),
32 last_total_buffered_bytes_(0), 33 last_total_buffered_bytes_(0),
33 registry_(registry), 34 registry_(registry),
34 read_observer_(NULL), 35 read_observer_(NULL),
35 write_observer_(write_observer), 36 write_observer_(write_observer),
36 stream_handle_(NULL), 37 stream_handle_(NULL),
37 weak_ptr_factory_(this) { 38 weak_ptr_factory_(this) {
38 CreateByteStream(base::MessageLoopProxy::current(), 39 CreateByteStream(base::ThreadTaskRunnerHandle::Get(),
39 base::MessageLoopProxy::current(), 40 base::ThreadTaskRunnerHandle::Get(), kDeferSizeThreshold,
40 kDeferSizeThreshold, 41 &writer_, &reader_);
41 &writer_,
42 &reader_);
43 42
44 // Setup callback for writing. 43 // Setup callback for writing.
45 writer_->RegisterCallback(base::Bind(&Stream::OnSpaceAvailable, 44 writer_->RegisterCallback(base::Bind(&Stream::OnSpaceAvailable,
46 weak_ptr_factory_.GetWeakPtr())); 45 weak_ptr_factory_.GetWeakPtr()));
47 reader_->RegisterCallback(base::Bind(&Stream::OnDataAvailable, 46 reader_->RegisterCallback(base::Bind(&Stream::OnDataAvailable,
48 weak_ptr_factory_.GetWeakPtr())); 47 weak_ptr_factory_.GetWeakPtr()));
49 48
50 registry_->RegisterStream(this); 49 registry_->RegisterStream(this);
51 } 50 }
52 51
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 114 }
116 115
117 void Stream::Finalize() { 116 void Stream::Finalize() {
118 if (!writer_.get()) 117 if (!writer_.get())
119 return; 118 return;
120 119
121 writer_->Close(0); 120 writer_->Close(0);
122 writer_.reset(); 121 writer_.reset();
123 122
124 // Continue asynchronously. 123 // Continue asynchronously.
125 base::MessageLoopProxy::current()->PostTask( 124 base::ThreadTaskRunnerHandle::Get()->PostTask(
126 FROM_HERE, 125 FROM_HERE,
127 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); 126 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr()));
128 } 127 }
129 128
130 Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf, 129 Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf,
131 int buf_size, 130 int buf_size,
132 int* bytes_read) { 131 int* bytes_read) {
133 DCHECK(buf); 132 DCHECK(buf);
134 DCHECK(bytes_read); 133 DCHECK(bytes_read);
135 134
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 read_observer_->OnDataAvailable(this); 193 read_observer_->OnDataAvailable(this);
195 } 194 }
196 195
197 void Stream::ClearBuffer() { 196 void Stream::ClearBuffer() {
198 data_ = NULL; 197 data_ = NULL;
199 data_length_ = 0; 198 data_length_ = 0;
200 data_bytes_read_ = 0; 199 data_bytes_read_ = 0;
201 } 200 }
202 201
203 } // namespace content 202 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl_unittest.cc ('k') | content/browser/streams/stream_handle_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698