Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "webkit/glue/media/buffered_data_source.h" | 5 #include "webkit/glue/media/buffered_data_source.h" |
| 6 | 6 |
| 7 #include "media/base/filter_host.h" | 7 #include "media/base/filter_host.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "webkit/glue/media/web_data_source_factory.h" | 9 #include "webkit/glue/media/web_data_source_factory.h" |
| 10 #include "webkit/glue/webkit_glue.h" | 10 #include "webkit/glue/webkit_glue.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 initialize_callback->Run(status); | 451 initialize_callback->Run(status); |
| 452 } | 452 } |
| 453 | 453 |
| 454 ///////////////////////////////////////////////////////////////////////////// | 454 ///////////////////////////////////////////////////////////////////////////// |
| 455 // BufferedResourceLoader callback methods. | 455 // BufferedResourceLoader callback methods. |
| 456 void BufferedDataSource::HttpInitialStartCallback(int error) { | 456 void BufferedDataSource::HttpInitialStartCallback(int error) { |
| 457 DCHECK(MessageLoop::current() == render_loop_); | 457 DCHECK(MessageLoop::current() == render_loop_); |
| 458 DCHECK(loader_.get()); | 458 DCHECK(loader_.get()); |
| 459 | 459 |
| 460 int64 instance_size = loader_->instance_size(); | 460 int64 instance_size = loader_->instance_size(); |
| 461 bool partial_response = loader_->partial_response(); | |
| 462 bool success = error == net::OK; | 461 bool success = error == net::OK; |
| 463 | 462 |
| 464 if (!initialize_callback_.get()) { | 463 if (!initialize_callback_.get()) { |
| 465 loader_->Stop(); | 464 loader_->Stop(); |
| 466 return; | 465 return; |
| 467 } | 466 } |
| 468 | 467 |
| 469 if (success) { | 468 if (success) { |
| 470 // TODO(hclam): Needs more thinking about supporting servers without range | 469 // TODO(hclam): Needs more thinking about supporting servers without range |
| 471 // request or their partial response is not complete. | 470 // request or their partial response is not complete. |
| 472 total_bytes_ = instance_size; | 471 total_bytes_ = instance_size; |
| 473 loaded_ = false; | 472 loaded_ = false; |
| 474 streaming_ = (instance_size == kPositionNotSpecified) || !partial_response; | 473 streaming_ = (instance_size == kPositionNotSpecified) || |
| 474 !loader_->range_supported(); | |
| 475 } else { | 475 } else { |
| 476 // TODO(hclam): In case of failure, we can retry several times. | 476 // TODO(hclam): In case of failure, we can retry several times. |
| 477 loader_->Stop(); | 477 loader_->Stop(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) { | 480 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) { |
| 481 // Assuming that the Range header was causing the problem. Retry without | 481 // Assuming that the Range header was causing the problem. Retry without |
| 482 // the Range header. | 482 // the Range header. |
| 483 using_range_request_ = false; | 483 using_range_request_ = false; |
| 484 loader_ = CreateResourceLoader(kPositionNotSpecified, | 484 loader_ = CreateResourceLoader(kPositionNotSpecified, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 | 565 |
| 566 UpdateHostState(); | 566 UpdateHostState(); |
| 567 DoneInitialization_Locked(media::PIPELINE_OK); | 567 DoneInitialization_Locked(media::PIPELINE_OK); |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 | 570 |
| 571 void BufferedDataSource::PartialReadStartCallback(int error) { | 571 void BufferedDataSource::PartialReadStartCallback(int error) { |
| 572 DCHECK(MessageLoop::current() == render_loop_); | 572 DCHECK(MessageLoop::current() == render_loop_); |
| 573 DCHECK(loader_.get()); | 573 DCHECK(loader_.get()); |
| 574 | 574 |
| 575 // This callback method is invoked after we have verified the server has | 575 if (error == net::OK) { |
|
acolwell GONE FROM CHROMIUM
2011/04/07 22:56:48
loader_->partial_response() is not needed here any
| |
| 576 // range request capability, so as a safety guard verify again the response | 576 // Once the request has started successfully, we can proceed with |
| 577 // is partial. | |
| 578 if (error == net::OK && loader_->partial_response()) { | |
| 579 // Once the range request has started successfully, we can proceed with | |
| 580 // reading from it. | 577 // reading from it. |
| 581 ReadInternal(); | 578 ReadInternal(); |
| 582 return; | 579 return; |
| 583 } | 580 } |
| 584 | 581 |
| 585 // Stop the resource loader since we have received an error. | 582 // Stop the resource loader since we have received an error. |
| 586 loader_->Stop(); | 583 loader_->Stop(); |
| 587 | 584 |
| 588 // We need to prevent calling to filter host and running the callback if | 585 // We need to prevent calling to filter host and running the callback if |
| 589 // we have received the stop signal. We need to lock down the whole callback | 586 // we have received the stop signal. We need to lock down the whole callback |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 // this object when Stop() method is ever called. Locking this method is safe | 621 // this object when Stop() method is ever called. Locking this method is safe |
| 625 // because |lock_| is only acquired in tasks on render thread. | 622 // because |lock_| is only acquired in tasks on render thread. |
| 626 base::AutoLock auto_lock(lock_); | 623 base::AutoLock auto_lock(lock_); |
| 627 if (stop_signal_received_) | 624 if (stop_signal_received_) |
| 628 return; | 625 return; |
| 629 | 626 |
| 630 if (error > 0) { | 627 if (error > 0) { |
| 631 // If a position error code is received, read was successful. So copy | 628 // If a position error code is received, read was successful. So copy |
| 632 // from intermediate read buffer to the target read buffer. | 629 // from intermediate read buffer to the target read buffer. |
| 633 memcpy(read_buffer_, intermediate_read_buffer_.get(), error); | 630 memcpy(read_buffer_, intermediate_read_buffer_.get(), error); |
| 631 } else if (error == 0 && total_bytes_ == kPositionNotSpecified) { | |
| 632 // We've reached the end of the file and we didn't know the total size | |
| 633 // before. Update the total size so Read()s past the end of the file will | |
| 634 // fail like they would if we had known the file size at the beginning. | |
| 635 total_bytes_ = loader_->instance_size(); | |
| 636 | |
| 637 if (total_bytes_ != kPositionNotSpecified) | |
| 638 host()->SetTotalBytes(total_bytes_); | |
|
Ami GONE FROM CHROMIUM
2011/04/08 03:02:10
Do you not need to check that host()!=NULL?
acolwell GONE FROM CHROMIUM
2011/04/18 22:09:56
Done.
| |
| 634 } | 639 } |
| 635 DoneRead_Locked(error); | 640 DoneRead_Locked(error); |
| 636 } | 641 } |
| 637 | 642 |
| 638 void BufferedDataSource::NetworkEventCallback() { | 643 void BufferedDataSource::NetworkEventCallback() { |
| 639 DCHECK(MessageLoop::current() == render_loop_); | 644 DCHECK(MessageLoop::current() == render_loop_); |
| 640 DCHECK(loader_.get()); | 645 DCHECK(loader_.get()); |
| 641 | 646 |
| 642 // In case of non-HTTP request we don't need to report network events, | 647 // In case of non-HTTP request we don't need to report network events, |
| 643 // so return immediately. | 648 // so return immediately. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 | 688 |
| 684 if (streaming_) { | 689 if (streaming_) { |
| 685 filter_host->SetStreaming(true); | 690 filter_host->SetStreaming(true); |
| 686 } else { | 691 } else { |
| 687 filter_host->SetTotalBytes(total_bytes_); | 692 filter_host->SetTotalBytes(total_bytes_); |
| 688 filter_host->SetBufferedBytes(buffered_bytes_); | 693 filter_host->SetBufferedBytes(buffered_bytes_); |
| 689 } | 694 } |
| 690 } | 695 } |
| 691 | 696 |
| 692 } // namespace webkit_glue | 697 } // namespace webkit_glue |
| OLD | NEW |