Commit 588611ac authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Pass main thread WebThread to Platform::Initialize().

The main thread's WebThread is currently owned by each embedder, but we
plan to have it owned by Platform and eventually stop exposing WebThread
to non-Blink directories.

Currently, Platform::CurrentThread() is used for two purposes: (1) to
obtain the pointer to the main thread WebThread object, and (2) to
return the current thread's WebThread object in thread-local storage.
This patch gets rid of (1) and move it to Platform::Initialize()'s
argument, so we can easily shift the ownership of WebThread in the
future.

TBR=eroman@chromium.org,kinuko@chromium.org,dalecurtis@chromium.org,jcivelli@chromium.org

Bug: 826203
Change-Id: I93608b13f6b84a47112865da486647afc46ab039
Reviewed-on: https://chromium-review.googlesource.com/1154854Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579733}
parent 6b0ccefa
......@@ -26,7 +26,7 @@ class InitOnce : public blink::Platform {
InitOnce() {
base::CommandLine::Init(0, nullptr);
mojo::core::Init();
blink::Platform::Initialize(this);
blink::Platform::Initialize(this, CurrentThread());
}
~InitOnce() override {}
......
......@@ -105,7 +105,8 @@ PpapiThread::PpapiThread(const base::CommandLine& command_line, bool is_broker)
command_line.GetSwitchValueASCII(switches::kPpapiFlashArgs));
blink_platform_impl_.reset(new PpapiBlinkPlatformImpl);
blink::Platform::Initialize(blink_platform_impl_.get());
blink::Platform::Initialize(blink_platform_impl_.get(),
blink_platform_impl_->CurrentThread());
if (!is_broker_) {
scoped_refptr<ppapi::proxy::PluginMessageFilter> plugin_filter(
......
......@@ -275,7 +275,8 @@ void RenderViewTest::SetUp() {
// Blink needs to be initialized before calling CreateContentRendererClient()
// because it uses blink internally.
blink_platform_impl_.Initialize();
blink::Initialize(blink_platform_impl_.Get(), &binder_registry_);
blink::Initialize(blink_platform_impl_.Get(), &binder_registry_,
blink_platform_impl_.Get()->CurrentThread());
content_client_.reset(CreateContentClient());
content_browser_client_.reset(CreateContentBrowserClient());
......
......@@ -1249,7 +1249,8 @@ void RenderThreadImpl::InitializeWebKit(
GetContentClient()
->renderer()
->SetRuntimeFeaturesDefaultsBeforeBlinkInitialization();
blink::Initialize(blink_platform_impl_.get(), registry);
blink::Initialize(blink_platform_impl_.get(), registry,
blink_platform_impl_->CurrentThread());
v8::Isolate* isolate = blink::MainThreadIsolate();
isolate->SetCreateHistogramFunction(CreateHistogram);
......
......@@ -180,7 +180,7 @@ TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport()
weak_factory_.GetWeakPtr()));
service_manager::BinderRegistry empty_registry;
blink::Initialize(this, &empty_registry);
blink::Initialize(this, &empty_registry, CurrentThread());
g_test_platform = this;
blink::SetLayoutTestMode(true);
blink::WebRuntimeFeatures::EnableDatabase(true);
......
......@@ -121,7 +121,8 @@ void UtilityThreadImpl::EnsureBlinkInitializedInternal(bool sandbox_support) {
? std::make_unique<UtilityBlinkPlatformWithSandboxSupportImpl>(
GetConnector())
: std::make_unique<UtilityBlinkPlatformImpl>();
blink::Platform::Initialize(blink_platform_impl_.get());
blink::Platform::Initialize(blink_platform_impl_.get(),
blink_platform_impl_->CurrentThread());
}
void UtilityThreadImpl::Init() {
......
......@@ -47,7 +47,6 @@ class BlinkPlatformWithTaskEnvironment : public blink::Platform {
main_thread_scheduler_->Shutdown();
}
protected:
blink::WebThread* CurrentThread() override {
CHECK(main_thread_->IsCurrentThread());
return main_thread_.get();
......@@ -83,7 +82,7 @@ static int RunTests(base::TestSuite* test_suite) {
BlinkPlatformWithTaskEnvironment platform_;
service_manager::BinderRegistry empty_registry;
blink::Initialize(&platform_, &empty_registry);
blink::Initialize(&platform_, &empty_registry, platform_.CurrentThread());
return test_suite->Run();
}
......
......@@ -87,7 +87,7 @@ class BlinkInitializer : public blink::Platform {
#endif // V8_USE_EXTERNAL_STARTUP_DATA
service_manager::BinderRegistry empty_registry;
blink::Initialize(this, &empty_registry);
blink::Initialize(this, &empty_registry, CurrentThread());
}
~BlinkInitializer() override {}
......
......@@ -138,7 +138,7 @@ class BLINK_PLATFORM_EXPORT Platform {
// Initialize platform and wtf. If you need to initialize the entire Blink,
// you should use blink::Initialize.
static void Initialize(Platform*);
static void Initialize(Platform*, WebThread* main_thread);
static Platform* Current();
// Used to switch the current platform only for testing.
......
......@@ -43,7 +43,9 @@ namespace blink {
// Must be called on the thread that will be the main thread before
// using any other public APIs. The provided Platform; must be
// non-null and must remain valid until the current thread calls shutdown.
BLINK_EXPORT void Initialize(Platform*, service_manager::BinderRegistry*);
BLINK_EXPORT void Initialize(Platform*,
service_manager::BinderRegistry*,
WebThread* main_thread);
// Get the V8 Isolate for the main thread.
// initialize must have been called first.
......
......@@ -83,9 +83,11 @@ static BlinkInitializer& GetBlinkInitializer() {
return *initializer;
}
void Initialize(Platform* platform, service_manager::BinderRegistry* registry) {
void Initialize(Platform* platform,
service_manager::BinderRegistry* registry,
WebThread* main_thread) {
DCHECK(registry);
Platform::Initialize(platform);
Platform::Initialize(platform, main_thread);
#if !defined(ARCH_CPU_X86_64) && !defined(ARCH_CPU_ARM64) && defined(OS_WIN)
// Reserve address space on 32 bit Windows, to make it likelier that large
......
......@@ -114,11 +114,11 @@ Platform::Platform() : main_thread_(nullptr) {
Platform::~Platform() = default;
void Platform::Initialize(Platform* platform) {
void Platform::Initialize(Platform* platform, WebThread* main_thread) {
DCHECK(!g_platform);
DCHECK(platform);
g_platform = platform;
g_platform->main_thread_ = platform->CurrentThread();
g_platform->main_thread_ = main_thread;
WTF::Initialize(CallOnMainThreadFunction);
......
......@@ -128,7 +128,8 @@ int ImageDecodeBenchMain(int argc, char* argv[]) {
// has a protected constructor.
class WebPlatform : public Platform {};
Platform::Initialize(new WebPlatform());
std::unique_ptr<WebPlatform> platform(new WebPlatform());
Platform::Initialize(platform.get(), platform->CurrentThread());
// Read entire file content into |data| (a contiguous block of memory) then
// decode it to verify the image and record its ImageMeta data.
......
......@@ -60,7 +60,7 @@ int main(int argc, char** argv) {
// Take a snapshot.
SnapshotPlatform platform;
service_manager::BinderRegistry empty_registry;
blink::Initialize(&platform, &empty_registry);
blink::Initialize(&platform, &empty_registry, platform.CurrentThread());
v8::StartupData blob = blink::WebV8ContextSnapshot::TakeSnapshot();
// Save the snapshot as a file. Filename is given in a command line option.
......
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