Commit 83733880 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Migrate RenderProcessHostImpl from the FILE thread to task scheduler.

Bug: 689520
Change-Id: I65b372857d44c52f97986d02598c74db8d423312
Reviewed-on: https://chromium-review.googlesource.com/567783Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486194}
parent 9e6de2fd
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/task_scheduler/post_task.h"
#include "base/timer/elapsed_timer.h" #include "base/timer/elapsed_timer.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
...@@ -66,8 +67,19 @@ void HyphenationImpl::Create(const service_manager::BindSourceInfo& source_info, ...@@ -66,8 +67,19 @@ void HyphenationImpl::Create(const service_manager::BindSourceInfo& source_info,
std::move(request)); std::move(request));
} }
// static
scoped_refptr<base::SequencedTaskRunner> HyphenationImpl::GetTaskRunner() {
CR_DEFINE_STATIC_LOCAL(
scoped_refptr<base::SequencedTaskRunner>, runner,
(base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
base::TaskPriority::USER_BLOCKING})));
return runner;
}
void HyphenationImpl::OpenDictionary(const std::string& locale, void HyphenationImpl::OpenDictionary(const std::string& locale,
OpenDictionaryCallback callback) { OpenDictionaryCallback callback) {
DCHECK(GetTaskRunner()->RunsTasksInCurrentSequence());
if (IsValidLocale(locale)) if (IsValidLocale(locale))
std::move(callback).Run(GetDictionaryFile(locale)); std::move(callback).Run(GetDictionaryFile(locale));
else else
......
...@@ -23,6 +23,8 @@ class HyphenationImpl : public blink::mojom::Hyphenation { ...@@ -23,6 +23,8 @@ class HyphenationImpl : public blink::mojom::Hyphenation {
static void Create(const service_manager::BindSourceInfo& source_info, static void Create(const service_manager::BindSourceInfo& source_info,
blink::mojom::HyphenationRequest); blink::mojom::HyphenationRequest);
static scoped_refptr<base::SequencedTaskRunner> GetTaskRunner();
// Hyphenation: // Hyphenation:
void OpenDictionary(const std::string& locale, void OpenDictionary(const std::string& locale,
OpenDictionaryCallback callback) override; OpenDictionaryCallback callback) override;
......
...@@ -20,7 +20,6 @@ MimeRegistryImpl::~MimeRegistryImpl() = default; ...@@ -20,7 +20,6 @@ MimeRegistryImpl::~MimeRegistryImpl() = default;
void MimeRegistryImpl::Create( void MimeRegistryImpl::Create(
const service_manager::BindSourceInfo& source_info, const service_manager::BindSourceInfo& source_info,
blink::mojom::MimeRegistryRequest request) { blink::mojom::MimeRegistryRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
mojo::MakeStrongBinding(base::MakeUnique<MimeRegistryImpl>(), mojo::MakeStrongBinding(base::MakeUnique<MimeRegistryImpl>(),
std::move(request)); std::move(request));
} }
...@@ -28,7 +27,7 @@ void MimeRegistryImpl::Create( ...@@ -28,7 +27,7 @@ void MimeRegistryImpl::Create(
void MimeRegistryImpl::GetMimeTypeFromExtension( void MimeRegistryImpl::GetMimeTypeFromExtension(
const std::string& extension, const std::string& extension,
GetMimeTypeFromExtensionCallback callback) { GetMimeTypeFromExtensionCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::string mime_type; std::string mime_type;
net::GetMimeTypeFromExtension( net::GetMimeTypeFromExtension(
base::FilePath::FromUTF8Unsafe(extension).value(), &mime_type); base::FilePath::FromUTF8Unsafe(extension).value(), &mime_type);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CONTENT_BROWSER_MIME_REGISTRY_IMPL_H_ #ifndef CONTENT_BROWSER_MIME_REGISTRY_IMPL_H_
#define CONTENT_BROWSER_MIME_REGISTRY_IMPL_H_ #define CONTENT_BROWSER_MIME_REGISTRY_IMPL_H_
#include "base/macros.h"
#include "base/sequence_checker.h"
#include "third_party/WebKit/public/platform/mime_registry.mojom.h" #include "third_party/WebKit/public/platform/mime_registry.mojom.h"
namespace service_manager { namespace service_manager {
...@@ -25,6 +27,10 @@ class MimeRegistryImpl : public blink::mojom::MimeRegistry { ...@@ -25,6 +27,10 @@ class MimeRegistryImpl : public blink::mojom::MimeRegistry {
void GetMimeTypeFromExtension( void GetMimeTypeFromExtension(
const std::string& extension, const std::string& extension,
GetMimeTypeFromExtensionCallback callback) override; GetMimeTypeFromExtensionCallback callback) override;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(MimeRegistryImpl);
}; };
} // namespace content } // namespace content
......
...@@ -318,7 +318,6 @@ void GetContexts( ...@@ -318,7 +318,6 @@ void GetContexts(
// Creates a file used for handing over to the renderer. // Creates a file used for handing over to the renderer.
IPC::PlatformFileForTransit CreateFileForProcess(base::FilePath file_path) { IPC::PlatformFileForTransit CreateFileForProcess(base::FilePath file_path) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
base::File dump_file(file_path, base::File dump_file(file_path,
base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND); base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND);
if (!dump_file.IsValid()) { if (!dump_file.IsValid()) {
...@@ -1641,13 +1640,14 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { ...@@ -1641,13 +1640,14 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
registry.get(), base::Bind(&CreateMemoryCoordinatorHandle, GetID())); registry.get(), base::Bind(&CreateMemoryCoordinatorHandle, GetID()));
} }
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = registry->AddInterface(
BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE); base::Bind(&MimeRegistryImpl::Create),
registry->AddInterface(base::Bind(&MimeRegistryImpl::Create), base::CreateSequencedTaskRunnerWithTraits(
file_task_runner); {base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
base::TaskPriority::USER_BLOCKING}));
#if BUILDFLAG(USE_MINIKIN_HYPHENATION) #if BUILDFLAG(USE_MINIKIN_HYPHENATION)
registry->AddInterface(base::Bind(&hyphenation::HyphenationImpl::Create), registry->AddInterface(base::Bind(&hyphenation::HyphenationImpl::Create),
file_task_runner); hyphenation::HyphenationImpl::GetTaskRunner());
#endif #endif
registry->AddInterface(base::Bind(&device::GamepadMonitor::Create)); registry->AddInterface(base::Bind(&device::GamepadMonitor::Create));
...@@ -2867,11 +2867,11 @@ void RenderProcessHostImpl::EnableAudioDebugRecordings( ...@@ -2867,11 +2867,11 @@ void RenderProcessHostImpl::EnableAudioDebugRecordings(
void RenderProcessHostImpl::DisableAudioDebugRecordings() { void RenderProcessHostImpl::DisableAudioDebugRecordings() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Posting on the FILE thread and then replying back on the UI thread is only // Posting on the sequence and then replying back on the UI thread is only
// for avoiding races between enable and disable. Nothing is done on the FILE // for avoiding races between enable and disable. Nothing is done on the
// thread. // sequence.
BrowserThread::PostTaskAndReply( GetAecDumpFileTaskRunner().PostTaskAndReply(
BrowserThread::FILE, FROM_HERE, base::Bind(&base::DoNothing), FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&RenderProcessHostImpl::SendDisableAecDumpToRenderer, base::Bind(&RenderProcessHostImpl::SendDisableAecDumpToRenderer,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
...@@ -3752,8 +3752,8 @@ void RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread(int id) { ...@@ -3752,8 +3752,8 @@ void RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread(int id) {
void RenderProcessHostImpl::EnableAecDumpForId(const base::FilePath& file, void RenderProcessHostImpl::EnableAecDumpForId(const base::FilePath& file,
int id) { int id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
BrowserThread::FILE, FROM_HERE, &GetAecDumpFileTaskRunner(), FROM_HERE,
base::Bind(&CreateFileForProcess, file.AddExtension(IntToStringType(id))), base::Bind(&CreateFileForProcess, file.AddExtension(IntToStringType(id))),
base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer, base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer,
weak_factory_.GetWeakPtr(), id)); weak_factory_.GetWeakPtr(), id));
...@@ -3776,6 +3776,16 @@ base::FilePath RenderProcessHostImpl::GetAecDumpFilePathWithExtensions( ...@@ -3776,6 +3776,16 @@ base::FilePath RenderProcessHostImpl::GetAecDumpFilePathWithExtensions(
return file.AddExtension(IntToStringType(base::GetProcId(GetHandle()))) return file.AddExtension(IntToStringType(base::GetProcId(GetHandle())))
.AddExtension(kAecDumpFileNameAddition); .AddExtension(kAecDumpFileNameAddition);
} }
base::SequencedTaskRunner& RenderProcessHostImpl::GetAecDumpFileTaskRunner() {
if (!audio_debug_recordings_file_task_runner_) {
audio_debug_recordings_file_task_runner_ =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
base::TaskPriority::USER_BLOCKING});
}
return *audio_debug_recordings_file_task_runner_;
}
#endif // BUILDFLAG(ENABLE_WEBRTC) #endif // BUILDFLAG(ENABLE_WEBRTC)
void RenderProcessHostImpl::RecomputeAndUpdateWebKitPreferences() { void RenderProcessHostImpl::RecomputeAndUpdateWebKitPreferences() {
......
...@@ -465,6 +465,7 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -465,6 +465,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
IPC::PlatformFileForTransit file_for_transit); IPC::PlatformFileForTransit file_for_transit);
void SendDisableAecDumpToRenderer(); void SendDisableAecDumpToRenderer();
base::FilePath GetAecDumpFilePathWithExtensions(const base::FilePath& file); base::FilePath GetAecDumpFilePathWithExtensions(const base::FilePath& file);
base::SequencedTaskRunner& GetAecDumpFileTaskRunner();
#endif #endif
static void OnMojoError(int render_process_id, const std::string& error); static void OnMojoError(int render_process_id, const std::string& error);
...@@ -655,6 +656,9 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -655,6 +656,9 @@ class CONTENT_EXPORT RenderProcessHostImpl
WebRtcStopRtpDumpCallback stop_rtp_dump_callback_; WebRtcStopRtpDumpCallback stop_rtp_dump_callback_;
WebRTCEventLogHost webrtc_eventlog_host_; WebRTCEventLogHost webrtc_eventlog_host_;
scoped_refptr<base::SequencedTaskRunner>
audio_debug_recordings_file_task_runner_;
#endif #endif
// Forwards messages between WebRTCInternals in the browser process // Forwards messages between WebRTCInternals in the browser process
......
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