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/allocator/allocator_extension.h" | 11 #include "base/allocator/allocator_extension.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.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/message_loop/message_loop.h" | |
17 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
18 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
19 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
20 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
21 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
23 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
24 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
25 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
26 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 break; | 409 break; |
411 } | 410 } |
412 return -1; | 411 return -1; |
413 } | 412 } |
414 | 413 |
415 BlinkPlatformImpl::BlinkPlatformImpl() | 414 BlinkPlatformImpl::BlinkPlatformImpl() |
416 : main_thread_task_runner_(base::MessageLoopProxy::current()), | 415 : main_thread_task_runner_(base::MessageLoopProxy::current()), |
417 shared_timer_func_(NULL), | 416 shared_timer_func_(NULL), |
418 shared_timer_fire_time_(0.0), | 417 shared_timer_fire_time_(0.0), |
419 shared_timer_fire_time_was_set_while_suspended_(false), | 418 shared_timer_fire_time_was_set_while_suspended_(false), |
420 shared_timer_suspended_(0), | 419 shared_timer_suspended_(0) { |
421 current_thread_slot_(&DestroyCurrentThread) { | |
422 InternalInit(); | 420 InternalInit(); |
423 } | 421 } |
424 | 422 |
425 BlinkPlatformImpl::BlinkPlatformImpl( | 423 BlinkPlatformImpl::BlinkPlatformImpl( |
426 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 424 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
427 : main_thread_task_runner_(main_thread_task_runner), | 425 : main_thread_task_runner_(main_thread_task_runner), |
428 shared_timer_func_(NULL), | 426 shared_timer_func_(NULL), |
429 shared_timer_fire_time_(0.0), | 427 shared_timer_fire_time_(0.0), |
430 shared_timer_fire_time_was_set_while_suspended_(false), | 428 shared_timer_fire_time_was_set_while_suspended_(false), |
431 shared_timer_suspended_(0), | 429 shared_timer_suspended_(0) { |
432 current_thread_slot_(&DestroyCurrentThread) { | |
433 // TODO(alexclarke): Use c++11 delegated constructors when allowed. | 430 // TODO(alexclarke): Use c++11 delegated constructors when allowed. |
434 InternalInit(); | 431 InternalInit(); |
435 } | 432 } |
436 | 433 |
437 void BlinkPlatformImpl::InternalInit() { | 434 void BlinkPlatformImpl::InternalInit() { |
438 // ChildThread may not exist in some tests. | 435 // ChildThread may not exist in some tests. |
439 if (ChildThreadImpl::current()) { | 436 if (ChildThreadImpl::current()) { |
440 geofencing_provider_.reset(new WebGeofencingProviderImpl( | 437 geofencing_provider_.reset(new WebGeofencingProviderImpl( |
441 ChildThreadImpl::current()->thread_safe_sender())); | 438 ChildThreadImpl::current()->thread_safe_sender())); |
442 bluetooth_.reset( | 439 bluetooth_.reset( |
443 new WebBluetoothImpl(ChildThreadImpl::current()->thread_safe_sender())); | 440 new WebBluetoothImpl(ChildThreadImpl::current()->thread_safe_sender())); |
444 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); | 441 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); |
445 notification_dispatcher_ = | 442 notification_dispatcher_ = |
446 ChildThreadImpl::current()->notification_dispatcher(); | 443 ChildThreadImpl::current()->notification_dispatcher(); |
447 push_dispatcher_ = ChildThreadImpl::current()->push_dispatcher(); | 444 push_dispatcher_ = ChildThreadImpl::current()->push_dispatcher(); |
448 } | 445 } |
449 | 446 |
450 if (main_thread_task_runner_.get()) { | 447 if (main_thread_task_runner_.get()) { |
451 shared_timer_.SetTaskRunner(main_thread_task_runner_); | 448 shared_timer_.SetTaskRunner(main_thread_task_runner_); |
452 } | 449 } |
453 } | 450 } |
454 | 451 |
| 452 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { |
| 453 DCHECK(!current_thread_slot_.Get()); |
| 454 current_thread_slot_.Set(thread); |
| 455 } |
| 456 |
455 BlinkPlatformImpl::~BlinkPlatformImpl() { | 457 BlinkPlatformImpl::~BlinkPlatformImpl() { |
456 } | 458 } |
457 | 459 |
458 WebURLLoader* BlinkPlatformImpl::createURLLoader() { | 460 WebURLLoader* BlinkPlatformImpl::createURLLoader() { |
459 ChildThreadImpl* child_thread = ChildThreadImpl::current(); | 461 ChildThreadImpl* child_thread = ChildThreadImpl::current(); |
460 // There may be no child thread in RenderViewTests. These tests can still use | 462 // There may be no child thread in RenderViewTests. These tests can still use |
461 // data URLs to bypass the ResourceDispatcher. | 463 // data URLs to bypass the ResourceDispatcher. |
462 return new WebURLLoaderImpl( | 464 return new WebURLLoaderImpl( |
463 child_thread ? child_thread->resource_dispatcher() : NULL, | 465 child_thread ? child_thread->resource_dispatcher() : NULL, |
464 MainTaskRunnerForCurrentThread()); | 466 MainTaskRunnerForCurrentThread()); |
(...skipping 27 matching lines...) Expand all Loading... |
492 | 494 |
493 bool BlinkPlatformImpl::isReservedIPAddress( | 495 bool BlinkPlatformImpl::isReservedIPAddress( |
494 const blink::WebString& host) const { | 496 const blink::WebString& host) const { |
495 net::IPAddressNumber address; | 497 net::IPAddressNumber address; |
496 if (!net::ParseURLHostnameToNumber(host.utf8(), &address)) | 498 if (!net::ParseURLHostnameToNumber(host.utf8(), &address)) |
497 return false; | 499 return false; |
498 return net::IsIPAddressReserved(address); | 500 return net::IsIPAddressReserved(address); |
499 } | 501 } |
500 | 502 |
501 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { | 503 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { |
502 return new WebThreadImpl(name); | 504 WebThreadImpl* thread = new WebThreadImpl(name); |
| 505 thread->TaskRunner()->PostTask( |
| 506 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS, |
| 507 base::Unretained(this), thread)); |
| 508 return thread; |
503 } | 509 } |
504 | 510 |
505 blink::WebThread* BlinkPlatformImpl::currentThread() { | 511 blink::WebThread* BlinkPlatformImpl::currentThread() { |
506 WebThreadImplForMessageLoop* thread = | 512 return static_cast<blink::WebThread*>(current_thread_slot_.Get()); |
507 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); | |
508 if (thread) | |
509 return (thread); | |
510 | |
511 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
512 MainTaskRunnerForCurrentThread(); | |
513 if (!task_runner.get()) | |
514 return NULL; | |
515 | |
516 thread = new WebThreadImplForMessageLoop(task_runner); | |
517 current_thread_slot_.Set(thread); | |
518 return thread; | |
519 } | 513 } |
520 | 514 |
521 void BlinkPlatformImpl::yieldCurrentThread() { | 515 void BlinkPlatformImpl::yieldCurrentThread() { |
522 base::PlatformThread::YieldCurrentThread(); | 516 base::PlatformThread::YieldCurrentThread(); |
523 } | 517 } |
524 | 518 |
525 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { | 519 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { |
526 return new WebWaitableEventImpl(); | 520 return new WebWaitableEventImpl(); |
527 } | 521 } |
528 | 522 |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 scoped_refptr<base::SingleThreadTaskRunner> | 1231 scoped_refptr<base::SingleThreadTaskRunner> |
1238 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() { | 1232 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() { |
1239 if (main_thread_task_runner_.get() && | 1233 if (main_thread_task_runner_.get() && |
1240 main_thread_task_runner_->BelongsToCurrentThread()) { | 1234 main_thread_task_runner_->BelongsToCurrentThread()) { |
1241 return main_thread_task_runner_; | 1235 return main_thread_task_runner_; |
1242 } else { | 1236 } else { |
1243 return base::MessageLoopProxy::current(); | 1237 return base::MessageLoopProxy::current(); |
1244 } | 1238 } |
1245 } | 1239 } |
1246 | 1240 |
1247 // static | |
1248 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { | |
1249 WebThreadImplForMessageLoop* impl = | |
1250 static_cast<WebThreadImplForMessageLoop*>(thread); | |
1251 delete impl; | |
1252 } | |
1253 | |
1254 WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) { | 1241 WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) { |
1255 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString( | 1242 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString( |
1256 static_cast<ui::DomCode>(dom_code))); | 1243 static_cast<ui::DomCode>(dom_code))); |
1257 } | 1244 } |
1258 | 1245 |
1259 int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) { | 1246 int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) { |
1260 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode( | 1247 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode( |
1261 code.utf8().data())); | 1248 code.utf8().data())); |
1262 } | 1249 } |
1263 | 1250 |
1264 } // namespace content | 1251 } // namespace content |
OLD | NEW |