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

Side by Side Diff: media/blink/multibuffer_data_source.cc

Issue 2445993003: Make sure we get at least one progress callback (Closed)
Patch Set: fix tests Created 4 years, 1 month 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
« no previous file with comments | « media/blink/multibuffer_data_source.h ('k') | media/blink/multibuffer_data_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/multibuffer_data_source.h" 5 #include "media/blink/multibuffer_data_source.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 init_cb_ = init_cb; 171 init_cb_ = init_cb;
172 172
173 CreateResourceLoader(0, kPositionNotSpecified); 173 CreateResourceLoader(0, kPositionNotSpecified);
174 174
175 // We're not allowed to call Wait() if data is already available. 175 // We're not allowed to call Wait() if data is already available.
176 if (reader_->Available()) { 176 if (reader_->Available()) {
177 render_task_runner_->PostTask( 177 render_task_runner_->PostTask(
178 FROM_HERE, 178 FROM_HERE,
179 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); 179 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_));
180
181 // When the entire file is already in the cache, we won't get any more
182 // progress callbacks, which breaks some expectations. Post a task to
183 // make sure that the client gets at least one call each for the progress
184 // and loading callbacks.
185 render_task_runner_->PostTask(
186 FROM_HERE, base::Bind(&MultibufferDataSource::UpdateProgress,
187 weak_factory_.GetWeakPtr()));
180 } else { 188 } else {
181 reader_->Wait(1, 189 reader_->Wait(1,
182 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); 190 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_));
183 } 191 }
184 } 192 }
185 193
186 void MultibufferDataSource::OnRedirect( 194 void MultibufferDataSource::OnRedirect(
187 const scoped_refptr<UrlData>& destination) { 195 const scoped_refptr<UrlData>& destination) {
188 if (!destination) { 196 if (!destination) {
189 // A failure occured. 197 // A failure occured.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 media_log_->SetBooleanProperty("single_origin", single_origin_); 506 media_log_->SetBooleanProperty("single_origin", single_origin_);
499 media_log_->SetBooleanProperty("passed_cors_access_check", 507 media_log_->SetBooleanProperty("passed_cors_access_check",
500 DidPassCORSAccessCheck()); 508 DidPassCORSAccessCheck());
501 media_log_->SetBooleanProperty("range_header_supported", 509 media_log_->SetBooleanProperty("range_header_supported",
502 url_data_->range_supported()); 510 url_data_->range_supported());
503 } 511 }
504 512
505 render_task_runner_->PostTask( 513 render_task_runner_->PostTask(
506 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); 514 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success));
507 515
508 // When we tell our clients that we're loading below, it's possible that
509 // the entire file is already cashed. If that's true, then we won't get
510 // any progress callbacks later, so we'll never tell the client that we
511 // stopped loading. Post a task to make sure that we check the loading
512 // state at least once.
513 render_task_runner_->PostTask(
514 FROM_HERE, base::Bind(&MultibufferDataSource::UpdateLoadingState,
515 weak_factory_.GetWeakPtr()));
516 // Even if data is cached, say that we're loading at this point for 516 // Even if data is cached, say that we're loading at this point for
517 // compatibility. 517 // compatibility.
518 UpdateLoadingState_Locked(true); 518 UpdateLoadingState_Locked(true);
519 } 519 }
520 520
521 void MultibufferDataSource::ProgressCallback(int64_t begin, int64_t end) { 521 void MultibufferDataSource::ProgressCallback(int64_t begin, int64_t end) {
522 DVLOG(1) << __func__ << "(" << begin << ", " << end << ")"; 522 DVLOG(1) << __func__ << "(" << begin << ", " << end << ")";
523 DCHECK(render_task_runner_->BelongsToCurrentThread()); 523 DCHECK(render_task_runner_->BelongsToCurrentThread());
524 524
525 if (assume_fully_buffered()) 525 if (assume_fully_buffered())
chcunningham 2016/10/28 17:53:52 The tests in the bug have both been http://, but I
hubbe 2016/10/31 17:25:17 I'm not entirely sure why we do this, but it's bee
chcunningham 2016/10/31 18:12:39 Acknowledged.
526 return; 526 return;
527 527
528 base::AutoLock auto_lock(lock_); 528 base::AutoLock auto_lock(lock_);
529 529
530 if (end > begin) { 530 if (end > begin) {
531 // TODO(scherkus): we shouldn't have to lock to signal host(), see 531 // TODO(scherkus): we shouldn't have to lock to signal host(), see
532 // http://crbug.com/113712 for details. 532 // http://crbug.com/113712 for details.
533 if (stop_signal_received_) 533 if (stop_signal_received_)
534 return; 534 return;
535 535
(...skipping 17 matching lines...) Expand all
553 553
554 if (!loading_ && cancel_on_defer_) { 554 if (!loading_ && cancel_on_defer_) {
555 reader_.reset(nullptr); 555 reader_.reset(nullptr);
556 } 556 }
557 557
558 // Callback could kill us, be sure to call it last. 558 // Callback could kill us, be sure to call it last.
559 downloading_cb_.Run(loading_); 559 downloading_cb_.Run(loading_);
560 } 560 }
561 } 561 }
562 562
563 void MultibufferDataSource::UpdateLoadingState() { 563 void MultibufferDataSource::UpdateProgress() {
564 DCHECK(render_task_runner_->BelongsToCurrentThread()); 564 DCHECK(render_task_runner_->BelongsToCurrentThread());
565 base::AutoLock auto_lock(lock_); 565 if (reader_) {
566 UpdateLoadingState_Locked(false); 566 uint64_t available = reader_->Available();
567 uint64_t pos = reader_->Tell();
568 ProgressCallback(pos, pos + available);
569 }
567 } 570 }
568 571
569 void MultibufferDataSource::UpdateBufferSizes() { 572 void MultibufferDataSource::UpdateBufferSizes() {
570 DVLOG(1) << __func__; 573 DVLOG(1) << __func__;
571 if (!reader_) 574 if (!reader_)
572 return; 575 return;
573 576
574 if (!assume_fully_buffered()) { 577 if (!assume_fully_buffered()) {
575 // If the playback has started and the strategy is aggressive, then try to 578 // If the playback has started and the strategy is aggressive, then try to
576 // load as much as possible, assuming that the file is cacheable. (If not, 579 // load as much as possible, assuming that the file is cacheable. (If not,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); 618 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra);
616 619
617 if (preload_ == METADATA) { 620 if (preload_ == METADATA) {
618 reader_->SetPreload(0, 0); 621 reader_->SetPreload(0, 0);
619 } else { 622 } else {
620 reader_->SetPreload(preload_high, preload); 623 reader_->SetPreload(preload_high, preload);
621 } 624 }
622 } 625 }
623 626
624 } // namespace media 627 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/multibuffer_data_source.h ('k') | media/blink/multibuffer_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698