Commit 39b8a004 authored by nick's avatar nick Committed by Commit bot

Fix TaskmanagerIoThreadHelper bug.

Deleting the TaskManagerIoThreadHelper should cancel any pending
OnMultipleBytesReadIO calls. If it doesn't, we can sometimes fail the
DCHECK(!bytes_read_buffer_.empty()); check.

BUG=None
TEST=TaskManagerOOPIFBrowserTest.LeavePageWithCrossSiteIframes/0

Review URL: https://codereview.chromium.org/1918423002

Cr-Commit-Position: refs/heads/master@{#389889}
parent 0101c9fd
...@@ -59,7 +59,7 @@ void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request, ...@@ -59,7 +59,7 @@ void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request,
g_io_thread_helper->OnNetworkBytesRead(request, bytes_read); g_io_thread_helper->OnNetworkBytesRead(request, bytes_read);
} }
TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() { TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
} }
...@@ -67,18 +67,14 @@ TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() { ...@@ -67,18 +67,14 @@ TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
} }
// static
void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() { void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (!g_io_thread_helper) DCHECK(!bytes_read_buffer_.empty());
return;
DCHECK(!g_io_thread_helper->bytes_read_buffer_.empty());
std::vector<BytesReadParam>* bytes_read_buffer = std::vector<BytesReadParam>* bytes_read_buffer =
new std::vector<BytesReadParam>(); new std::vector<BytesReadParam>();
g_io_thread_helper->bytes_read_buffer_.swap(*bytes_read_buffer); bytes_read_buffer_.swap(*bytes_read_buffer);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, content::BrowserThread::UI,
...@@ -114,9 +110,9 @@ void TaskManagerIoThreadHelper::OnNetworkBytesRead( ...@@ -114,9 +110,9 @@ void TaskManagerIoThreadHelper::OnNetworkBytesRead(
// delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them
// after one second from now. // after one second from now.
content::BrowserThread::PostDelayedTask( content::BrowserThread::PostDelayedTask(
content::BrowserThread::IO, content::BrowserThread::IO, FROM_HERE,
FROM_HERE, base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesReadIO,
base::Bind(TaskManagerIoThreadHelper::OnMultipleBytesReadIO), weak_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(1)); base::TimeDelta::FromSeconds(1));
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
namespace net { namespace net {
class URLRequest; class URLRequest;
...@@ -78,7 +79,7 @@ class TaskManagerIoThreadHelper { ...@@ -78,7 +79,7 @@ class TaskManagerIoThreadHelper {
// We gather multiple notifications on the IO thread in one second before a // We gather multiple notifications on the IO thread in one second before a
// call is made to the following function to start the processing. // call is made to the following function to start the processing.
static void OnMultipleBytesReadIO(); void OnMultipleBytesReadIO();
// This will update the task manager with the network bytes read. // This will update the task manager with the network bytes read.
void OnNetworkBytesRead(const net::URLRequest& request, int64_t bytes_read); void OnNetworkBytesRead(const net::URLRequest& request, int64_t bytes_read);
...@@ -87,6 +88,8 @@ class TaskManagerIoThreadHelper { ...@@ -87,6 +88,8 @@ class TaskManagerIoThreadHelper {
// of bytes read from URLRequests. // of bytes read from URLRequests.
std::vector<BytesReadParam> bytes_read_buffer_; std::vector<BytesReadParam> bytes_read_buffer_;
base::WeakPtrFactory<TaskManagerIoThreadHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerIoThreadHelper); DISALLOW_COPY_AND_ASSIGN(TaskManagerIoThreadHelper);
}; };
......
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