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

Side by Side Diff: content/child/blink_platform_impl.cc

Issue 690703002: WebThreadImplForMessageLoop to use blink scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a TODO, removed stray whitespace Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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 }
435 } 451 }
436 452
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { 499 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) {
484 return new WebThreadImpl(name); 500 return new WebThreadImpl(name);
485 } 501 }
486 502
487 blink::WebThread* BlinkPlatformImpl::currentThread() { 503 blink::WebThread* BlinkPlatformImpl::currentThread() {
488 WebThreadImplForMessageLoop* thread = 504 WebThreadImplForMessageLoop* thread =
489 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); 505 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get());
490 if (thread) 506 if (thread)
491 return (thread); 507 return (thread);
492 508
493 scoped_refptr<base::MessageLoopProxy> message_loop = 509 scoped_refptr<base::SingleThreadTaskRunner> task_runner;
494 base::MessageLoopProxy::current(); 510 if (main_thread_task_runner_.get() &&
495 if (!message_loop.get()) 511 main_thread_task_runner_->BelongsToCurrentThread()) {
512 task_runner = main_thread_task_runner_;
513 } else {
514 task_runner = base::MessageLoopProxy::current();
515 }
516
517 if (!task_runner.get())
496 return NULL; 518 return NULL;
497 519
498 thread = new WebThreadImplForMessageLoop(message_loop.get()); 520 thread = new WebThreadImplForMessageLoop(task_runner);
499 current_thread_slot_.Set(thread); 521 current_thread_slot_.Set(thread);
500 return thread; 522 return thread;
501 } 523 }
502 524
503 void BlinkPlatformImpl::yieldCurrentThread() { 525 void BlinkPlatformImpl::yieldCurrentThread() {
504 base::PlatformThread::YieldCurrentThread(); 526 base::PlatformThread::YieldCurrentThread();
505 } 527 }
506 528
507 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { 529 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() {
508 return new WebWaitableEventImpl(); 530 return new WebWaitableEventImpl();
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 this, &BlinkPlatformImpl::DoTimeout); 1007 this, &BlinkPlatformImpl::DoTimeout);
986 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); 1008 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval));
987 } 1009 }
988 1010
989 void BlinkPlatformImpl::stopSharedTimer() { 1011 void BlinkPlatformImpl::stopSharedTimer() {
990 shared_timer_.Stop(); 1012 shared_timer_.Stop();
991 } 1013 }
992 1014
993 void BlinkPlatformImpl::callOnMainThread( 1015 void BlinkPlatformImpl::callOnMainThread(
994 void (*func)(void*), void* context) { 1016 void (*func)(void*), void* context) {
995 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); 1017 main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context));
996 } 1018 }
997 1019
998 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( 1020 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve(
999 blink::WebGestureDevice device_source, 1021 blink::WebGestureDevice device_source,
1000 const blink::WebFloatPoint& velocity, 1022 const blink::WebFloatPoint& velocity,
1001 const blink::WebSize& cumulative_scroll) { 1023 const blink::WebSize& cumulative_scroll) {
1002 auto curve = WebGestureCurveImpl::CreateFromDefaultPlatformCurve( 1024 auto curve = WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
1003 gfx::Vector2dF(velocity.x, velocity.y), 1025 gfx::Vector2dF(velocity.x, velocity.y),
1004 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height)); 1026 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height));
1005 return curve.release(); 1027 return curve.release();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 } 1236 }
1215 1237
1216 // static 1238 // static
1217 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { 1239 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) {
1218 WebThreadImplForMessageLoop* impl = 1240 WebThreadImplForMessageLoop* impl =
1219 static_cast<WebThreadImplForMessageLoop*>(thread); 1241 static_cast<WebThreadImplForMessageLoop*>(thread);
1220 delete impl; 1242 delete impl;
1221 } 1243 }
1222 1244
1223 } // namespace content 1245 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698