| 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/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 17 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
| 18 #include "base/process/process_metrics.h" | 19 #include "base/process/process_metrics.h" |
| 19 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
| 24 #include "base/synchronization/waitable_event.h" | 26 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
| 26 #include "base/thread_task_runner_handle.h" | 28 #include "base/thread_task_runner_handle.h" |
| 27 #include "base/threading/platform_thread.h" | 29 #include "base/threading/platform_thread.h" |
| 28 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 29 #include "base/trace_event/memory_dump_manager.h" | 31 #include "base/trace_event/memory_dump_manager.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 // This "default:" line exists to avoid compile warnings about enum | 419 // This "default:" line exists to avoid compile warnings about enum |
| 418 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. | 420 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. |
| 419 // After a planned WebKit patch is landed, we need to add a case statement | 421 // After a planned WebKit patch is landed, we need to add a case statement |
| 420 // for the added symbol here. | 422 // for the added symbol here. |
| 421 default: | 423 default: |
| 422 break; | 424 break; |
| 423 } | 425 } |
| 424 return -1; | 426 return -1; |
| 425 } | 427 } |
| 426 | 428 |
| 429 // TODO(skyostil): Ensure that we always have an active task runner when |
| 430 // constructing the platform. |
| 427 BlinkPlatformImpl::BlinkPlatformImpl() | 431 BlinkPlatformImpl::BlinkPlatformImpl() |
| 428 : main_thread_task_runner_(base::MessageLoopProxy::current()), | 432 : main_thread_task_runner_(base::ThreadTaskRunnerHandle::IsSet() |
| 433 ? base::ThreadTaskRunnerHandle::Get() |
| 434 : nullptr), |
| 429 shared_timer_func_(NULL), | 435 shared_timer_func_(NULL), |
| 430 shared_timer_fire_time_(0.0), | 436 shared_timer_fire_time_(0.0), |
| 431 shared_timer_fire_time_was_set_while_suspended_(false), | 437 shared_timer_fire_time_was_set_while_suspended_(false), |
| 432 shared_timer_suspended_(0) { | 438 shared_timer_suspended_(0) { |
| 433 InternalInit(); | 439 InternalInit(); |
| 434 } | 440 } |
| 435 | 441 |
| 436 BlinkPlatformImpl::BlinkPlatformImpl( | 442 BlinkPlatformImpl::BlinkPlatformImpl( |
| 437 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 443 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
| 438 : main_thread_task_runner_(main_thread_task_runner), | 444 : main_thread_task_runner_(main_thread_task_runner), |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 shared_timer_fire_time_ - monotonicallyIncreasingTime()); | 1367 shared_timer_fire_time_ - monotonicallyIncreasingTime()); |
| 1362 } | 1368 } |
| 1363 } | 1369 } |
| 1364 | 1370 |
| 1365 scoped_refptr<base::SingleThreadTaskRunner> | 1371 scoped_refptr<base::SingleThreadTaskRunner> |
| 1366 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() { | 1372 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() { |
| 1367 if (main_thread_task_runner_.get() && | 1373 if (main_thread_task_runner_.get() && |
| 1368 main_thread_task_runner_->BelongsToCurrentThread()) { | 1374 main_thread_task_runner_->BelongsToCurrentThread()) { |
| 1369 return main_thread_task_runner_; | 1375 return main_thread_task_runner_; |
| 1370 } else { | 1376 } else { |
| 1371 return base::MessageLoopProxy::current(); | 1377 return base::ThreadTaskRunnerHandle::Get(); |
| 1372 } | 1378 } |
| 1373 } | 1379 } |
| 1374 | 1380 |
| 1375 bool BlinkPlatformImpl::IsMainThread() const { | 1381 bool BlinkPlatformImpl::IsMainThread() const { |
| 1376 return main_thread_task_runner_.get() && | 1382 return main_thread_task_runner_.get() && |
| 1377 main_thread_task_runner_->BelongsToCurrentThread(); | 1383 main_thread_task_runner_->BelongsToCurrentThread(); |
| 1378 } | 1384 } |
| 1379 | 1385 |
| 1380 WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) { | 1386 WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) { |
| 1381 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString( | 1387 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString( |
| 1382 static_cast<ui::DomCode>(dom_code))); | 1388 static_cast<ui::DomCode>(dom_code))); |
| 1383 } | 1389 } |
| 1384 | 1390 |
| 1385 int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) { | 1391 int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) { |
| 1386 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode( | 1392 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode( |
| 1387 code.utf8().data())); | 1393 code.utf8().data())); |
| 1388 } | 1394 } |
| 1389 | 1395 |
| 1390 } // namespace content | 1396 } // namespace content |
| OLD | NEW |