OLD | NEW |
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 "content/renderer/media/buffered_data_source.h" | 5 #include "content/renderer/media/buffered_data_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
11 #include "media/base/media_log.h" | 11 #include "media/base/media_log.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 | 13 |
14 using blink::WebFrame; | 14 using blink::WebFrame; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // BufferedDataSource has an intermediate buffer, this value governs the initial | 18 // BufferedDataSource has an intermediate buffer, this value governs the initial |
19 // size of that buffer. It is set to 32KB because this is a typical read size | 19 // size of that buffer. It is set to 32KB because this is a typical read size |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 // static | 75 // static |
76 void BufferedDataSource::ReadOperation::Run( | 76 void BufferedDataSource::ReadOperation::Run( |
77 scoped_ptr<ReadOperation> read_op, int result) { | 77 scoped_ptr<ReadOperation> read_op, int result) { |
78 base::ResetAndReturn(&read_op->callback_).Run(result); | 78 base::ResetAndReturn(&read_op->callback_).Run(result); |
79 } | 79 } |
80 | 80 |
81 BufferedDataSource::BufferedDataSource( | 81 BufferedDataSource::BufferedDataSource( |
82 const GURL& url, | 82 const GURL& url, |
83 BufferedResourceLoader::CORSMode cors_mode, | 83 BufferedResourceLoader::CORSMode cors_mode, |
84 const scoped_refptr<base::MessageLoopProxy>& render_loop, | 84 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
85 WebFrame* frame, | 85 WebFrame* frame, |
86 media::MediaLog* media_log, | 86 media::MediaLog* media_log, |
87 BufferedDataSourceHost* host, | 87 BufferedDataSourceHost* host, |
88 const DownloadingCB& downloading_cb) | 88 const DownloadingCB& downloading_cb) |
89 : url_(url), | 89 : url_(url), |
90 cors_mode_(cors_mode), | 90 cors_mode_(cors_mode), |
91 total_bytes_(kPositionNotSpecified), | 91 total_bytes_(kPositionNotSpecified), |
92 streaming_(false), | 92 streaming_(false), |
93 frame_(frame), | 93 frame_(frame), |
94 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), | 94 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), |
95 intermediate_read_buffer_size_(kInitialReadBufferSize), | 95 intermediate_read_buffer_size_(kInitialReadBufferSize), |
96 render_loop_(render_loop), | 96 render_task_runner_(task_runner), |
97 stop_signal_received_(false), | 97 stop_signal_received_(false), |
98 media_has_played_(false), | 98 media_has_played_(false), |
99 preload_(AUTO), | 99 preload_(AUTO), |
100 bitrate_(0), | 100 bitrate_(0), |
101 playback_rate_(0.0), | 101 playback_rate_(0.0), |
102 media_log_(media_log), | 102 media_log_(media_log), |
103 host_(host), | 103 host_(host), |
104 downloading_cb_(downloading_cb), | 104 downloading_cb_(downloading_cb), |
105 weak_factory_(this) { | 105 weak_factory_(this) { |
106 DCHECK(host_); | 106 DCHECK(host_); |
107 DCHECK(!downloading_cb_.is_null()); | 107 DCHECK(!downloading_cb_.is_null()); |
108 } | 108 } |
109 | 109 |
110 BufferedDataSource::~BufferedDataSource() {} | 110 BufferedDataSource::~BufferedDataSource() {} |
111 | 111 |
112 // A factory method to create BufferedResourceLoader using the read parameters. | 112 // A factory method to create BufferedResourceLoader using the read parameters. |
113 // This method can be overridden to inject mock BufferedResourceLoader object | 113 // This method can be overridden to inject mock BufferedResourceLoader object |
114 // for testing purpose. | 114 // for testing purpose. |
115 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( | 115 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( |
116 int64 first_byte_position, int64 last_byte_position) { | 116 int64 first_byte_position, int64 last_byte_position) { |
117 DCHECK(render_loop_->BelongsToCurrentThread()); | 117 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
118 | 118 |
119 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? | 119 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? |
120 BufferedResourceLoader::kReadThenDefer : | 120 BufferedResourceLoader::kReadThenDefer : |
121 BufferedResourceLoader::kCapacityDefer; | 121 BufferedResourceLoader::kCapacityDefer; |
122 | 122 |
123 return new BufferedResourceLoader(url_, | 123 return new BufferedResourceLoader(url_, |
124 cors_mode_, | 124 cors_mode_, |
125 first_byte_position, | 125 first_byte_position, |
126 last_byte_position, | 126 last_byte_position, |
127 strategy, | 127 strategy, |
128 bitrate_, | 128 bitrate_, |
129 playback_rate_, | 129 playback_rate_, |
130 media_log_.get()); | 130 media_log_.get()); |
131 } | 131 } |
132 | 132 |
133 void BufferedDataSource::Initialize(const InitializeCB& init_cb) { | 133 void BufferedDataSource::Initialize(const InitializeCB& init_cb) { |
134 DCHECK(render_loop_->BelongsToCurrentThread()); | 134 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
135 DCHECK(!init_cb.is_null()); | 135 DCHECK(!init_cb.is_null()); |
136 DCHECK(!loader_.get()); | 136 DCHECK(!loader_.get()); |
137 | 137 |
138 init_cb_ = init_cb; | 138 init_cb_ = init_cb; |
139 | 139 |
140 if (url_.SchemeIsHTTPOrHTTPS()) { | 140 if (url_.SchemeIsHTTPOrHTTPS()) { |
141 // Do an unbounded range request starting at the beginning. If the server | 141 // Do an unbounded range request starting at the beginning. If the server |
142 // responds with 200 instead of 206 we'll fall back into a streaming mode. | 142 // responds with 200 instead of 206 we'll fall back into a streaming mode. |
143 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); | 143 loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); |
144 } else { | 144 } else { |
145 // For all other protocols, assume they support range request. We fetch | 145 // For all other protocols, assume they support range request. We fetch |
146 // the full range of the resource to obtain the instance size because | 146 // the full range of the resource to obtain the instance size because |
147 // we won't be served HTTP headers. | 147 // we won't be served HTTP headers. |
148 loader_.reset(CreateResourceLoader(kPositionNotSpecified, | 148 loader_.reset(CreateResourceLoader(kPositionNotSpecified, |
149 kPositionNotSpecified)); | 149 kPositionNotSpecified)); |
150 } | 150 } |
151 | 151 |
152 base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr(); | 152 base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr(); |
153 loader_->Start( | 153 loader_->Start( |
154 base::Bind(&BufferedDataSource::StartCallback, weak_this), | 154 base::Bind(&BufferedDataSource::StartCallback, weak_this), |
155 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, weak_this), | 155 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, weak_this), |
156 base::Bind(&BufferedDataSource::ProgressCallback, weak_this), | 156 base::Bind(&BufferedDataSource::ProgressCallback, weak_this), |
157 frame_); | 157 frame_); |
158 } | 158 } |
159 | 159 |
160 void BufferedDataSource::SetPreload(Preload preload) { | 160 void BufferedDataSource::SetPreload(Preload preload) { |
161 DCHECK(render_loop_->BelongsToCurrentThread()); | 161 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
162 preload_ = preload; | 162 preload_ = preload; |
163 } | 163 } |
164 | 164 |
165 bool BufferedDataSource::HasSingleOrigin() { | 165 bool BufferedDataSource::HasSingleOrigin() { |
166 DCHECK(render_loop_->BelongsToCurrentThread()); | 166 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
167 DCHECK(init_cb_.is_null() && loader_.get()) | 167 DCHECK(init_cb_.is_null() && loader_.get()) |
168 << "Initialize() must complete before calling HasSingleOrigin()"; | 168 << "Initialize() must complete before calling HasSingleOrigin()"; |
169 return loader_->HasSingleOrigin(); | 169 return loader_->HasSingleOrigin(); |
170 } | 170 } |
171 | 171 |
172 bool BufferedDataSource::DidPassCORSAccessCheck() const { | 172 bool BufferedDataSource::DidPassCORSAccessCheck() const { |
173 return loader_.get() && loader_->DidPassCORSAccessCheck(); | 173 return loader_.get() && loader_->DidPassCORSAccessCheck(); |
174 } | 174 } |
175 | 175 |
176 void BufferedDataSource::Abort() { | 176 void BufferedDataSource::Abort() { |
177 DCHECK(render_loop_->BelongsToCurrentThread()); | 177 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
178 { | 178 { |
179 base::AutoLock auto_lock(lock_); | 179 base::AutoLock auto_lock(lock_); |
180 StopInternal_Locked(); | 180 StopInternal_Locked(); |
181 } | 181 } |
182 StopLoader(); | 182 StopLoader(); |
183 frame_ = NULL; | 183 frame_ = NULL; |
184 } | 184 } |
185 | 185 |
186 void BufferedDataSource::MediaPlaybackRateChanged(float playback_rate) { | 186 void BufferedDataSource::MediaPlaybackRateChanged(float playback_rate) { |
187 DCHECK(render_loop_->BelongsToCurrentThread()); | 187 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
188 DCHECK(loader_.get()); | 188 DCHECK(loader_.get()); |
189 | 189 |
190 if (playback_rate < 0.0f) | 190 if (playback_rate < 0.0f) |
191 return; | 191 return; |
192 | 192 |
193 playback_rate_ = playback_rate; | 193 playback_rate_ = playback_rate; |
194 loader_->SetPlaybackRate(playback_rate); | 194 loader_->SetPlaybackRate(playback_rate); |
195 } | 195 } |
196 | 196 |
197 void BufferedDataSource::MediaIsPlaying() { | 197 void BufferedDataSource::MediaIsPlaying() { |
198 DCHECK(render_loop_->BelongsToCurrentThread()); | 198 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
199 media_has_played_ = true; | 199 media_has_played_ = true; |
200 UpdateDeferStrategy(false); | 200 UpdateDeferStrategy(false); |
201 } | 201 } |
202 | 202 |
203 void BufferedDataSource::MediaIsPaused() { | 203 void BufferedDataSource::MediaIsPaused() { |
204 DCHECK(render_loop_->BelongsToCurrentThread()); | 204 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
205 UpdateDeferStrategy(true); | 205 UpdateDeferStrategy(true); |
206 } | 206 } |
207 | 207 |
208 ///////////////////////////////////////////////////////////////////////////// | 208 ///////////////////////////////////////////////////////////////////////////// |
209 // media::DataSource implementation. | 209 // media::DataSource implementation. |
210 void BufferedDataSource::Stop() { | 210 void BufferedDataSource::Stop() { |
211 { | 211 { |
212 base::AutoLock auto_lock(lock_); | 212 base::AutoLock auto_lock(lock_); |
213 StopInternal_Locked(); | 213 StopInternal_Locked(); |
214 } | 214 } |
215 | 215 |
216 render_loop_->PostTask( | 216 render_task_runner_->PostTask( |
217 FROM_HERE, | 217 FROM_HERE, |
218 base::Bind(&BufferedDataSource::StopLoader, weak_factory_.GetWeakPtr())); | 218 base::Bind(&BufferedDataSource::StopLoader, weak_factory_.GetWeakPtr())); |
219 } | 219 } |
220 | 220 |
221 void BufferedDataSource::SetBitrate(int bitrate) { | 221 void BufferedDataSource::SetBitrate(int bitrate) { |
222 render_loop_->PostTask(FROM_HERE, | 222 render_task_runner_->PostTask(FROM_HERE, |
223 base::Bind(&BufferedDataSource::SetBitrateTask, | 223 base::Bind(&BufferedDataSource::SetBitrateTask, |
224 weak_factory_.GetWeakPtr(), | 224 weak_factory_.GetWeakPtr(), |
225 bitrate)); | 225 bitrate)); |
226 } | 226 } |
227 | 227 |
228 void BufferedDataSource::Read( | 228 void BufferedDataSource::Read( |
229 int64 position, int size, uint8* data, | 229 int64 position, int size, uint8* data, |
230 const media::DataSource::ReadCB& read_cb) { | 230 const media::DataSource::ReadCB& read_cb) { |
231 DVLOG(1) << "Read: " << position << " offset, " << size << " bytes"; | 231 DVLOG(1) << "Read: " << position << " offset, " << size << " bytes"; |
232 DCHECK(!read_cb.is_null()); | 232 DCHECK(!read_cb.is_null()); |
233 | 233 |
234 { | 234 { |
235 base::AutoLock auto_lock(lock_); | 235 base::AutoLock auto_lock(lock_); |
236 DCHECK(!read_op_); | 236 DCHECK(!read_op_); |
237 | 237 |
238 if (stop_signal_received_) { | 238 if (stop_signal_received_) { |
239 read_cb.Run(kReadError); | 239 read_cb.Run(kReadError); |
240 return; | 240 return; |
241 } | 241 } |
242 | 242 |
243 read_op_.reset(new ReadOperation(position, size, data, read_cb)); | 243 read_op_.reset(new ReadOperation(position, size, data, read_cb)); |
244 } | 244 } |
245 | 245 |
246 render_loop_->PostTask( | 246 render_task_runner_->PostTask( |
247 FROM_HERE, | 247 FROM_HERE, |
248 base::Bind(&BufferedDataSource::ReadTask, weak_factory_.GetWeakPtr())); | 248 base::Bind(&BufferedDataSource::ReadTask, weak_factory_.GetWeakPtr())); |
249 } | 249 } |
250 | 250 |
251 bool BufferedDataSource::GetSize(int64* size_out) { | 251 bool BufferedDataSource::GetSize(int64* size_out) { |
252 if (total_bytes_ != kPositionNotSpecified) { | 252 if (total_bytes_ != kPositionNotSpecified) { |
253 *size_out = total_bytes_; | 253 *size_out = total_bytes_; |
254 return true; | 254 return true; |
255 } | 255 } |
256 *size_out = 0; | 256 *size_out = 0; |
257 return false; | 257 return false; |
258 } | 258 } |
259 | 259 |
260 bool BufferedDataSource::IsStreaming() { | 260 bool BufferedDataSource::IsStreaming() { |
261 return streaming_; | 261 return streaming_; |
262 } | 262 } |
263 | 263 |
264 ///////////////////////////////////////////////////////////////////////////// | 264 ///////////////////////////////////////////////////////////////////////////// |
265 // Render thread tasks. | 265 // Render thread tasks. |
266 void BufferedDataSource::ReadTask() { | 266 void BufferedDataSource::ReadTask() { |
267 DCHECK(render_loop_->BelongsToCurrentThread()); | 267 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
268 ReadInternal(); | 268 ReadInternal(); |
269 } | 269 } |
270 | 270 |
271 void BufferedDataSource::StopInternal_Locked() { | 271 void BufferedDataSource::StopInternal_Locked() { |
272 lock_.AssertAcquired(); | 272 lock_.AssertAcquired(); |
273 if (stop_signal_received_) | 273 if (stop_signal_received_) |
274 return; | 274 return; |
275 | 275 |
276 stop_signal_received_ = true; | 276 stop_signal_received_ = true; |
277 | 277 |
278 // Initialize() isn't part of the DataSource interface so don't call it in | 278 // Initialize() isn't part of the DataSource interface so don't call it in |
279 // response to Stop(). | 279 // response to Stop(). |
280 init_cb_.Reset(); | 280 init_cb_.Reset(); |
281 | 281 |
282 if (read_op_) | 282 if (read_op_) |
283 ReadOperation::Run(read_op_.Pass(), kReadError); | 283 ReadOperation::Run(read_op_.Pass(), kReadError); |
284 } | 284 } |
285 | 285 |
286 void BufferedDataSource::StopLoader() { | 286 void BufferedDataSource::StopLoader() { |
287 DCHECK(render_loop_->BelongsToCurrentThread()); | 287 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
288 | 288 |
289 if (loader_) | 289 if (loader_) |
290 loader_->Stop(); | 290 loader_->Stop(); |
291 } | 291 } |
292 | 292 |
293 void BufferedDataSource::SetBitrateTask(int bitrate) { | 293 void BufferedDataSource::SetBitrateTask(int bitrate) { |
294 DCHECK(render_loop_->BelongsToCurrentThread()); | 294 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
295 DCHECK(loader_.get()); | 295 DCHECK(loader_.get()); |
296 | 296 |
297 bitrate_ = bitrate; | 297 bitrate_ = bitrate; |
298 loader_->SetBitrate(bitrate); | 298 loader_->SetBitrate(bitrate); |
299 } | 299 } |
300 | 300 |
301 // This method is the place where actual read happens, |loader_| must be valid | 301 // This method is the place where actual read happens, |loader_| must be valid |
302 // prior to make this method call. | 302 // prior to make this method call. |
303 void BufferedDataSource::ReadInternal() { | 303 void BufferedDataSource::ReadInternal() { |
304 DCHECK(render_loop_->BelongsToCurrentThread()); | 304 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
305 int64 position = 0; | 305 int64 position = 0; |
306 int size = 0; | 306 int size = 0; |
307 { | 307 { |
308 base::AutoLock auto_lock(lock_); | 308 base::AutoLock auto_lock(lock_); |
309 if (stop_signal_received_) | 309 if (stop_signal_received_) |
310 return; | 310 return; |
311 | 311 |
312 position = read_op_->position(); | 312 position = read_op_->position(); |
313 size = read_op_->size(); | 313 size = read_op_->size(); |
314 } | 314 } |
(...skipping 10 matching lines...) Expand all Loading... |
325 intermediate_read_buffer_.get(), | 325 intermediate_read_buffer_.get(), |
326 base::Bind(&BufferedDataSource::ReadCallback, | 326 base::Bind(&BufferedDataSource::ReadCallback, |
327 weak_factory_.GetWeakPtr())); | 327 weak_factory_.GetWeakPtr())); |
328 } | 328 } |
329 | 329 |
330 | 330 |
331 ///////////////////////////////////////////////////////////////////////////// | 331 ///////////////////////////////////////////////////////////////////////////// |
332 // BufferedResourceLoader callback methods. | 332 // BufferedResourceLoader callback methods. |
333 void BufferedDataSource::StartCallback( | 333 void BufferedDataSource::StartCallback( |
334 BufferedResourceLoader::Status status) { | 334 BufferedResourceLoader::Status status) { |
335 DCHECK(render_loop_->BelongsToCurrentThread()); | 335 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
336 DCHECK(loader_.get()); | 336 DCHECK(loader_.get()); |
337 | 337 |
338 bool init_cb_is_null = false; | 338 bool init_cb_is_null = false; |
339 { | 339 { |
340 base::AutoLock auto_lock(lock_); | 340 base::AutoLock auto_lock(lock_); |
341 init_cb_is_null = init_cb_.is_null(); | 341 init_cb_is_null = init_cb_.is_null(); |
342 } | 342 } |
343 if (init_cb_is_null) { | 343 if (init_cb_is_null) { |
344 loader_->Stop(); | 344 loader_->Stop(); |
345 return; | 345 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 loader_->DidPassCORSAccessCheck()); | 382 loader_->DidPassCORSAccessCheck()); |
383 media_log_->SetBooleanProperty("range_header_supported", | 383 media_log_->SetBooleanProperty("range_header_supported", |
384 loader_->range_supported()); | 384 loader_->range_supported()); |
385 } | 385 } |
386 | 386 |
387 base::ResetAndReturn(&init_cb_).Run(success); | 387 base::ResetAndReturn(&init_cb_).Run(success); |
388 } | 388 } |
389 | 389 |
390 void BufferedDataSource::PartialReadStartCallback( | 390 void BufferedDataSource::PartialReadStartCallback( |
391 BufferedResourceLoader::Status status) { | 391 BufferedResourceLoader::Status status) { |
392 DCHECK(render_loop_->BelongsToCurrentThread()); | 392 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
393 DCHECK(loader_.get()); | 393 DCHECK(loader_.get()); |
394 | 394 |
395 if (status == BufferedResourceLoader::kOk) { | 395 if (status == BufferedResourceLoader::kOk) { |
396 // Once the request has started successfully, we can proceed with | 396 // Once the request has started successfully, we can proceed with |
397 // reading from it. | 397 // reading from it. |
398 ReadInternal(); | 398 ReadInternal(); |
399 return; | 399 return; |
400 } | 400 } |
401 | 401 |
402 // Stop the resource loader since we have received an error. | 402 // Stop the resource loader since we have received an error. |
403 loader_->Stop(); | 403 loader_->Stop(); |
404 | 404 |
405 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 405 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
406 // http://crbug.com/113712 for details. | 406 // http://crbug.com/113712 for details. |
407 base::AutoLock auto_lock(lock_); | 407 base::AutoLock auto_lock(lock_); |
408 if (stop_signal_received_) | 408 if (stop_signal_received_) |
409 return; | 409 return; |
410 ReadOperation::Run(read_op_.Pass(), kReadError); | 410 ReadOperation::Run(read_op_.Pass(), kReadError); |
411 } | 411 } |
412 | 412 |
413 void BufferedDataSource::ReadCallback( | 413 void BufferedDataSource::ReadCallback( |
414 BufferedResourceLoader::Status status, | 414 BufferedResourceLoader::Status status, |
415 int bytes_read) { | 415 int bytes_read) { |
416 DCHECK(render_loop_->BelongsToCurrentThread()); | 416 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
417 | 417 |
418 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 418 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
419 // http://crbug.com/113712 for details. | 419 // http://crbug.com/113712 for details. |
420 base::AutoLock auto_lock(lock_); | 420 base::AutoLock auto_lock(lock_); |
421 if (stop_signal_received_) | 421 if (stop_signal_received_) |
422 return; | 422 return; |
423 | 423 |
424 if (status != BufferedResourceLoader::kOk) { | 424 if (status != BufferedResourceLoader::kOk) { |
425 // Stop the resource load if it failed. | 425 // Stop the resource load if it failed. |
426 loader_->Stop(); | 426 loader_->Stop(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 host_->SetTotalBytes(total_bytes_); | 460 host_->SetTotalBytes(total_bytes_); |
461 host_->AddBufferedByteRange(loader_->first_byte_position(), | 461 host_->AddBufferedByteRange(loader_->first_byte_position(), |
462 total_bytes_); | 462 total_bytes_); |
463 } | 463 } |
464 } | 464 } |
465 ReadOperation::Run(read_op_.Pass(), bytes_read); | 465 ReadOperation::Run(read_op_.Pass(), bytes_read); |
466 } | 466 } |
467 | 467 |
468 void BufferedDataSource::LoadingStateChangedCallback( | 468 void BufferedDataSource::LoadingStateChangedCallback( |
469 BufferedResourceLoader::LoadingState state) { | 469 BufferedResourceLoader::LoadingState state) { |
470 DCHECK(render_loop_->BelongsToCurrentThread()); | 470 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
471 | 471 |
472 if (assume_fully_buffered()) | 472 if (assume_fully_buffered()) |
473 return; | 473 return; |
474 | 474 |
475 bool is_downloading_data; | 475 bool is_downloading_data; |
476 switch (state) { | 476 switch (state) { |
477 case BufferedResourceLoader::kLoading: | 477 case BufferedResourceLoader::kLoading: |
478 is_downloading_data = true; | 478 is_downloading_data = true; |
479 break; | 479 break; |
480 case BufferedResourceLoader::kLoadingDeferred: | 480 case BufferedResourceLoader::kLoadingDeferred: |
481 case BufferedResourceLoader::kLoadingFinished: | 481 case BufferedResourceLoader::kLoadingFinished: |
482 is_downloading_data = false; | 482 is_downloading_data = false; |
483 break; | 483 break; |
484 | 484 |
485 // TODO(scherkus): we don't signal network activity changes when loads | 485 // TODO(scherkus): we don't signal network activity changes when loads |
486 // fail to preserve existing behaviour when deferring is toggled, however | 486 // fail to preserve existing behaviour when deferring is toggled, however |
487 // we should consider changing DownloadingCB to also propagate loading | 487 // we should consider changing DownloadingCB to also propagate loading |
488 // state. For example there isn't any signal today to notify the client that | 488 // state. For example there isn't any signal today to notify the client that |
489 // loading has failed (we only get errors on subsequent reads). | 489 // loading has failed (we only get errors on subsequent reads). |
490 case BufferedResourceLoader::kLoadingFailed: | 490 case BufferedResourceLoader::kLoadingFailed: |
491 return; | 491 return; |
492 } | 492 } |
493 | 493 |
494 downloading_cb_.Run(is_downloading_data); | 494 downloading_cb_.Run(is_downloading_data); |
495 } | 495 } |
496 | 496 |
497 void BufferedDataSource::ProgressCallback(int64 position) { | 497 void BufferedDataSource::ProgressCallback(int64 position) { |
498 DCHECK(render_loop_->BelongsToCurrentThread()); | 498 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
499 | 499 |
500 if (assume_fully_buffered()) | 500 if (assume_fully_buffered()) |
501 return; | 501 return; |
502 | 502 |
503 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 503 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
504 // http://crbug.com/113712 for details. | 504 // http://crbug.com/113712 for details. |
505 base::AutoLock auto_lock(lock_); | 505 base::AutoLock auto_lock(lock_); |
506 if (stop_signal_received_) | 506 if (stop_signal_received_) |
507 return; | 507 return; |
508 | 508 |
(...skipping 18 matching lines...) Expand all Loading... |
527 } | 527 } |
528 | 528 |
529 // If media is currently playing or the page indicated preload=auto or the | 529 // If media is currently playing or the page indicated preload=auto or the |
530 // the server does not support the byte range request or we do not want to go | 530 // the server does not support the byte range request or we do not want to go |
531 // too far ahead of the read head, use threshold strategy to enable/disable | 531 // too far ahead of the read head, use threshold strategy to enable/disable |
532 // deferring when the buffer is full/depleted. | 532 // deferring when the buffer is full/depleted. |
533 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 533 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
534 } | 534 } |
535 | 535 |
536 } // namespace content | 536 } // namespace content |
OLD | NEW |