Commit a0af9d91 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Add checks to help debug a crash

BUG=1009839

Change-Id: I2307fb1e693a963b9e472d73dd01cc944b0e3306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929438
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717871}
parent 9258320c
...@@ -136,6 +136,7 @@ void DownloadFileImpl::SourceStream::RegisterCompletionCallback( ...@@ -136,6 +136,7 @@ void DownloadFileImpl::SourceStream::RegisterCompletionCallback(
InputStream::StreamState DownloadFileImpl::SourceStream::Read( InputStream::StreamState DownloadFileImpl::SourceStream::Read(
scoped_refptr<net::IOBuffer>* data, scoped_refptr<net::IOBuffer>* data,
size_t* length) { size_t* length) {
CHECK(input_stream_);
return input_stream_->Read(data, length); return input_stream_->Read(data, length);
} }
...@@ -177,6 +178,8 @@ DownloadFileImpl::DownloadFileImpl( ...@@ -177,6 +178,8 @@ DownloadFileImpl::DownloadFileImpl(
DownloadFileImpl::~DownloadFileImpl() { DownloadFileImpl::~DownloadFileImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!use_test_task_runner_ && task_runner_)
CHECK(!main_task_runner_->BelongsToCurrentThread());
TRACE_EVENT_NESTABLE_ASYNC_END0("download", "DownloadFileActive", TRACE_EVENT_NESTABLE_ASYNC_END0("download", "DownloadFileActive",
download_id_); download_id_);
...@@ -248,7 +251,7 @@ void DownloadFileImpl::AddInputStream(std::unique_ptr<InputStream> stream, ...@@ -248,7 +251,7 @@ void DownloadFileImpl::AddInputStream(std::unique_ptr<InputStream> stream,
CancelRequest(offset); CancelRequest(offset);
return; return;
} }
DCHECK(source_streams_.find(offset) == source_streams_.end()); CHECK(source_streams_.find(offset) == source_streams_.end());
source_streams_[offset] = source_streams_[offset] =
std::make_unique<SourceStream>(offset, offset, std::move(stream)); std::make_unique<SourceStream>(offset, offset, std::move(stream));
OnSourceStreamAdded(source_streams_[offset].get()); OnSourceStreamAdded(source_streams_[offset].get());
...@@ -579,6 +582,17 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream, ...@@ -579,6 +582,17 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream,
DownloadInterruptReason reason = DOWNLOAD_INTERRUPT_REASON_NONE; DownloadInterruptReason reason = DOWNLOAD_INTERRUPT_REASON_NONE;
base::TimeDelta delta( base::TimeDelta delta(
base::TimeDelta::FromMilliseconds(kMaxTimeBlockingFileThreadMs)); base::TimeDelta::FromMilliseconds(kMaxTimeBlockingFileThreadMs));
// TODO(qinmin): remove this once crbug.com/1009839 is fixed.
bool stream_exists = false;
for (auto& stream : source_streams_) {
SourceStream* stream_ptr = stream.second.get();
if (stream_ptr == source_stream) {
stream_exists = true;
break;
}
}
CHECK(stream_exists);
// Take care of any file local activity required. // Take care of any file local activity required.
do { do {
state = source_stream->Read(&incoming_data, &incoming_data_size); state = source_stream->Read(&incoming_data, &incoming_data_size);
...@@ -915,6 +929,7 @@ void DownloadFileImpl::DebugStates() const { ...@@ -915,6 +929,7 @@ void DownloadFileImpl::DebugStates() const {
void DownloadFileImpl::SetTaskRunnerForTesting( void DownloadFileImpl::SetTaskRunnerForTesting(
scoped_refptr<base::SequencedTaskRunner> task_runner) { scoped_refptr<base::SequencedTaskRunner> task_runner) {
task_runner_ = std::move(task_runner); task_runner_ = std::move(task_runner);
use_test_task_runner_ = true;
} }
DownloadFileImpl::RenameParameters::RenameParameters( DownloadFileImpl::RenameParameters::RenameParameters(
......
...@@ -72,6 +72,8 @@ InputStream::StreamState StreamHandleInputStream::Read( ...@@ -72,6 +72,8 @@ InputStream::StreamState StreamHandleInputStream::Read(
if (!handle_watcher_) if (!handle_watcher_)
return InputStream::EMPTY; return InputStream::EMPTY;
CHECK(stream_handle_);
CHECK(stream_handle_->stream);
*length = kBytesToRead; *length = kBytesToRead;
*data = base::MakeRefCounted<net::IOBuffer>(kBytesToRead); *data = base::MakeRefCounted<net::IOBuffer>(kBytesToRead);
MojoResult mojo_result = stream_handle_->stream->ReadData( MojoResult mojo_result = stream_handle_->stream->ReadData(
......
...@@ -382,6 +382,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile { ...@@ -382,6 +382,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile {
// TaskRunner this object lives on after initialization. // TaskRunner this object lives on after initialization.
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
// TODO(qinmin): remove this once crbug.com/1009839 is fixed.
bool use_test_task_runner_ = false;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
base::FilePath display_name_; base::FilePath display_name_;
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment