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

Side by Side Diff: webkit/media/buffered_data_source.cc

Issue 9113023: Fire canplaythrough as soon as download defers to fix autoplay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
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/media/buffered_data_source.h" 5 #include "webkit/media/buffered_data_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "media/base/media_log.h" 8 #include "media/base/media_log.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "webkit/media/web_data_source_factory.h" 10 #include "webkit/media/web_data_source_factory.h"
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 590
591 if (error > 0) { 591 if (error > 0) {
592 // If a position error code is received, read was successful. So copy 592 // If a position error code is received, read was successful. So copy
593 // from intermediate read buffer to the target read buffer. 593 // from intermediate read buffer to the target read buffer.
594 memcpy(read_buffer_, intermediate_read_buffer_.get(), error); 594 memcpy(read_buffer_, intermediate_read_buffer_.get(), error);
595 } else if (error == 0 && total_bytes_ == kPositionNotSpecified) { 595 } else if (error == 0 && total_bytes_ == kPositionNotSpecified) {
596 // We've reached the end of the file and we didn't know the total size 596 // We've reached the end of the file and we didn't know the total size
597 // before. Update the total size so Read()s past the end of the file will 597 // before. Update the total size so Read()s past the end of the file will
598 // fail like they would if we had known the file size at the beginning. 598 // fail like they would if we had known the file size at the beginning.
599 total_bytes_ = loader_->instance_size(); 599 total_bytes_ = loader_->instance_size();
600 if (total_bytes_ != kPositionNotSpecified)
601 buffered_bytes_ = total_bytes_;
600 602
601 if (host() && total_bytes_ != kPositionNotSpecified) { 603 UpdateHostState_Locked();
602 host()->SetTotalBytes(total_bytes_);
603 host()->SetBufferedBytes(total_bytes_);
604 }
605 } 604 }
606 DoneRead_Locked(error); 605 DoneRead_Locked(error);
607 } 606 }
608 607
609 void BufferedDataSource::NetworkEventCallback() { 608 void BufferedDataSource::NetworkEventCallback() {
610 DCHECK(MessageLoop::current() == render_loop_); 609 DCHECK(MessageLoop::current() == render_loop_);
611 DCHECK(loader_.get()); 610 DCHECK(loader_.get());
612 611
613 // In case of non-HTTP request we don't need to report network events, 612 // In case of non-HTTP request we don't need to report network events,
614 // so return immediately. 613 // so return immediately.
(...skipping 12 matching lines...) Expand all
627 // method to prevent bad things from happening. The reason behind this is 626 // method to prevent bad things from happening. The reason behind this is
628 // that we cannot guarantee tasks on render thread have completely stopped 627 // that we cannot guarantee tasks on render thread have completely stopped
629 // when we receive the Stop() method call. So only way to solve this is to 628 // when we receive the Stop() method call. So only way to solve this is to
630 // let tasks on render thread to run but make sure they don't call outside 629 // let tasks on render thread to run but make sure they don't call outside
631 // this object when Stop() method is ever called. Locking this method is safe 630 // this object when Stop() method is ever called. Locking this method is safe
632 // because |lock_| is only acquired in tasks on render thread. 631 // because |lock_| is only acquired in tasks on render thread.
633 base::AutoLock auto_lock(lock_); 632 base::AutoLock auto_lock(lock_);
634 if (stop_signal_received_) 633 if (stop_signal_received_)
635 return; 634 return;
636 635
637 if (is_downloading_data != is_downloading_data_) { 636 is_downloading_data_ = is_downloading_data;
638 is_downloading_data_ = is_downloading_data; 637 buffered_bytes_ = buffered_position + 1;
639 if (host())
640 host()->SetNetworkActivity(is_downloading_data);
641 }
642 638
643 buffered_bytes_ = buffered_position + 1; 639 UpdateHostState_Locked();
644 if (host())
645 host()->SetBufferedBytes(buffered_bytes_);
646 } 640 }
647 641
648 void BufferedDataSource::UpdateHostState_Locked() { 642 void BufferedDataSource::UpdateHostState_Locked() {
649 // Called from various threads, under lock. 643 // Called from various threads, under lock.
650 lock_.AssertAcquired(); 644 lock_.AssertAcquired();
651 645
652 if (!host()) 646 if (!host())
653 return; 647 return;
654 648
655 if (total_bytes_ != kPositionNotSpecified) 649 if (total_bytes_ != kPositionNotSpecified)
656 host()->SetTotalBytes(total_bytes_); 650 host()->SetTotalBytes(total_bytes_);
651 host()->SetNetworkActivity(is_downloading_data_);
657 host()->SetBufferedBytes(buffered_bytes_); 652 host()->SetBufferedBytes(buffered_bytes_);
658 } 653 }
659 654
660 } // namespace webkit_media 655 } // namespace webkit_media
OLDNEW
« no previous file with comments | « media/base/download_rate_monitor_unittest.cc ('k') | webkit/media/buffered_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698