OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 DCHECK(MessageLoop::current() == render_loop_); | 731 DCHECK(MessageLoop::current() == render_loop_); |
732 return single_origin_; | 732 return single_origin_; |
733 } | 733 } |
734 | 734 |
735 void BufferedDataSource::Abort() { | 735 void BufferedDataSource::Abort() { |
736 DCHECK(MessageLoop::current() == render_loop_); | 736 DCHECK(MessageLoop::current() == render_loop_); |
737 | 737 |
738 // If we are told to abort, immediately return from any pending read | 738 // If we are told to abort, immediately return from any pending read |
739 // with an error. | 739 // with an error. |
740 if (read_callback_.get()) { | 740 if (read_callback_.get()) { |
741 AutoLock auto_lock(lock_); | 741 AutoLock auto_lock(lock_); |
742 DoneRead_Locked(net::ERR_FAILED); | 742 DoneRead_Locked(net::ERR_FAILED); |
743 } | 743 } |
744 | 744 |
745 CleanupTask(); | 745 CleanupTask(); |
746 frame_ = NULL; | 746 frame_ = NULL; |
747 } | 747 } |
748 | 748 |
749 ///////////////////////////////////////////////////////////////////////////// | 749 ///////////////////////////////////////////////////////////////////////////// |
750 // BufferedDataSource, render thread tasks | 750 // BufferedDataSource, render thread tasks |
751 void BufferedDataSource::InitializeTask() { | 751 void BufferedDataSource::InitializeTask() { |
752 DCHECK(MessageLoop::current() == render_loop_); | 752 DCHECK(MessageLoop::current() == render_loop_); |
753 DCHECK(!loader_.get()); | 753 DCHECK(!loader_.get()); |
754 DCHECK(!stopped_on_render_loop_); | 754 if (stopped_on_render_loop_) |
| 755 return; |
755 | 756 |
756 // Kick starts the watch dog task that will handle connection timeout. | 757 // Kick starts the watch dog task that will handle connection timeout. |
757 // We run the watch dog 2 times faster the actual timeout so as to catch | 758 // We run the watch dog 2 times faster the actual timeout so as to catch |
758 // the timeout more accurately. | 759 // the timeout more accurately. |
759 watch_dog_timer_.Start( | 760 watch_dog_timer_.Start( |
760 GetTimeoutMilliseconds() / 2, | 761 GetTimeoutMilliseconds() / 2, |
761 this, | 762 this, |
762 &BufferedDataSource::WatchDogTask); | 763 &BufferedDataSource::WatchDogTask); |
763 | 764 |
764 if (IsHttpProtocol(url_)) { | 765 if (IsHttpProtocol(url_)) { |
(...skipping 16 matching lines...) Expand all Loading... |
781 NewCallback(this, &BufferedDataSource::NonHttpInitialStartCallback), | 782 NewCallback(this, &BufferedDataSource::NonHttpInitialStartCallback), |
782 NewCallback(this, &BufferedDataSource::NetworkEventCallback), | 783 NewCallback(this, &BufferedDataSource::NetworkEventCallback), |
783 frame_); | 784 frame_); |
784 } | 785 } |
785 } | 786 } |
786 | 787 |
787 void BufferedDataSource::ReadTask( | 788 void BufferedDataSource::ReadTask( |
788 int64 position, int read_size, uint8* buffer, | 789 int64 position, int read_size, uint8* buffer, |
789 media::DataSource::ReadCallback* read_callback) { | 790 media::DataSource::ReadCallback* read_callback) { |
790 DCHECK(MessageLoop::current() == render_loop_); | 791 DCHECK(MessageLoop::current() == render_loop_); |
791 | |
792 // If CleanupTask() was executed we should return immediately. We check this | |
793 // variable to prevent doing any actual work after clean up was done. We do | |
794 // not check |stop_signal_received_| because anything use of it has to be | |
795 // within |lock_| which is not desirable. | |
796 if (stopped_on_render_loop_) | 792 if (stopped_on_render_loop_) |
797 return; | 793 return; |
798 | 794 |
799 DCHECK(!read_callback_.get()); | 795 DCHECK(!read_callback_.get()); |
800 DCHECK(read_callback); | 796 DCHECK(read_callback); |
801 | 797 |
802 // Saves the read parameters. | 798 // Saves the read parameters. |
803 read_position_ = position; | 799 read_position_ = position; |
804 read_size_ = read_size; | 800 read_size_ = read_size; |
805 read_callback_.reset(read_callback); | 801 read_callback_.reset(read_callback); |
806 read_buffer_ = buffer; | 802 read_buffer_ = buffer; |
807 read_submitted_time_ = base::Time::Now(); | 803 read_submitted_time_ = base::Time::Now(); |
808 read_attempts_ = 0; | 804 read_attempts_ = 0; |
809 | 805 |
810 // Call to read internal to perform the actual read. | 806 // Call to read internal to perform the actual read. |
811 ReadInternal(); | 807 ReadInternal(); |
812 } | 808 } |
813 | 809 |
814 void BufferedDataSource::CleanupTask() { | 810 void BufferedDataSource::CleanupTask() { |
815 DCHECK(MessageLoop::current() == render_loop_); | 811 DCHECK(MessageLoop::current() == render_loop_); |
816 | |
817 // If we have already stopped, do nothing. | |
818 if (stopped_on_render_loop_) | 812 if (stopped_on_render_loop_) |
819 return; | 813 return; |
820 | 814 |
821 // Stop the watch dog. | 815 // Stop the watch dog. |
822 watch_dog_timer_.Stop(); | 816 watch_dog_timer_.Stop(); |
823 | 817 |
824 // We just need to stop the loader, so it stops activity. | 818 // We just need to stop the loader, so it stops activity. |
825 if (loader_.get()) | 819 if (loader_.get()) |
826 loader_->Stop(); | 820 loader_->Stop(); |
827 | 821 |
828 // Reset the parameters of the current read request. | 822 // Reset the parameters of the current read request. |
829 read_callback_.reset(); | 823 read_callback_.reset(); |
830 read_position_ = 0; | 824 read_position_ = 0; |
831 read_size_ = 0; | 825 read_size_ = 0; |
832 read_buffer_ = 0; | 826 read_buffer_ = 0; |
833 read_submitted_time_ = base::Time(); | 827 read_submitted_time_ = base::Time(); |
834 read_attempts_ = 0; | 828 read_attempts_ = 0; |
835 | 829 |
836 // Signal that stop task has finished execution. | 830 // Signal that stop task has finished execution. |
837 stopped_on_render_loop_ = true; | 831 stopped_on_render_loop_ = true; |
838 } | 832 } |
839 | 833 |
840 void BufferedDataSource::RestartLoadingTask() { | 834 void BufferedDataSource::RestartLoadingTask() { |
841 DCHECK(MessageLoop::current() == render_loop_); | 835 DCHECK(MessageLoop::current() == render_loop_); |
842 | |
843 // This variable is set in CleanupTask(). We check this and do an early | |
844 // return. The sequence of actions which enable this conditions is: | |
845 // 1. Stop() is called from the pipeline. | |
846 // 2. ReadCallback() is called from the resource loader. | |
847 // 3. CleanupTask() is executed. | |
848 // 4. RestartLoadingTask() is executed. | |
849 if (stopped_on_render_loop_) | 836 if (stopped_on_render_loop_) |
850 return; | 837 return; |
851 | 838 |
852 // If there's no outstanding read then return early. | 839 // If there's no outstanding read then return early. |
853 if (!read_callback_.get()) | 840 if (!read_callback_.get()) |
854 return; | 841 return; |
855 | 842 |
856 loader_ = CreateResourceLoader(read_position_, -1); | 843 loader_ = CreateResourceLoader(read_position_, -1); |
857 loader_->SetAllowDefer(!media_is_paused_); | 844 loader_->SetAllowDefer(!media_is_paused_); |
858 loader_->Start( | 845 loader_->Start( |
859 NewCallback(this, &BufferedDataSource::PartialReadStartCallback), | 846 NewCallback(this, &BufferedDataSource::PartialReadStartCallback), |
860 NewCallback(this, &BufferedDataSource::NetworkEventCallback), | 847 NewCallback(this, &BufferedDataSource::NetworkEventCallback), |
861 frame_); | 848 frame_); |
862 } | 849 } |
863 | 850 |
864 void BufferedDataSource::WatchDogTask() { | 851 void BufferedDataSource::WatchDogTask() { |
865 DCHECK(MessageLoop::current() == render_loop_); | 852 DCHECK(MessageLoop::current() == render_loop_); |
866 DCHECK(!stopped_on_render_loop_); | 853 if (stopped_on_render_loop_) |
| 854 return; |
867 | 855 |
868 // We only care if there is an active read request. | 856 // We only care if there is an active read request. |
869 if (!read_callback_.get()) | 857 if (!read_callback_.get()) |
870 return; | 858 return; |
871 | 859 |
872 DCHECK(loader_.get()); | 860 DCHECK(loader_.get()); |
873 base::TimeDelta delta = base::Time::Now() - read_submitted_time_; | 861 base::TimeDelta delta = base::Time::Now() - read_submitted_time_; |
874 if (delta < GetTimeoutMilliseconds()) | 862 if (delta < GetTimeoutMilliseconds()) |
875 return; | 863 return; |
876 | 864 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 return; | 1150 return; |
1163 | 1151 |
1164 if (network_activity != network_activity_) { | 1152 if (network_activity != network_activity_) { |
1165 network_activity_ = network_activity; | 1153 network_activity_ = network_activity; |
1166 host()->SetNetworkActivity(network_activity); | 1154 host()->SetNetworkActivity(network_activity); |
1167 } | 1155 } |
1168 host()->SetBufferedBytes(buffered_last_byte_position + 1); | 1156 host()->SetBufferedBytes(buffered_last_byte_position + 1); |
1169 } | 1157 } |
1170 | 1158 |
1171 } // namespace webkit_glue | 1159 } // namespace webkit_glue |
OLD | NEW |