| 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 "media/blink/buffered_data_source.h" | 5 #include "media/blink/buffered_data_source.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "media/base/media_log.h" | 14 #include "media/base/media_log.h" |
| 13 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 14 | 16 |
| 15 using blink::WebFrame; | 17 using blink::WebFrame; |
| 16 | 18 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 if (stop_signal_received_) | 310 if (stop_signal_received_) |
| 309 return; | 311 return; |
| 310 | 312 |
| 311 stop_signal_received_ = true; | 313 stop_signal_received_ = true; |
| 312 | 314 |
| 313 // Initialize() isn't part of the DataSource interface so don't call it in | 315 // Initialize() isn't part of the DataSource interface so don't call it in |
| 314 // response to Stop(). | 316 // response to Stop(). |
| 315 init_cb_.Reset(); | 317 init_cb_.Reset(); |
| 316 | 318 |
| 317 if (read_op_) | 319 if (read_op_) |
| 318 ReadOperation::Run(read_op_.Pass(), kReadError); | 320 ReadOperation::Run(std::move(read_op_), kReadError); |
| 319 } | 321 } |
| 320 | 322 |
| 321 void BufferedDataSource::StopLoader() { | 323 void BufferedDataSource::StopLoader() { |
| 322 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 324 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
| 323 | 325 |
| 324 if (loader_) | 326 if (loader_) |
| 325 loader_->Stop(); | 327 loader_->Stop(); |
| 326 } | 328 } |
| 327 | 329 |
| 328 void BufferedDataSource::SetBitrateTask(int bitrate) { | 330 void BufferedDataSource::SetBitrateTask(int bitrate) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 439 } |
| 438 | 440 |
| 439 // Stop the resource loader since we have received an error. | 441 // Stop the resource loader since we have received an error. |
| 440 loader_->Stop(); | 442 loader_->Stop(); |
| 441 | 443 |
| 442 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 444 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
| 443 // http://crbug.com/113712 for details. | 445 // http://crbug.com/113712 for details. |
| 444 base::AutoLock auto_lock(lock_); | 446 base::AutoLock auto_lock(lock_); |
| 445 if (stop_signal_received_) | 447 if (stop_signal_received_) |
| 446 return; | 448 return; |
| 447 ReadOperation::Run(read_op_.Pass(), kReadError); | 449 ReadOperation::Run(std::move(read_op_), kReadError); |
| 448 } | 450 } |
| 449 | 451 |
| 450 bool BufferedDataSource::CheckPartialResponseURL( | 452 bool BufferedDataSource::CheckPartialResponseURL( |
| 451 const GURL& partial_response_original_url) const { | 453 const GURL& partial_response_original_url) const { |
| 452 // We check the redirected URL of partial responses in case malicious | 454 // We check the redirected URL of partial responses in case malicious |
| 453 // attackers scan the bytes of other origin resources by mixing their | 455 // attackers scan the bytes of other origin resources by mixing their |
| 454 // generated bytes and the target response. See http://crbug.com/489060#c32 | 456 // generated bytes and the target response. See http://crbug.com/489060#c32 |
| 455 // for details. | 457 // for details. |
| 456 // If the origin of the new response is different from the first response we | 458 // If the origin of the new response is different from the first response we |
| 457 // deny the redirected response unless the crossorigin attribute has been set. | 459 // deny the redirected response unless the crossorigin attribute has been set. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr(); | 505 base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr(); |
| 504 loader_->Start( | 506 loader_->Start( |
| 505 base::Bind(&BufferedDataSource::PartialReadStartCallback, weak_this), | 507 base::Bind(&BufferedDataSource::PartialReadStartCallback, weak_this), |
| 506 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, | 508 base::Bind(&BufferedDataSource::LoadingStateChangedCallback, |
| 507 weak_this), | 509 weak_this), |
| 508 base::Bind(&BufferedDataSource::ProgressCallback, weak_this), | 510 base::Bind(&BufferedDataSource::ProgressCallback, weak_this), |
| 509 frame_); | 511 frame_); |
| 510 return; | 512 return; |
| 511 } | 513 } |
| 512 | 514 |
| 513 ReadOperation::Run(read_op_.Pass(), kReadError); | 515 ReadOperation::Run(std::move(read_op_), kReadError); |
| 514 return; | 516 return; |
| 515 } | 517 } |
| 516 | 518 |
| 517 if (bytes_read > 0) { | 519 if (bytes_read > 0) { |
| 518 DCHECK(!intermediate_read_buffer_.empty()); | 520 DCHECK(!intermediate_read_buffer_.empty()); |
| 519 memcpy(read_op_->data(), &intermediate_read_buffer_[0], bytes_read); | 521 memcpy(read_op_->data(), &intermediate_read_buffer_[0], bytes_read); |
| 520 } else if (bytes_read == 0 && total_bytes_ == kPositionNotSpecified) { | 522 } else if (bytes_read == 0 && total_bytes_ == kPositionNotSpecified) { |
| 521 // We've reached the end of the file and we didn't know the total size | 523 // We've reached the end of the file and we didn't know the total size |
| 522 // before. Update the total size so Read()s past the end of the file will | 524 // before. Update the total size so Read()s past the end of the file will |
| 523 // fail like they would if we had known the file size at the beginning. | 525 // fail like they would if we had known the file size at the beginning. |
| 524 total_bytes_ = loader_->instance_size(); | 526 total_bytes_ = loader_->instance_size(); |
| 525 | 527 |
| 526 if (total_bytes_ != kPositionNotSpecified) { | 528 if (total_bytes_ != kPositionNotSpecified) { |
| 527 host_->SetTotalBytes(total_bytes_); | 529 host_->SetTotalBytes(total_bytes_); |
| 528 host_->AddBufferedByteRange(loader_->first_byte_position(), | 530 host_->AddBufferedByteRange(loader_->first_byte_position(), |
| 529 total_bytes_); | 531 total_bytes_); |
| 530 } | 532 } |
| 531 } | 533 } |
| 532 ReadOperation::Run(read_op_.Pass(), bytes_read); | 534 ReadOperation::Run(std::move(read_op_), bytes_read); |
| 533 } | 535 } |
| 534 | 536 |
| 535 void BufferedDataSource::LoadingStateChangedCallback( | 537 void BufferedDataSource::LoadingStateChangedCallback( |
| 536 BufferedResourceLoader::LoadingState state) { | 538 BufferedResourceLoader::LoadingState state) { |
| 537 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 539 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
| 538 | 540 |
| 539 if (assume_fully_buffered()) | 541 if (assume_fully_buffered()) |
| 540 return; | 542 return; |
| 541 | 543 |
| 542 bool is_downloading_data; | 544 bool is_downloading_data; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 600 } |
| 599 | 601 |
| 600 // If media is currently playing or the page indicated preload=auto or the | 602 // If media is currently playing or the page indicated preload=auto or the |
| 601 // the server does not support the byte range request or we do not want to go | 603 // the server does not support the byte range request or we do not want to go |
| 602 // too far ahead of the read head, use threshold strategy to enable/disable | 604 // too far ahead of the read head, use threshold strategy to enable/disable |
| 603 // deferring when the buffer is full/depleted. | 605 // deferring when the buffer is full/depleted. |
| 604 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 606 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
| 605 } | 607 } |
| 606 | 608 |
| 607 } // namespace media | 609 } // namespace media |
| OLD | NEW |