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

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

Issue 2481673004: media: Make sure we transition back to a non-loading state (Closed)
Patch Set: merged 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 | « no previous file | 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // fail like they would if we had known the file size at the beginning. 417 // fail like they would if we had known the file size at the beginning.
418 total_bytes_ = reader_->Tell(); 418 total_bytes_ = reader_->Tell();
419 if (total_bytes_ != kPositionNotSpecified) 419 if (total_bytes_ != kPositionNotSpecified)
420 host_->SetTotalBytes(total_bytes_); 420 host_->SetTotalBytes(total_bytes_);
421 } 421 }
422 422
423 ReadOperation::Run(std::move(read_op_), bytes_read); 423 ReadOperation::Run(std::move(read_op_), bytes_read);
424 } else { 424 } else {
425 reader_->Wait(1, base::Bind(&MultibufferDataSource::ReadTask, 425 reader_->Wait(1, base::Bind(&MultibufferDataSource::ReadTask,
426 weak_factory_.GetWeakPtr())); 426 weak_factory_.GetWeakPtr()));
427 UpdateLoadingState_Locked(false);
428 } 427 }
428 UpdateLoadingState_Locked(false);
429 } 429 }
430 430
431 void MultibufferDataSource::StopInternal_Locked() { 431 void MultibufferDataSource::StopInternal_Locked() {
432 lock_.AssertAcquired(); 432 lock_.AssertAcquired();
433 if (stop_signal_received_) 433 if (stop_signal_received_)
434 return; 434 return;
435 435
436 stop_signal_received_ = true; 436 stop_signal_received_ = true;
437 437
438 // Initialize() isn't part of the DataSource interface so don't call it in 438 // Initialize() isn't part of the DataSource interface so don't call it in
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 UpdateLoadingState_Locked(false); 539 UpdateLoadingState_Locked(false);
540 } 540 }
541 541
542 void MultibufferDataSource::UpdateLoadingState_Locked(bool force_loading) { 542 void MultibufferDataSource::UpdateLoadingState_Locked(bool force_loading) {
543 DVLOG(1) << __func__; 543 DVLOG(1) << __func__;
544 lock_.AssertAcquired(); 544 lock_.AssertAcquired();
545 if (assume_fully_buffered()) 545 if (assume_fully_buffered())
546 return; 546 return;
547 // Update loading state. 547 // Update loading state.
548 bool is_loading = !!reader_ && reader_->IsLoading(); 548 bool is_loading = !!reader_ && reader_->IsLoading();
549 if (read_op_)
550 is_loading = true;
551 if (force_loading || is_loading != loading_) { 549 if (force_loading || is_loading != loading_) {
552 loading_ = is_loading || force_loading; 550 bool loading = is_loading || force_loading;
553 551
554 if (!loading_ && cancel_on_defer_) { 552 if (!loading && cancel_on_defer_) {
553 if (read_op_) {
554 // We can't destroy the reader if a read operation is pending.
555 // UpdateLoadingState_Locked will be called again when the read
556 // operation is done.
557 return;
558 }
555 reader_.reset(nullptr); 559 reader_.reset(nullptr);
556 } 560 }
557 561
562 loading_ = loading;
563
558 // Callback could kill us, be sure to call it last. 564 // Callback could kill us, be sure to call it last.
559 downloading_cb_.Run(loading_); 565 downloading_cb_.Run(loading_);
560 } 566 }
561 } 567 }
562 568
563 void MultibufferDataSource::UpdateProgress() { 569 void MultibufferDataSource::UpdateProgress() {
564 DCHECK(render_task_runner_->BelongsToCurrentThread()); 570 DCHECK(render_task_runner_->BelongsToCurrentThread());
565 if (reader_) { 571 if (reader_) {
566 uint64_t available = reader_->Available(); 572 uint64_t available = reader_->Available();
567 uint64_t pos = reader_->Tell(); 573 uint64_t pos = reader_->Tell();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 reader_->SetPinRange(pin_backward, pin_forward); 634 reader_->SetPinRange(pin_backward, pin_forward);
629 635
630 if (preload_ == METADATA) { 636 if (preload_ == METADATA) {
631 reader_->SetPreload(0, 0); 637 reader_->SetPreload(0, 0);
632 } else { 638 } else {
633 reader_->SetPreload(preload_high, preload); 639 reader_->SetPreload(preload_high, preload);
634 } 640 }
635 } 641 }
636 642
637 } // namespace media 643 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/blink/multibuffer_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698