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

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

Issue 1449953002: compositor-worker: Refactor CompositorWorkerManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add documentation and ASSERTS for some subtleties. Created 5 years 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
« no previous file with comments | « content/child/blink_platform_impl.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // TODO(skyostil): Ensure that we always have an active task runner when 452 // TODO(skyostil): Ensure that we always have an active task runner when
452 // constructing the platform. 453 // constructing the platform.
453 BlinkPlatformImpl::BlinkPlatformImpl() 454 BlinkPlatformImpl::BlinkPlatformImpl()
454 : BlinkPlatformImpl(base::ThreadTaskRunnerHandle::IsSet() 455 : BlinkPlatformImpl(base::ThreadTaskRunnerHandle::IsSet()
455 ? base::ThreadTaskRunnerHandle::Get() 456 ? base::ThreadTaskRunnerHandle::Get()
456 : nullptr) { 457 : nullptr) {
457 } 458 }
458 459
459 BlinkPlatformImpl::BlinkPlatformImpl( 460 BlinkPlatformImpl::BlinkPlatformImpl(
460 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) 461 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
461 : main_thread_task_runner_(main_thread_task_runner) { 462 : main_thread_task_runner_(main_thread_task_runner),
463 compositor_thread_(nullptr) {
462 InternalInit(); 464 InternalInit();
463 } 465 }
464 466
465 void BlinkPlatformImpl::InternalInit() { 467 void BlinkPlatformImpl::InternalInit() {
466 // ChildThread may not exist in some tests. 468 // ChildThread may not exist in some tests.
467 if (ChildThreadImpl::current()) { 469 if (ChildThreadImpl::current()) {
468 geofencing_provider_.reset(new WebGeofencingProviderImpl( 470 geofencing_provider_.reset(new WebGeofencingProviderImpl(
469 ChildThreadImpl::current()->thread_safe_sender())); 471 ChildThreadImpl::current()->thread_safe_sender()));
470 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); 472 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender();
471 notification_dispatcher_ = 473 notification_dispatcher_ =
472 ChildThreadImpl::current()->notification_dispatcher(); 474 ChildThreadImpl::current()->notification_dispatcher();
473 push_dispatcher_ = ChildThreadImpl::current()->push_dispatcher(); 475 push_dispatcher_ = ChildThreadImpl::current()->push_dispatcher();
474 permission_client_.reset(new PermissionDispatcher( 476 permission_client_.reset(new PermissionDispatcher(
475 ChildThreadImpl::current()->service_registry())); 477 ChildThreadImpl::current()->service_registry()));
476 main_thread_sync_provider_.reset( 478 main_thread_sync_provider_.reset(
477 new BackgroundSyncProvider(main_thread_task_runner_.get())); 479 new BackgroundSyncProvider(main_thread_task_runner_.get()));
478 } 480 }
479 } 481 }
480 482
481 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { 483 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread,
484 base::WaitableEvent* event) {
482 DCHECK(!current_thread_slot_.Get()); 485 DCHECK(!current_thread_slot_.Get());
483 current_thread_slot_.Set(thread); 486 current_thread_slot_.Set(thread);
487 event->Signal();
484 } 488 }
485 489
486 BlinkPlatformImpl::~BlinkPlatformImpl() { 490 BlinkPlatformImpl::~BlinkPlatformImpl() {
487 } 491 }
488 492
489 WebURLLoader* BlinkPlatformImpl::createURLLoader() { 493 WebURLLoader* BlinkPlatformImpl::createURLLoader() {
490 ChildThreadImpl* child_thread = ChildThreadImpl::current(); 494 ChildThreadImpl* child_thread = ChildThreadImpl::current();
491 // There may be no child thread in RenderViewTests. These tests can still use 495 // There may be no child thread in RenderViewTests. These tests can still use
492 // data URLs to bypass the ResourceDispatcher. 496 // data URLs to bypass the ResourceDispatcher.
493 return new WebURLLoaderImpl( 497 return new WebURLLoaderImpl(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 bool BlinkPlatformImpl::portAllowed(const blink::WebURL& url) const { 542 bool BlinkPlatformImpl::portAllowed(const blink::WebURL& url) const {
539 GURL gurl = GURL(url); 543 GURL gurl = GURL(url);
540 // Return true for URLs without a port specified. This is needed to let 544 // Return true for URLs without a port specified. This is needed to let
541 // through non-network schemes that don't go over the network. 545 // through non-network schemes that don't go over the network.
542 if (!gurl.has_port()) 546 if (!gurl.has_port())
543 return true; 547 return true;
544 return net::IsPortAllowedForScheme(gurl.EffectiveIntPort(), gurl.scheme()); 548 return net::IsPortAllowedForScheme(gurl.EffectiveIntPort(), gurl.scheme());
545 } 549 }
546 550
547 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { 551 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) {
548 scheduler::WebThreadImplForWorkerScheduler* thread = 552 return createThreadWithOptions(name, base::Thread::Options()).release();
549 new scheduler::WebThreadImplForWorkerScheduler(name); 553 }
554
555 scoped_ptr<scheduler::WebThreadBase> BlinkPlatformImpl::createThreadWithOptions(
556 const char* name,
557 base::Thread::Options options) {
558 scoped_ptr<scheduler::WebThreadBase> thread(
559 new scheduler::WebThreadImplForWorkerScheduler(name, options));
560 base::WaitableEvent event(false, false);
550 thread->TaskRunner()->PostTask( 561 thread->TaskRunner()->PostTask(
551 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, 562 FROM_HERE,
552 base::Unretained(this), thread)); 563 base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, base::Unretained(this),
564 base::Unretained(thread.get()), base::Unretained(&event)));
565 event.Wait();
553 return thread; 566 return thread;
554 } 567 }
555 568
556 blink::WebThread* BlinkPlatformImpl::currentThread() { 569 blink::WebThread* BlinkPlatformImpl::currentThread() {
557 return static_cast<blink::WebThread*>(current_thread_slot_.Get()); 570 return static_cast<blink::WebThread*>(current_thread_slot_.Get());
558 } 571 }
559 572
560 void BlinkPlatformImpl::yieldCurrentThread() { 573 void BlinkPlatformImpl::yieldCurrentThread() {
561 base::PlatformThread::YieldCurrentThread(); 574 base::PlatformThread::YieldCurrentThread();
562 } 575 }
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 1125
1113 double BlinkPlatformImpl::systemTraceTime() { 1126 double BlinkPlatformImpl::systemTraceTime() {
1114 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 1127 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1115 } 1128 }
1116 1129
1117 void BlinkPlatformImpl::cryptographicallyRandomValues( 1130 void BlinkPlatformImpl::cryptographicallyRandomValues(
1118 unsigned char* buffer, size_t length) { 1131 unsigned char* buffer, size_t length) {
1119 base::RandBytes(buffer, length); 1132 base::RandBytes(buffer, length);
1120 } 1133 }
1121 1134
1135 blink::WebThread* BlinkPlatformImpl::compositorThread() const {
1136 return compositor_thread_;
1137 }
1138
1122 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( 1139 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve(
1123 blink::WebGestureDevice device_source, 1140 blink::WebGestureDevice device_source,
1124 const blink::WebFloatPoint& velocity, 1141 const blink::WebFloatPoint& velocity,
1125 const blink::WebSize& cumulative_scroll) { 1142 const blink::WebSize& cumulative_scroll) {
1126 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve( 1143 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
1127 gfx::Vector2dF(velocity.x, velocity.y), 1144 gfx::Vector2dF(velocity.x, velocity.y),
1128 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height), 1145 gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height),
1129 IsMainThread()).release(); 1146 IsMainThread()).release();
1130 } 1147 }
1131 1148
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString( 1345 return WebString::fromUTF8(ui::KeycodeConverter::DomKeyToKeyString(
1329 static_cast<ui::DomKey>(dom_key))); 1346 static_cast<ui::DomKey>(dom_key)));
1330 } 1347 }
1331 1348
1332 int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key_string) { 1349 int BlinkPlatformImpl::domKeyEnumFromString(const WebString& key_string) {
1333 return static_cast<int>( 1350 return static_cast<int>(
1334 ui::KeycodeConverter::KeyStringToDomKey(key_string.utf8())); 1351 ui::KeycodeConverter::KeyStringToDomKey(key_string.utf8()));
1335 } 1352 }
1336 1353
1337 } // namespace content 1354 } // namespace content
OLDNEW
« no previous file with comments | « content/child/blink_platform_impl.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698