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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
| 18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
| 24 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 26 #include "base/thread_task_runner_handle.h" | 26 #include "base/thread_task_runner_handle.h" |
| 27 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
| 28 #include "base/threading/thread.h" | |
| 28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 29 #include "base/trace_event/memory_allocator_dump_guid.h" | 30 #include "base/trace_event/memory_allocator_dump_guid.h" |
| 30 #include "base/trace_event/memory_dump_manager.h" | 31 #include "base/trace_event/memory_dump_manager.h" |
| 31 #include "base/trace_event/trace_event.h" | 32 #include "base/trace_event/trace_event.h" |
| 32 #include "blink/public/resources/grit/blink_image_resources.h" | 33 #include "blink/public/resources/grit/blink_image_resources.h" |
| 33 #include "blink/public/resources/grit/blink_resources.h" | 34 #include "blink/public/resources/grit/blink_resources.h" |
| 34 #include "components/mime_util/mime_util.h" | 35 #include "components/mime_util/mime_util.h" |
| 35 #include "components/scheduler/child/web_task_runner_impl.h" | 36 #include "components/scheduler/child/web_task_runner_impl.h" |
| 36 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" | 37 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h" |
| 37 #include "content/app/resources/grit/content_resources.h" | 38 #include "content/app/resources/grit/content_resources.h" |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 // TODO(skyostil): Ensure that we always have an active task runner when | 436 // TODO(skyostil): Ensure that we always have an active task runner when |
| 436 // constructing the platform. | 437 // constructing the platform. |
| 437 BlinkPlatformImpl::BlinkPlatformImpl() | 438 BlinkPlatformImpl::BlinkPlatformImpl() |
| 438 : BlinkPlatformImpl(base::ThreadTaskRunnerHandle::IsSet() | 439 : BlinkPlatformImpl(base::ThreadTaskRunnerHandle::IsSet() |
| 439 ? base::ThreadTaskRunnerHandle::Get() | 440 ? base::ThreadTaskRunnerHandle::Get() |
| 440 : nullptr) { | 441 : nullptr) { |
| 441 } | 442 } |
| 442 | 443 |
| 443 BlinkPlatformImpl::BlinkPlatformImpl( | 444 BlinkPlatformImpl::BlinkPlatformImpl( |
| 444 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 445 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
| 445 : main_thread_task_runner_(main_thread_task_runner) { | 446 : main_thread_task_runner_(main_thread_task_runner), |
| 447 compositor_thread_(nullptr) { | |
| 446 InternalInit(); | 448 InternalInit(); |
| 447 } | 449 } |
| 448 | 450 |
| 449 void BlinkPlatformImpl::InternalInit() { | 451 void BlinkPlatformImpl::InternalInit() { |
| 450 // ChildThread may not exist in some tests. | 452 // ChildThread may not exist in some tests. |
| 451 if (ChildThreadImpl::current()) { | 453 if (ChildThreadImpl::current()) { |
| 452 geofencing_provider_.reset(new WebGeofencingProviderImpl( | 454 geofencing_provider_.reset(new WebGeofencingProviderImpl( |
| 453 ChildThreadImpl::current()->thread_safe_sender())); | 455 ChildThreadImpl::current()->thread_safe_sender())); |
| 454 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); | 456 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); |
| 455 notification_dispatcher_ = | 457 notification_dispatcher_ = |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 bool BlinkPlatformImpl::portAllowed(const blink::WebURL& url) const { | 524 bool BlinkPlatformImpl::portAllowed(const blink::WebURL& url) const { |
| 523 GURL gurl = GURL(url); | 525 GURL gurl = GURL(url); |
| 524 // Return true for URLs without a port specified. This is needed to let | 526 // Return true for URLs without a port specified. This is needed to let |
| 525 // through non-network schemes that don't go over the network. | 527 // through non-network schemes that don't go over the network. |
| 526 if (!gurl.has_port()) | 528 if (!gurl.has_port()) |
| 527 return true; | 529 return true; |
| 528 return net::IsPortAllowedForScheme(gurl.EffectiveIntPort(), gurl.scheme()); | 530 return net::IsPortAllowedForScheme(gurl.EffectiveIntPort(), gurl.scheme()); |
| 529 } | 531 } |
| 530 | 532 |
| 531 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { | 533 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { |
| 534 base::Thread::Options options; | |
| 532 scheduler::WebThreadImplForWorkerScheduler* thread = | 535 scheduler::WebThreadImplForWorkerScheduler* thread = |
| 533 new scheduler::WebThreadImplForWorkerScheduler(name); | 536 new scheduler::WebThreadImplForWorkerScheduler(name, options); |
| 534 thread->TaskRunner()->PostTask( | 537 thread->TaskRunner()->PostTask( |
| 535 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, | 538 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, |
| 536 base::Unretained(this), thread)); | 539 base::Unretained(this), thread)); |
| 537 return thread; | 540 return thread; |
| 538 } | 541 } |
| 539 | 542 |
| 543 blink::WebThread* BlinkPlatformImpl::createThreadForCompositor( | |
| 544 const char* name) { | |
| 545 base::Thread::Options options; | |
| 546 DCHECK(!compositor_thread_); | |
| 547 #if defined(OS_ANDROID) | |
| 548 options.priority = base::ThreadPriority::DISPLAY; | |
| 549 #endif | |
| 550 compositor_thread_ = | |
| 551 new scheduler::WebThreadImplForWorkerScheduler(name, options); | |
|
piman
2015/11/30 21:41:45
I think this makes ownership muddy and confusing.
Ian Vollick
2015/12/01 04:00:04
Agree that this is crummy, but I think there's som
piman
2015/12/01 04:24:10
Unretained(this) is still fine if BlinkPlatformImp
Ian Vollick
2015/12/01 05:01:08
I think I've got a plan, but before describing it
| |
| 552 compositor_thread_->TaskRunner()->PostTask( | |
| 553 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, | |
| 554 base::Unretained(this), compositor_thread_)); | |
| 555 return compositor_thread_; | |
| 556 } | |
| 557 | |
| 540 blink::WebThread* BlinkPlatformImpl::currentThread() { | 558 blink::WebThread* BlinkPlatformImpl::currentThread() { |
| 541 return static_cast<blink::WebThread*>(current_thread_slot_.Get()); | 559 return static_cast<blink::WebThread*>(current_thread_slot_.Get()); |
| 542 } | 560 } |
| 543 | 561 |
| 544 void BlinkPlatformImpl::yieldCurrentThread() { | 562 void BlinkPlatformImpl::yieldCurrentThread() { |
| 545 base::PlatformThread::YieldCurrentThread(); | 563 base::PlatformThread::YieldCurrentThread(); |
| 546 } | 564 } |
| 547 | 565 |
| 548 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent( | 566 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent( |
| 549 blink::WebWaitableEvent::ResetPolicy policy, | 567 blink::WebWaitableEvent::ResetPolicy policy, |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 | 1100 |
| 1083 double BlinkPlatformImpl::systemTraceTime() { | 1101 double BlinkPlatformImpl::systemTraceTime() { |
| 1084 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 1102 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 1085 } | 1103 } |
| 1086 | 1104 |
| 1087 void BlinkPlatformImpl::cryptographicallyRandomValues( | 1105 void BlinkPlatformImpl::cryptographicallyRandomValues( |
| 1088 unsigned char* buffer, size_t length) { | 1106 unsigned char* buffer, size_t length) { |
| 1089 base::RandBytes(buffer, length); | 1107 base::RandBytes(buffer, length); |
| 1090 } | 1108 } |
| 1091 | 1109 |
| 1110 blink::WebThread* BlinkPlatformImpl::compositorThread() const { | |
| 1111 return compositor_thread_; | |
| 1112 } | |
| 1113 | |
| 1092 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( | 1114 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( |
| 1093 blink::WebGestureDevice device_source, | 1115 blink::WebGestureDevice device_source, |
| 1094 const blink::WebFloatPoint& velocity, | 1116 const blink::WebFloatPoint& velocity, |
| 1095 const blink::WebSize& cumulative_scroll) { | 1117 const blink::WebSize& cumulative_scroll) { |
| 1096 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 1118 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
| 1097 gfx::Vector2dF(velocity.x, velocity.y), | 1119 gfx::Vector2dF(velocity.x, velocity.y), |
| 1098 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height), | 1120 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height), |
| 1099 IsMainThread()).release(); | 1121 IsMainThread()).release(); |
| 1100 } | 1122 } |
| 1101 | 1123 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1298 return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString( | 1320 return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString( |
| 1299 static_cast<ui::DomKey>(dom_key))); | 1321 static_cast<ui::DomKey>(dom_key))); |
| 1300 } | 1322 } |
| 1301 | 1323 |
| 1302 int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key_string) { | 1324 int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key_string) { |
| 1303 return static_cast<int>( | 1325 return static_cast<int>( |
| 1304 ui::KeycodeConverter::KeyStringToDomKey(key_string.utf8())); | 1326 ui::KeycodeConverter::KeyStringToDomKey(key_string.utf8())); |
| 1305 } | 1327 } |
| 1306 | 1328 |
| 1307 } // namespace content | 1329 } // namespace content |
| OLD | NEW |