Commit 154c384e authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Simplify initialization of utility thread.

Utility thread is a thread for utilities that make use of Blink.
Currently, the WebThread object for that thread is defined as
WebThreadImplForUtilityThread, but we can remove it if we initialize
Blink with blink::CreateMainThreadAndInitialize(), because the
utility thread does not require multi-thread nor other complex
functionalities.

UtilityBlinkPlatformImpl inherits from BlinkPlatformImpl, which is
a base class for blink::Platform defined in content/. This patch
makes it directly inherit from blink::Platform, since the utility
thread does not require functions defined in BlinkPlatformImpl --
BlinkPlatformImpl's functions are basically for full-fledged browser,
and we don't need them in the utility thread.

Bug: 826203
Change-Id: I57af86931af176ef5d1bd08d0f0ceb5e60d9d65b
Reviewed-on: https://chromium-review.googlesource.com/1175746
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584030}
parent 9cfff7e2
...@@ -17,8 +17,6 @@ jumbo_source_set("utility") { ...@@ -17,8 +17,6 @@ jumbo_source_set("utility") {
sources = [ sources = [
"in_process_utility_thread.cc", "in_process_utility_thread.cc",
"in_process_utility_thread.h", "in_process_utility_thread.h",
"utility_blink_platform_impl.cc",
"utility_blink_platform_impl.h",
"utility_blink_platform_with_sandbox_support_impl.cc", "utility_blink_platform_with_sandbox_support_impl.cc",
"utility_blink_platform_with_sandbox_support_impl.h", "utility_blink_platform_with_sandbox_support_impl.h",
"utility_main.cc", "utility_main.cc",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/utility/utility_blink_platform_impl.h"
#include "third_party/blink/public/platform/scheduler/child/webthread_base.h"
namespace content {
UtilityBlinkPlatformImpl::UtilityBlinkPlatformImpl()
: main_thread_(blink::scheduler::WebThreadBase::InitializeUtilityThread()) {
}
UtilityBlinkPlatformImpl::~UtilityBlinkPlatformImpl() {
}
blink::WebThread* UtilityBlinkPlatformImpl::CurrentThread() {
if (main_thread_->IsCurrentThread())
return main_thread_.get();
return BlinkPlatformImpl::CurrentThread();
}
} // namespace content
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_UTILITY_UTILITY_BLINK_PLATFORM_IMPL_H_
#define CONTENT_UTILITY_UTILITY_BLINK_PLATFORM_IMPL_H_
#include <memory>
#include "base/macros.h"
#include "content/child/blink_platform_impl.h"
namespace blink {
namespace scheduler {
class WebThreadBase;
}
}
namespace content {
class UtilityBlinkPlatformImpl : public BlinkPlatformImpl {
public:
UtilityBlinkPlatformImpl();
~UtilityBlinkPlatformImpl() override;
// BlinkPlatformImpl implementation.
blink::WebThread* CurrentThread() override;
private:
std::unique_ptr<blink::scheduler::WebThreadBase> main_thread_;
DISALLOW_COPY_AND_ASSIGN(UtilityBlinkPlatformImpl);
};
} // namespace content
#endif // CONTENT_UTILITY_UTILITY_BLINK_PLATFORM_IMPL_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/utility/utility_blink_platform_impl.h" #include "third_party/blink/public/platform/platform.h"
#if defined(OS_POSIX) && !defined(OS_ANDROID) #if defined(OS_POSIX) && !defined(OS_ANDROID)
#include "components/services/font/public/cpp/font_loader.h" // nogncheck #include "components/services/font/public/cpp/font_loader.h" // nogncheck
...@@ -28,8 +28,7 @@ namespace content { ...@@ -28,8 +28,7 @@ namespace content {
// This class extends from UtilityBlinkPlatformImpl with added blink web // This class extends from UtilityBlinkPlatformImpl with added blink web
// sandbox support. // sandbox support.
class UtilityBlinkPlatformWithSandboxSupportImpl class UtilityBlinkPlatformWithSandboxSupportImpl : public blink::Platform {
: public UtilityBlinkPlatformImpl {
public: public:
UtilityBlinkPlatformWithSandboxSupportImpl() = delete; UtilityBlinkPlatformWithSandboxSupportImpl() = delete;
explicit UtilityBlinkPlatformWithSandboxSupportImpl( explicit UtilityBlinkPlatformWithSandboxSupportImpl(
......
...@@ -8,12 +8,10 @@ ...@@ -8,12 +8,10 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/child/blink_platform_impl.h"
#include "content/child/child_process.h" #include "content/child/child_process.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/common/simple_connection_filter.h" #include "content/public/common/simple_connection_filter.h"
#include "content/public/utility/content_utility_client.h" #include "content/public/utility/content_utility_client.h"
#include "content/utility/utility_blink_platform_impl.h"
#include "content/utility/utility_blink_platform_with_sandbox_support_impl.h" #include "content/utility/utility_blink_platform_with_sandbox_support_impl.h"
#include "content/utility/utility_service_factory.h" #include "content/utility/utility_service_factory.h"
#include "ipc/ipc_sync_channel.h" #include "ipc/ipc_sync_channel.h"
...@@ -120,9 +118,8 @@ void UtilityThreadImpl::EnsureBlinkInitializedInternal(bool sandbox_support) { ...@@ -120,9 +118,8 @@ void UtilityThreadImpl::EnsureBlinkInitializedInternal(bool sandbox_support) {
sandbox_support sandbox_support
? std::make_unique<UtilityBlinkPlatformWithSandboxSupportImpl>( ? std::make_unique<UtilityBlinkPlatformWithSandboxSupportImpl>(
GetConnector()) GetConnector())
: std::make_unique<UtilityBlinkPlatformImpl>(); : std::make_unique<blink::Platform>();
blink::Platform::Initialize(blink_platform_impl_.get(), blink::Platform::CreateMainThreadAndInitialize(blink_platform_impl_.get());
blink_platform_impl_->CurrentThread());
} }
void UtilityThreadImpl::Init() { void UtilityThreadImpl::Init() {
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
#include "content/public/utility/utility_thread.h" #include "content/public/utility/utility_thread.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/mojom/service_factory.mojom.h" #include "services/service_manager/public/mojom/service_factory.mojom.h"
#include "third_party/blink/public/platform/platform.h"
namespace content { namespace content {
class UtilityBlinkPlatformImpl;
class UtilityServiceFactory; class UtilityServiceFactory;
namespace mojom { namespace mojom {
...@@ -64,7 +64,7 @@ class UtilityThreadImpl : public UtilityThread, ...@@ -64,7 +64,7 @@ class UtilityThreadImpl : public UtilityThread,
service_manager::mojom::ServiceFactoryRequest request); service_manager::mojom::ServiceFactoryRequest request);
// blink::Platform implementation if needed. // blink::Platform implementation if needed.
std::unique_ptr<UtilityBlinkPlatformImpl> blink_platform_impl_; std::unique_ptr<blink::Platform> blink_platform_impl_;
// service_manager::mojom::ServiceFactory for service_manager::Service // service_manager::mojom::ServiceFactory for service_manager::Service
// hosting. // hosting.
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "services/data_decoder/image_decoder_impl.h" #include "services/data_decoder/image_decoder_impl.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/scheduler/child/webthread_base.h"
#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/blink.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/jpeg_codec.h" #include "ui/gfx/codec/jpeg_codec.h"
...@@ -78,25 +77,19 @@ class Request { ...@@ -78,25 +77,19 @@ class Request {
// image decoding call. // image decoding call.
class BlinkInitializer : public blink::Platform { class BlinkInitializer : public blink::Platform {
public: public:
BlinkInitializer() BlinkInitializer() {
: main_thread_(
blink::scheduler::WebThreadBase::InitializeUtilityThread()) {
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
gin::V8Initializer::LoadV8Snapshot(kSnapshotType); gin::V8Initializer::LoadV8Snapshot(kSnapshotType);
gin::V8Initializer::LoadV8Natives(); gin::V8Initializer::LoadV8Natives();
#endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // V8_USE_EXTERNAL_STARTUP_DATA
service_manager::BinderRegistry empty_registry; service_manager::BinderRegistry empty_registry;
blink::Initialize(this, &empty_registry, CurrentThread()); blink::CreateMainThreadAndInitialize(this, &empty_registry);
} }
~BlinkInitializer() override {} ~BlinkInitializer() override {}
blink::WebThread* CurrentThread() override { return main_thread_.get(); }
private: private:
std::unique_ptr<blink::scheduler::WebThreadBase> main_thread_;
DISALLOW_COPY_AND_ASSIGN(BlinkInitializer); DISALLOW_COPY_AND_ASSIGN(BlinkInitializer);
}; };
......
...@@ -160,6 +160,9 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -160,6 +160,9 @@ class BLINK_PLATFORM_EXPORT Platform {
// You should not pass in a Platform object that is not fully instantiated. // You should not pass in a Platform object that is not fully instantiated.
static void SetCurrentPlatformForTesting(Platform*); static void SetCurrentPlatformForTesting(Platform*);
Platform();
virtual ~Platform();
// May return null. // May return null.
virtual WebCookieJar* CookieJar() { return nullptr; } virtual WebCookieJar* CookieJar() { return nullptr; }
...@@ -702,9 +705,6 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -702,9 +705,6 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual bool IsTakingV8ContextSnapshot() { return false; } virtual bool IsTakingV8ContextSnapshot() { return false; }
protected: protected:
Platform();
virtual ~Platform();
WebThread* main_thread_; WebThread* main_thread_;
private: private:
......
...@@ -33,8 +33,6 @@ class BLINK_PLATFORM_EXPORT WebThreadBase : public WebThread { ...@@ -33,8 +33,6 @@ class BLINK_PLATFORM_EXPORT WebThreadBase : public WebThread {
const WebThreadCreationParams& params); const WebThreadCreationParams& params);
static std::unique_ptr<WebThreadBase> CreateCompositorThread( static std::unique_ptr<WebThreadBase> CreateCompositorThread(
const WebThreadCreationParams& params); const WebThreadCreationParams& params);
// Must be called on utility thread.
static std::unique_ptr<WebThreadBase> InitializeUtilityThread();
// WebThread implementation. // WebThread implementation.
bool IsCurrentThread() const override; bool IsCurrentThread() const override;
......
...@@ -110,8 +110,6 @@ blink_platform_sources("scheduler") { ...@@ -110,8 +110,6 @@ blink_platform_sources("scheduler") {
"util/thread_type.h", "util/thread_type.h",
"util/tracing_helper.cc", "util/tracing_helper.cc",
"util/tracing_helper.h", "util/tracing_helper.h",
"utility/webthread_impl_for_utility_thread.cc",
"utility/webthread_impl_for_utility_thread.h",
"worker/compositor_metrics_helper.cc", "worker/compositor_metrics_helper.cc",
"worker/compositor_metrics_helper.h", "worker/compositor_metrics_helper.h",
"worker/compositor_thread_scheduler.cc", "worker/compositor_thread_scheduler.cc",
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/pending_task.h" #include "base/pending_task.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "third_party/blink/renderer/platform/scheduler/child/webthread_impl_for_worker_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/child/webthread_impl_for_worker_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/utility/webthread_impl_for_utility_thread.h"
#include "third_party/blink/renderer/platform/scheduler/worker/compositor_thread_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/worker/compositor_thread_scheduler.h"
namespace blink { namespace blink {
...@@ -124,9 +123,5 @@ std::unique_ptr<WebThreadBase> WebThreadBase::CreateCompositorThread( ...@@ -124,9 +123,5 @@ std::unique_ptr<WebThreadBase> WebThreadBase::CreateCompositorThread(
return std::make_unique<WebThreadForCompositor>(params); return std::make_unique<WebThreadForCompositor>(params);
} }
std::unique_ptr<WebThreadBase> WebThreadBase::InitializeUtilityThread() {
return std::make_unique<WebThreadImplForUtilityThread>();
}
} // namespace scheduler } // namespace scheduler
} // namespace blink } // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/scheduler/utility/webthread_impl_for_utility_thread.h"
#include "base/threading/thread_task_runner_handle.h"
namespace blink {
namespace scheduler {
WebThreadImplForUtilityThread::WebThreadImplForUtilityThread()
: task_runner_(base::ThreadTaskRunnerHandle::Get()),
thread_id_(base::PlatformThread::CurrentId()) {}
WebThreadImplForUtilityThread::~WebThreadImplForUtilityThread() = default;
blink::ThreadScheduler* WebThreadImplForUtilityThread::Scheduler() const {
return nullptr;
}
blink::PlatformThreadId WebThreadImplForUtilityThread::ThreadId() const {
return thread_id_;
}
scoped_refptr<base::SingleThreadTaskRunner>
WebThreadImplForUtilityThread::GetTaskRunner() const {
return task_runner_;
}
void WebThreadImplForUtilityThread::Init() {}
} // namespace scheduler
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_UTILITY_WEBTHREAD_IMPL_FOR_UTILITY_THREAD_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_UTILITY_WEBTHREAD_IMPL_FOR_UTILITY_THREAD_H_
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/single_thread_task_runner.h"
#include "third_party/blink/public/platform/scheduler/child/webthread_base.h"
#include "third_party/blink/renderer/platform/platform_export.h"
namespace blink {
namespace scheduler {
class PLATFORM_EXPORT WebThreadImplForUtilityThread
: public scheduler::WebThreadBase {
public:
WebThreadImplForUtilityThread();
~WebThreadImplForUtilityThread() override;
// WebThread implementation.
ThreadScheduler* Scheduler() const override;
PlatformThreadId ThreadId() const override;
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const override;
// WebThreadBase implementation.
void Init() override;
private:
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
PlatformThreadId thread_id_;
DISALLOW_COPY_AND_ASSIGN(WebThreadImplForUtilityThread);
};
} // namespace scheduler
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_UTILITY_WEBTHREAD_IMPL_FOR_UTILITY_THREAD_H_
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