Chromium Code Reviews| Index: content/child/blink_platform_impl.cc |
| diff --git a/content/child/blink_platform_impl.cc b/content/child/blink_platform_impl.cc |
| index 79f72adcffcbe5daa58d9d36e8d9587f52cc11ce..d24d00aa023c9a76841ab9ae7ca41b203c3376a0 100644 |
| --- a/content/child/blink_platform_impl.cc |
| +++ b/content/child/blink_platform_impl.cc |
| @@ -418,12 +418,28 @@ static int ToMessageID(WebLocalizedString::Name name) { |
| } |
| BlinkPlatformImpl::BlinkPlatformImpl() |
| - : main_loop_(base::MessageLoop::current()), |
| + : main_thread_task_runner_(base::MessageLoopProxy::current()), |
| shared_timer_func_(NULL), |
| shared_timer_fire_time_(0.0), |
| shared_timer_fire_time_was_set_while_suspended_(false), |
| shared_timer_suspended_(0), |
| current_thread_slot_(&DestroyCurrentThread) { |
| + InternalInit(); |
| +} |
| + |
| +BlinkPlatformImpl::BlinkPlatformImpl( |
| + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
| + : main_thread_task_runner_(main_thread_task_runner), |
| + shared_timer_func_(NULL), |
| + shared_timer_fire_time_(0.0), |
| + shared_timer_fire_time_was_set_while_suspended_(false), |
| + shared_timer_suspended_(0), |
| + current_thread_slot_(&DestroyCurrentThread) { |
| + // TODO(alexclarke): Use c++11 delegated constructors when allowed. |
| + InternalInit(); |
| +} |
| + |
| +void BlinkPlatformImpl::InternalInit() { |
| // ChildThread may not exist in some tests. |
| if (ChildThread::current()) { |
| geofencing_provider_.reset(new WebGeofencingProviderImpl( |
| @@ -432,6 +448,8 @@ BlinkPlatformImpl::BlinkPlatformImpl() |
| notification_dispatcher_ = |
| ChildThread::current()->notification_dispatcher(); |
| } |
| + |
| + shared_timer_.SetTaskRunner(main_thread_task_runner_); |
|
Sami
2014/11/07 05:26:25
Do we need to check that the runner is non-null he
alex clarke (OOO till 29th)
2014/11/07 15:19:16
It probably doesn't hurt to check, however the pro
Sami
2014/11/07 18:48:33
Ok, I'm still a bit confused how this thing would
alex clarke (OOO till 29th)
2014/11/07 19:18:56
As discussed offline I added the null check here t
|
| } |
| BlinkPlatformImpl::~BlinkPlatformImpl() { |
| @@ -490,12 +508,18 @@ blink::WebThread* BlinkPlatformImpl::currentThread() { |
| if (thread) |
| return (thread); |
| - scoped_refptr<base::MessageLoopProxy> message_loop = |
| - base::MessageLoopProxy::current(); |
| - if (!message_loop.get()) |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
| + if (main_thread_task_runner_.get() && |
| + main_thread_task_runner_->BelongsToCurrentThread()) { |
| + task_runner = main_thread_task_runner_; |
| + } else { |
| + task_runner = base::MessageLoopProxy::current(); |
| + } |
| + |
| + if (!task_runner.get()) |
| return NULL; |
| - thread = new WebThreadImplForMessageLoop(message_loop.get()); |
| + thread = new WebThreadImplForMessageLoop(task_runner); |
| current_thread_slot_.Set(thread); |
| return thread; |
| } |
| @@ -992,7 +1016,7 @@ void BlinkPlatformImpl::stopSharedTimer() { |
| void BlinkPlatformImpl::callOnMainThread( |
| void (*func)(void*), void* context) { |
| - main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); |
| + main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context)); |
| } |
| blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( |