OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/blink_platform_impl.h" | 5 #include "content/child/blink_platform_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. | 411 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. |
412 // After a planned WebKit patch is landed, we need to add a case statement | 412 // After a planned WebKit patch is landed, we need to add a case statement |
413 // for the added symbol here. | 413 // for the added symbol here. |
414 default: | 414 default: |
415 break; | 415 break; |
416 } | 416 } |
417 return -1; | 417 return -1; |
418 } | 418 } |
419 | 419 |
420 BlinkPlatformImpl::BlinkPlatformImpl() | 420 BlinkPlatformImpl::BlinkPlatformImpl() |
421 : main_loop_(base::MessageLoop::current()), | 421 : main_thread_task_runner_(base::MessageLoopProxy::current()), |
422 shared_timer_func_(NULL), | 422 shared_timer_func_(NULL), |
423 shared_timer_fire_time_(0.0), | 423 shared_timer_fire_time_(0.0), |
424 shared_timer_fire_time_was_set_while_suspended_(false), | 424 shared_timer_fire_time_was_set_while_suspended_(false), |
425 shared_timer_suspended_(0), | 425 shared_timer_suspended_(0), |
426 current_thread_slot_(&DestroyCurrentThread) { | 426 current_thread_slot_(&DestroyCurrentThread) { |
427 // ChildThread may not exist in some tests. | 427 InternalInit(); |
428 } | |
429 | |
430 BlinkPlatformImpl::BlinkPlatformImpl( | |
Sami
2014/11/06 00:22:59
Delegated constructors still blocked it looks like
alex clarke (OOO till 29th)
2014/11/06 00:40:49
Lets just get this patch in :) I can add a fixme
| |
431 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | |
432 : main_thread_task_runner_(main_thread_task_runner), | |
433 shared_timer_func_(NULL), | |
434 shared_timer_fire_time_(0.0), | |
435 shared_timer_fire_time_was_set_while_suspended_(false), | |
436 shared_timer_suspended_(0), | |
437 current_thread_slot_(&DestroyCurrentThread) { | |
438 InternalInit(); | |
439 } | |
440 | |
441 void BlinkPlatformImpl::InternalInit() { | |
442 // ChildThread may not exist in some tests. | |
428 if (ChildThread::current()) { | 443 if (ChildThread::current()) { |
429 geofencing_provider_.reset(new WebGeofencingProviderImpl( | 444 geofencing_provider_.reset(new WebGeofencingProviderImpl( |
430 ChildThread::current()->thread_safe_sender())); | 445 ChildThread::current()->thread_safe_sender())); |
431 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); | 446 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); |
432 notification_dispatcher_ = | 447 notification_dispatcher_ = |
433 ChildThread::current()->notification_dispatcher(); | 448 ChildThread::current()->notification_dispatcher(); |
434 } | 449 } |
435 } | 450 } |
436 | 451 |
437 BlinkPlatformImpl::~BlinkPlatformImpl() { | 452 BlinkPlatformImpl::~BlinkPlatformImpl() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { | 498 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { |
484 return new WebThreadImpl(name); | 499 return new WebThreadImpl(name); |
485 } | 500 } |
486 | 501 |
487 blink::WebThread* BlinkPlatformImpl::currentThread() { | 502 blink::WebThread* BlinkPlatformImpl::currentThread() { |
488 WebThreadImplForMessageLoop* thread = | 503 WebThreadImplForMessageLoop* thread = |
489 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); | 504 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); |
490 if (thread) | 505 if (thread) |
491 return (thread); | 506 return (thread); |
492 | 507 |
493 scoped_refptr<base::MessageLoopProxy> message_loop = | 508 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
494 base::MessageLoopProxy::current(); | 509 base::MessageLoopProxy::current(); |
495 if (!message_loop.get()) | 510 if (main_thread_task_runner_.get() && |
511 main_thread_task_runner_->BelongsToCurrentThread()) { | |
Sami
2014/11/06 00:22:59
Could you rewrite this in a way that we don't do t
alex clarke (OOO till 29th)
2014/11/06 00:40:49
Done.
| |
512 task_runner = main_thread_task_runner_; | |
513 } | |
514 | |
515 if (!task_runner.get()) | |
496 return NULL; | 516 return NULL; |
497 | 517 |
498 thread = new WebThreadImplForMessageLoop(message_loop.get()); | 518 thread = new WebThreadImplForMessageLoop(task_runner); |
499 current_thread_slot_.Set(thread); | 519 current_thread_slot_.Set(thread); |
500 return thread; | 520 return thread; |
501 } | 521 } |
502 | 522 |
503 void BlinkPlatformImpl::yieldCurrentThread() { | 523 void BlinkPlatformImpl::yieldCurrentThread() { |
504 base::PlatformThread::YieldCurrentThread(); | 524 base::PlatformThread::YieldCurrentThread(); |
505 } | 525 } |
506 | 526 |
507 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { | 527 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { |
508 return new WebWaitableEventImpl(); | 528 return new WebWaitableEventImpl(); |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 this, &BlinkPlatformImpl::DoTimeout); | 1005 this, &BlinkPlatformImpl::DoTimeout); |
986 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); | 1006 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); |
987 } | 1007 } |
988 | 1008 |
989 void BlinkPlatformImpl::stopSharedTimer() { | 1009 void BlinkPlatformImpl::stopSharedTimer() { |
990 shared_timer_.Stop(); | 1010 shared_timer_.Stop(); |
991 } | 1011 } |
992 | 1012 |
993 void BlinkPlatformImpl::callOnMainThread( | 1013 void BlinkPlatformImpl::callOnMainThread( |
994 void (*func)(void*), void* context) { | 1014 void (*func)(void*), void* context) { |
995 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); | 1015 main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context)); |
996 } | 1016 } |
997 | 1017 |
998 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( | 1018 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( |
999 blink::WebGestureDevice device_source, | 1019 blink::WebGestureDevice device_source, |
1000 const blink::WebFloatPoint& velocity, | 1020 const blink::WebFloatPoint& velocity, |
1001 const blink::WebSize& cumulative_scroll) { | 1021 const blink::WebSize& cumulative_scroll) { |
1002 auto curve = WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 1022 auto curve = WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
1003 gfx::Vector2dF(velocity.x, velocity.y), | 1023 gfx::Vector2dF(velocity.x, velocity.y), |
1004 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height)); | 1024 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height)); |
1005 return curve.release(); | 1025 return curve.release(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1214 } | 1234 } |
1215 | 1235 |
1216 // static | 1236 // static |
1217 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | 1237 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { |
1218 WebThreadImplForMessageLoop* impl = | 1238 WebThreadImplForMessageLoop* impl = |
1219 static_cast<WebThreadImplForMessageLoop*>(thread); | 1239 static_cast<WebThreadImplForMessageLoop*>(thread); |
1220 delete impl; | 1240 delete impl; |
1221 } | 1241 } |
1222 | 1242 |
1223 } // namespace content | 1243 } // namespace content |
OLD | NEW |