Chromium Code Reviews| 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 InternalInit(); | |
| 428 } | |
| 429 | |
| 430 BlinkPlatformImpl::BlinkPlatformImpl( | |
| 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 // TODO(alexclarke): Use c++11 delegated constructors when allowed. | |
| 439 InternalInit(); | |
| 440 } | |
| 441 | |
| 442 void BlinkPlatformImpl::InternalInit() { | |
| 427 // ChildThread may not exist in some tests. | 443 // ChildThread may not exist in some tests. |
| 428 if (ChildThread::current()) { | 444 if (ChildThread::current()) { |
| 429 geofencing_provider_.reset(new WebGeofencingProviderImpl( | 445 geofencing_provider_.reset(new WebGeofencingProviderImpl( |
| 430 ChildThread::current()->thread_safe_sender())); | 446 ChildThread::current()->thread_safe_sender())); |
| 431 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); | 447 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); |
| 432 notification_dispatcher_ = | 448 notification_dispatcher_ = |
| 433 ChildThread::current()->notification_dispatcher(); | 449 ChildThread::current()->notification_dispatcher(); |
| 434 } | 450 } |
| 451 | |
| 452 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
| |
| 435 } | 453 } |
| 436 | 454 |
| 437 BlinkPlatformImpl::~BlinkPlatformImpl() { | 455 BlinkPlatformImpl::~BlinkPlatformImpl() { |
| 438 } | 456 } |
| 439 | 457 |
| 440 WebURLLoader* BlinkPlatformImpl::createURLLoader() { | 458 WebURLLoader* BlinkPlatformImpl::createURLLoader() { |
| 441 ChildThread* child_thread = ChildThread::current(); | 459 ChildThread* child_thread = ChildThread::current(); |
| 442 // There may be no child thread in RenderViewTests. These tests can still use | 460 // There may be no child thread in RenderViewTests. These tests can still use |
| 443 // data URLs to bypass the ResourceDispatcher. | 461 // data URLs to bypass the ResourceDispatcher. |
| 444 return new WebURLLoaderImpl( | 462 return new WebURLLoaderImpl( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { | 501 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { |
| 484 return new WebThreadImpl(name); | 502 return new WebThreadImpl(name); |
| 485 } | 503 } |
| 486 | 504 |
| 487 blink::WebThread* BlinkPlatformImpl::currentThread() { | 505 blink::WebThread* BlinkPlatformImpl::currentThread() { |
| 488 WebThreadImplForMessageLoop* thread = | 506 WebThreadImplForMessageLoop* thread = |
| 489 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); | 507 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); |
| 490 if (thread) | 508 if (thread) |
| 491 return (thread); | 509 return (thread); |
| 492 | 510 |
| 493 scoped_refptr<base::MessageLoopProxy> message_loop = | 511 scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
| 494 base::MessageLoopProxy::current(); | 512 if (main_thread_task_runner_.get() && |
| 495 if (!message_loop.get()) | 513 main_thread_task_runner_->BelongsToCurrentThread()) { |
| 514 task_runner = main_thread_task_runner_; | |
| 515 } else { | |
| 516 task_runner = base::MessageLoopProxy::current(); | |
| 517 } | |
| 518 | |
| 519 if (!task_runner.get()) | |
| 496 return NULL; | 520 return NULL; |
| 497 | 521 |
| 498 thread = new WebThreadImplForMessageLoop(message_loop.get()); | 522 thread = new WebThreadImplForMessageLoop(task_runner); |
| 499 current_thread_slot_.Set(thread); | 523 current_thread_slot_.Set(thread); |
| 500 return thread; | 524 return thread; |
| 501 } | 525 } |
| 502 | 526 |
| 503 void BlinkPlatformImpl::yieldCurrentThread() { | 527 void BlinkPlatformImpl::yieldCurrentThread() { |
| 504 base::PlatformThread::YieldCurrentThread(); | 528 base::PlatformThread::YieldCurrentThread(); |
| 505 } | 529 } |
| 506 | 530 |
| 507 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { | 531 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { |
| 508 return new WebWaitableEventImpl(); | 532 return new WebWaitableEventImpl(); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 this, &BlinkPlatformImpl::DoTimeout); | 1009 this, &BlinkPlatformImpl::DoTimeout); |
| 986 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); | 1010 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); |
| 987 } | 1011 } |
| 988 | 1012 |
| 989 void BlinkPlatformImpl::stopSharedTimer() { | 1013 void BlinkPlatformImpl::stopSharedTimer() { |
| 990 shared_timer_.Stop(); | 1014 shared_timer_.Stop(); |
| 991 } | 1015 } |
| 992 | 1016 |
| 993 void BlinkPlatformImpl::callOnMainThread( | 1017 void BlinkPlatformImpl::callOnMainThread( |
| 994 void (*func)(void*), void* context) { | 1018 void (*func)(void*), void* context) { |
| 995 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); | 1019 main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context)); |
| 996 } | 1020 } |
| 997 | 1021 |
| 998 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( | 1022 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( |
| 999 blink::WebGestureDevice device_source, | 1023 blink::WebGestureDevice device_source, |
| 1000 const blink::WebFloatPoint& velocity, | 1024 const blink::WebFloatPoint& velocity, |
| 1001 const blink::WebSize& cumulative_scroll) { | 1025 const blink::WebSize& cumulative_scroll) { |
| 1002 auto curve = WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 1026 auto curve = WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
| 1003 gfx::Vector2dF(velocity.x, velocity.y), | 1027 gfx::Vector2dF(velocity.x, velocity.y), |
| 1004 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height)); | 1028 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height)); |
| 1005 return curve.release(); | 1029 return curve.release(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 } | 1238 } |
| 1215 | 1239 |
| 1216 // static | 1240 // static |
| 1217 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | 1241 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { |
| 1218 WebThreadImplForMessageLoop* impl = | 1242 WebThreadImplForMessageLoop* impl = |
| 1219 static_cast<WebThreadImplForMessageLoop*>(thread); | 1243 static_cast<WebThreadImplForMessageLoop*>(thread); |
| 1220 delete impl; | 1244 delete impl; |
| 1221 } | 1245 } |
| 1222 | 1246 |
| 1223 } // namespace content | 1247 } // namespace content |
| OLD | NEW |