Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: content/child/blink_platform_impl.cc

Issue 959803003: web-threads: Create a single instance of WebThread for each blink thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/blink_platform_impl.cc
diff --git a/content/child/blink_platform_impl.cc b/content/child/blink_platform_impl.cc
index f4d609b2f3f9535a0e352baac876888faba54a2b..eac44c4c7443fadb67d101c1434d96dca85f3323 100644
--- a/content/child/blink_platform_impl.cc
+++ b/content/child/blink_platform_impl.cc
@@ -13,7 +13,6 @@
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/process/process_metrics.h"
@@ -418,7 +417,7 @@ BlinkPlatformImpl::BlinkPlatformImpl()
shared_timer_fire_time_(0.0),
shared_timer_fire_time_was_set_while_suspended_(false),
shared_timer_suspended_(0),
- current_thread_slot_(&DestroyCurrentThread) {
+ current_thread_slot_() {
Sami 2015/03/02 11:40:02 nit: I don't think you need to initialize current_
sadrul 2015/03/02 16:53:21 Done.
InternalInit();
}
@@ -429,7 +428,7 @@ BlinkPlatformImpl::BlinkPlatformImpl(
shared_timer_fire_time_(0.0),
shared_timer_fire_time_was_set_while_suspended_(false),
shared_timer_suspended_(0),
- current_thread_slot_(&DestroyCurrentThread) {
+ current_thread_slot_() {
// TODO(alexclarke): Use c++11 delegated constructors when allowed.
InternalInit();
}
@@ -452,6 +451,11 @@ void BlinkPlatformImpl::InternalInit() {
}
}
+void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) {
+ DCHECK(!current_thread_slot_.Get());
+ current_thread_slot_.Set(thread);
+}
+
BlinkPlatformImpl::~BlinkPlatformImpl() {
}
@@ -499,23 +503,15 @@ bool BlinkPlatformImpl::isReservedIPAddress(
}
blink::WebThread* BlinkPlatformImpl::createThread(const char* name) {
- return new WebThreadImpl(name);
+ WebThreadImpl* thread = new WebThreadImpl(name);
+ thread->TaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS,
+ base::Unretained(this), thread));
+ return thread;
}
blink::WebThread* BlinkPlatformImpl::currentThread() {
- WebThreadImplForMessageLoop* thread =
- static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get());
- if (thread)
- return (thread);
-
- scoped_refptr<base::SingleThreadTaskRunner> task_runner =
- MainTaskRunnerForCurrentThread();
- if (!task_runner.get())
- return NULL;
-
- thread = new WebThreadImplForMessageLoop(task_runner);
- current_thread_slot_.Set(thread);
- return thread;
+ return static_cast<blink::WebThread*>(current_thread_slot_.Get());
}
void BlinkPlatformImpl::yieldCurrentThread() {
@@ -1244,13 +1240,6 @@ BlinkPlatformImpl::MainTaskRunnerForCurrentThread() {
}
}
-// static
-void BlinkPlatformImpl::DestroyCurrentThread(void* thread) {
- WebThreadImplForMessageLoop* impl =
- static_cast<WebThreadImplForMessageLoop*>(thread);
- delete impl;
-}
-
WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) {
return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString(
static_cast<ui::DomCode>(dom_code)));

Powered by Google App Engine
This is Rietveld 408576698