Commit 1204628b authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[content] Use scoped_refptr<SequencedTaskRunner> in BrowserMessageFilter.

All interfaces should use scoped_refptr<SequencedTaskRunner> for passing
refcounted objects, which includes the task runners.

This is due to the fact that the embedder should be able to return the
only reference to the object and should not be forced to keep it alive.

R=clamy@chromium.org,gab@chromium.org
TBR=ddorwin@chromium.org
BUG=937336

Change-Id: I61a7b3c6e97b3c1ede4a2b462a2204d5437d1ed4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1634866Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665575}
parent 935eeca9
......@@ -119,7 +119,8 @@ bool CdmMessageFilterAndroid::OnMessageReceived(const IPC::Message& message) {
return handled;
}
base::TaskRunner* CdmMessageFilterAndroid::OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner>
CdmMessageFilterAndroid::OverrideTaskRunnerForMessage(
const IPC::Message& message) {
// Move the IPC handling to FILE thread as it is not very cheap.
if (message.type() == ChromeViewHostMsg_QueryKeySystemSupport::ID)
......
......@@ -31,7 +31,7 @@ class CdmMessageFilterAndroid : public content::BrowserMessageFilter {
// BrowserMessageFilter implementation.
bool OnMessageReceived(const IPC::Message& message) override;
base::TaskRunner* OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& message) override;
// Query the key system information.
......
......@@ -59,7 +59,8 @@ bool GinJavaBridgeMessageFilter::OnMessageReceived(
return handled;
}
base::TaskRunner* GinJavaBridgeMessageFilter::OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner>
GinJavaBridgeMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& message) {
// As the filter is only invoked for the messages of the particular class,
// we can return the task runner unconditionally.
......
......@@ -37,7 +37,7 @@ class GinJavaBridgeMessageFilter : public BrowserMessageFilter,
// BrowserMessageFilter
void OnDestruct() const override;
bool OnMessageReceived(const IPC::Message& message) override;
base::TaskRunner* OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& message) override;
// RenderProcessHostObserver
......
......@@ -40,8 +40,8 @@ bool JavaBridgeThread::CurrentlyOn() {
}
// static
base::TaskRunner* JavaBridgeThread::GetTaskRunner() {
return g_background_thread.Get().message_loop()->task_runner().get();
scoped_refptr<base::SingleThreadTaskRunner> JavaBridgeThread::GetTaskRunner() {
return g_background_thread.Get().message_loop()->task_runner();
}
} // namespace content
......@@ -6,10 +6,7 @@
#define CONTENT_BROWSER_ANDROID_JAVA_GIN_JAVA_JAVA_BRIDGE_THREAD_H_
#include "base/android/java_handler_thread.h"
namespace base {
class TaskRunner;
}
#include "base/single_thread_task_runner.h"
namespace content {
......@@ -21,7 +18,9 @@ class JavaBridgeThread : public base::android::JavaHandlerThread {
~JavaBridgeThread() override;
static bool CurrentlyOn();
static base::TaskRunner* GetTaskRunner();
// TODO(altimin): Make it const scoped_refptr& after we support this
// which is blocked by revoming MessageLoop::SetTaskRunner.
static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner();
};
} // namespace content
......
......@@ -63,7 +63,7 @@ class BrowserMessageFilter::Internal : public IPC::MessageFilter {
filter_->OverrideThreadForMessage(message, &thread);
if (thread == BrowserThread::IO) {
scoped_refptr<base::TaskRunner> runner =
scoped_refptr<base::SequencedTaskRunner> runner =
filter_->OverrideTaskRunnerForMessage(message);
if (runner.get()) {
runner->PostTask(
......@@ -160,7 +160,8 @@ bool BrowserMessageFilter::Send(IPC::Message* message) {
return false;
}
base::TaskRunner* BrowserMessageFilter::OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner>
BrowserMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& message) {
return nullptr;
}
......
......@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/process/process.h"
#include "base/sequenced_task_runner.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
......@@ -20,10 +21,6 @@
#include "base/synchronization/lock.h"
#endif
namespace base {
class TaskRunner;
}
namespace IPC {
class MessageFilter;
}
......@@ -75,7 +72,7 @@ class CONTENT_EXPORT BrowserMessageFilter
// return a non-null task runner which will target tasks accordingly.
// Note: To target the UI thread, please use OverrideThreadForMessage
// since that has extra checks to avoid deadlocks.
virtual base::TaskRunner* OverrideTaskRunnerForMessage(
virtual scoped_refptr<base::SequencedTaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& message);
// Override this to receive messages.
......
......@@ -59,7 +59,8 @@ void WebTestMessageFilter::OnDestruct() const {
BrowserThread::DeleteOnUIThread::Destruct(this);
}
base::TaskRunner* WebTestMessageFilter::OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner>
WebTestMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& message) {
switch (message.type()) {
case WebTestHostMsg_ClearAllDatabases::ID:
......@@ -73,8 +74,7 @@ base::TaskRunner* WebTestMessageFilter::OverrideTaskRunnerForMessage(
case WebTestHostMsg_InitiateCaptureDump::ID:
case WebTestHostMsg_InspectSecondaryWindow::ID:
case WebTestHostMsg_DeleteAllCookies::ID:
return base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})
.get();
return base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI});
}
return nullptr;
}
......
......@@ -55,7 +55,7 @@ class WebTestMessageFilter : public BrowserMessageFilter {
// BrowserMessageFilter implementation.
void OnDestruct() const override;
base::TaskRunner* OverrideTaskRunnerForMessage(
scoped_refptr<base::SequencedTaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& message) override;
bool OnMessageReceived(const IPC::Message& message) override;
......
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