Commit 90e34895 authored by ssid's avatar ssid Committed by Commit bot

Adding WebThread and new BlinkPlatformImpl for utility thread.

For ensuring that the blink is always initialized with WebThread, the
call sites of blink must implement WebThread to expose the task runner.
UtilityThread is the only case where blink is run without exposing the
platform thread. This CL adds new WebThread implementation for
UtilityThread. After this change blink will always initialized with
platform thread and task runner exposed.

BUG=486782

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

Cr-Commit-Position: refs/heads/master@{#329442}
parent 57439937
......@@ -14,9 +14,13 @@
'public/utility/utility_thread.h',
'utility/in_process_utility_thread.cc',
'utility/in_process_utility_thread.h',
'utility/utility_blink_platform_impl.cc',
'utility/utility_blink_platform_impl.h',
'utility/utility_main.cc',
'utility/utility_thread_impl.cc',
'utility/utility_thread_impl.h',
'utility/webthread_impl_for_utility_thread.cc',
'utility/webthread_impl_for_utility_thread.h',
],
'include_dirs': [
'..',
......
......@@ -10,9 +10,13 @@ source_set("utility") {
sources = [
"in_process_utility_thread.cc",
"in_process_utility_thread.h",
"utility_blink_platform_impl.cc",
"utility_blink_platform_impl.h",
"utility_main.cc",
"utility_thread_impl.cc",
"utility_thread_impl.h",
"webthread_impl_for_utility_thread.cc",
"webthread_impl_for_utility_thread.h",
]
configs += [ "//content:content_implementation" ]
......
include_rules = [
"+components/scheduler/child",
"+content/child",
"+content/public/utility",
"+sandbox/win/src",
......
// 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 "content/utility/webthread_impl_for_utility_thread.h"
namespace content {
UtilityBlinkPlatformImpl::UtilityBlinkPlatformImpl()
: main_thread_(new WebThreadImplForUtilityThread()) {
}
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 "content/child/blink_platform_impl.h"
namespace content {
class WebThreadImplForUtilityThread;
class UtilityBlinkPlatformImpl : public BlinkPlatformImpl {
public:
UtilityBlinkPlatformImpl();
~UtilityBlinkPlatformImpl() override;
// BlinkPlatformImpl implementation.
blink::WebThread* currentThread() override;
private:
scoped_ptr<WebThreadImplForUtilityThread> main_thread_;
DISALLOW_COPY_AND_ASSIGN(UtilityBlinkPlatformImpl);
};
} // namespace content
#endif // CONTENT_UTILITY_UTILITY_BLINK_PLATFORM_IMPL_H_
......@@ -14,6 +14,7 @@
#include "content/common/utility_messages.h"
#include "content/public/common/content_switches.h"
#include "content/public/utility/content_utility_client.h"
#include "content/utility/utility_blink_platform_impl.h"
#include "ipc/ipc_sync_channel.h"
#include "third_party/WebKit/public/web/WebKit.h"
......@@ -80,7 +81,7 @@ void UtilityThreadImpl::Init() {
// we run the utility thread on separate thread. This means that if any code
// needs WebKit initialized in the utility process, they need to have
// another path to support single process mode.
blink_platform_impl_.reset(new BlinkPlatformImpl);
blink_platform_impl_.reset(new UtilityBlinkPlatformImpl);
blink::initialize(blink_platform_impl_.get());
}
GetContentClient()->utility()->UtilityThreadStarted();
......
......@@ -20,6 +20,7 @@ class FilePath;
namespace content {
class BlinkPlatformImpl;
class UtilityBlinkPlatformImpl;
#if defined(COMPILER_MSVC)
// See explanation for other RenderViewHostImpl which is the same issue.
......@@ -56,7 +57,7 @@ class UtilityThreadImpl : public UtilityThread,
// True when we're running in batch mode.
bool batch_mode_;
scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
scoped_ptr<UtilityBlinkPlatformImpl> blink_platform_impl_;
DISALLOW_COPY_AND_ASSIGN(UtilityThreadImpl);
};
......
// 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/webthread_impl_for_utility_thread.h"
namespace content {
WebThreadImplForUtilityThread::WebThreadImplForUtilityThread()
: task_runner_(base::MessageLoopProxy::current()),
thread_id_(base::PlatformThread::CurrentId()) {
}
WebThreadImplForUtilityThread::~WebThreadImplForUtilityThread() {
}
blink::WebScheduler* WebThreadImplForUtilityThread::scheduler() const {
NOTIMPLEMENTED();
return nullptr;
}
blink::PlatformThreadId WebThreadImplForUtilityThread::threadId() const {
return thread_id_;
}
base::SingleThreadTaskRunner* WebThreadImplForUtilityThread::TaskRunner()
const {
return task_runner_.get();
}
scheduler::SingleThreadIdleTaskRunner*
WebThreadImplForUtilityThread::IdleTaskRunner() const {
NOTIMPLEMENTED();
return nullptr;
}
} // 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_WEBTHREAD_IMPL_FOR_UTILITY_THREAD_H_
#define CONTENT_UTILITY_WEBTHREAD_IMPL_FOR_UTILITY_THREAD_H_
#include "base/memory/ref_counted.h"
#include "components/scheduler/child/webthread_base.h"
namespace content {
class WebThreadImplForUtilityThread : public scheduler::WebThreadBase {
public:
WebThreadImplForUtilityThread();
~WebThreadImplForUtilityThread() override;
// blink::WebThread implementation.
blink::WebScheduler* scheduler() const override;
blink::PlatformThreadId threadId() const override;
// WebThreadBase implementation.
base::SingleThreadTaskRunner* TaskRunner() const override;
scheduler::SingleThreadIdleTaskRunner* IdleTaskRunner() const override;
private:
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
blink::PlatformThreadId thread_id_;
DISALLOW_COPY_AND_ASSIGN(WebThreadImplForUtilityThread);
};
} // namespace content
#endif // CONTENT_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