| 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 |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. | 405 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. |
| 406 // After a planned WebKit patch is landed, we need to add a case statement | 406 // After a planned WebKit patch is landed, we need to add a case statement |
| 407 // for the added symbol here. | 407 // for the added symbol here. |
| 408 default: | 408 default: |
| 409 break; | 409 break; |
| 410 } | 410 } |
| 411 return -1; | 411 return -1; |
| 412 } | 412 } |
| 413 | 413 |
| 414 BlinkPlatformImpl::BlinkPlatformImpl() | 414 BlinkPlatformImpl::BlinkPlatformImpl() |
| 415 : main_thread_task_runner_(base::MessageLoopProxy::current()), | 415 : main_thread_task_runner_(base::MessageLoopProxy::current()) { |
| 416 shared_timer_func_(NULL), | |
| 417 shared_timer_fire_time_(0.0), | |
| 418 shared_timer_fire_time_was_set_while_suspended_(false), | |
| 419 shared_timer_suspended_(0) { | |
| 420 InternalInit(); | 416 InternalInit(); |
| 421 } | 417 } |
| 422 | 418 |
| 423 BlinkPlatformImpl::BlinkPlatformImpl( | 419 BlinkPlatformImpl::BlinkPlatformImpl( |
| 424 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 420 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
| 425 : main_thread_task_runner_(main_thread_task_runner), | 421 : main_thread_task_runner_(main_thread_task_runner) { |
| 426 shared_timer_func_(NULL), | |
| 427 shared_timer_fire_time_(0.0), | |
| 428 shared_timer_fire_time_was_set_while_suspended_(false), | |
| 429 shared_timer_suspended_(0) { | |
| 430 // TODO(alexclarke): Use c++11 delegated constructors when allowed. | 422 // TODO(alexclarke): Use c++11 delegated constructors when allowed. |
| 431 InternalInit(); | 423 InternalInit(); |
| 432 } | 424 } |
| 433 | 425 |
| 434 void BlinkPlatformImpl::InternalInit() { | 426 void BlinkPlatformImpl::InternalInit() { |
| 435 // ChildThread may not exist in some tests. | 427 // ChildThread may not exist in some tests. |
| 436 if (ChildThreadImpl::current()) { | 428 if (ChildThreadImpl::current()) { |
| 437 geofencing_provider_.reset(new WebGeofencingProviderImpl( | 429 geofencing_provider_.reset(new WebGeofencingProviderImpl( |
| 438 ChildThreadImpl::current()->thread_safe_sender())); | 430 ChildThreadImpl::current()->thread_safe_sender())); |
| 439 bluetooth_.reset( | 431 bluetooth_.reset( |
| 440 new WebBluetoothImpl(ChildThreadImpl::current()->thread_safe_sender())); | 432 new WebBluetoothImpl(ChildThreadImpl::current()->thread_safe_sender())); |
| 441 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); | 433 thread_safe_sender_ = ChildThreadImpl::current()->thread_safe_sender(); |
| 442 notification_dispatcher_ = | 434 notification_dispatcher_ = |
| 443 ChildThreadImpl::current()->notification_dispatcher(); | 435 ChildThreadImpl::current()->notification_dispatcher(); |
| 444 push_dispatcher_ = ChildThreadImpl::current()->push_dispatcher(); | 436 push_dispatcher_ = ChildThreadImpl::current()->push_dispatcher(); |
| 445 } | 437 } |
| 446 | |
| 447 if (main_thread_task_runner_.get()) { | |
| 448 shared_timer_.SetTaskRunner(main_thread_task_runner_); | |
| 449 } | |
| 450 } | 438 } |
| 451 | 439 |
| 452 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { | 440 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { |
| 453 DCHECK(!current_thread_slot_.Get()); | 441 DCHECK(!current_thread_slot_.Get()); |
| 454 current_thread_slot_.Set(thread); | 442 current_thread_slot_.Set(thread); |
| 455 } | 443 } |
| 456 | 444 |
| 457 BlinkPlatformImpl::~BlinkPlatformImpl() { | 445 BlinkPlatformImpl::~BlinkPlatformImpl() { |
| 458 } | 446 } |
| 459 | 447 |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 double BlinkPlatformImpl::monotonicallyIncreasingTime() { | 956 double BlinkPlatformImpl::monotonicallyIncreasingTime() { |
| 969 return base::TimeTicks::Now().ToInternalValue() / | 957 return base::TimeTicks::Now().ToInternalValue() / |
| 970 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 958 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 971 } | 959 } |
| 972 | 960 |
| 973 void BlinkPlatformImpl::cryptographicallyRandomValues( | 961 void BlinkPlatformImpl::cryptographicallyRandomValues( |
| 974 unsigned char* buffer, size_t length) { | 962 unsigned char* buffer, size_t length) { |
| 975 base::RandBytes(buffer, length); | 963 base::RandBytes(buffer, length); |
| 976 } | 964 } |
| 977 | 965 |
| 978 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func)()) { | |
| 979 shared_timer_func_ = func; | |
| 980 } | |
| 981 | |
| 982 void BlinkPlatformImpl::setSharedTimerFireInterval( | |
| 983 double interval_seconds) { | |
| 984 shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime(); | |
| 985 if (shared_timer_suspended_) { | |
| 986 shared_timer_fire_time_was_set_while_suspended_ = true; | |
| 987 return; | |
| 988 } | |
| 989 | |
| 990 // By converting between double and int64 representation, we run the risk | |
| 991 // of losing precision due to rounding errors. Performing computations in | |
| 992 // microseconds reduces this risk somewhat. But there still is the potential | |
| 993 // of us computing a fire time for the timer that is shorter than what we | |
| 994 // need. | |
| 995 // As the event loop will check event deadlines prior to actually firing | |
| 996 // them, there is a risk of needlessly rescheduling events and of | |
| 997 // needlessly looping if sleep times are too short even by small amounts. | |
| 998 // This results in measurable performance degradation unless we use ceil() to | |
| 999 // always round up the sleep times. | |
| 1000 int64 interval = static_cast<int64>( | |
| 1001 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) | |
| 1002 * base::Time::kMicrosecondsPerMillisecond); | |
| 1003 | |
| 1004 if (interval < 0) | |
| 1005 interval = 0; | |
| 1006 | |
| 1007 shared_timer_.Stop(); | |
| 1008 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), | |
| 1009 this, &BlinkPlatformImpl::DoTimeout); | |
| 1010 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); | |
| 1011 } | |
| 1012 | |
| 1013 void BlinkPlatformImpl::stopSharedTimer() { | |
| 1014 shared_timer_.Stop(); | |
| 1015 } | |
| 1016 | |
| 1017 void BlinkPlatformImpl::callOnMainThread( | 966 void BlinkPlatformImpl::callOnMainThread( |
| 1018 void (*func)(void*), void* context) { | 967 void (*func)(void*), void* context) { |
| 1019 main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context)); | 968 main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context)); |
| 1020 } | 969 } |
| 1021 | 970 |
| 1022 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( | 971 blink::WebGestureCurve* BlinkPlatformImpl::createFlingAnimationCurve( |
| 1023 blink::WebGestureDevice device_source, | 972 blink::WebGestureDevice device_source, |
| 1024 const blink::WebFloatPoint& velocity, | 973 const blink::WebFloatPoint& velocity, |
| 1025 const blink::WebSize& cumulative_scroll) { | 974 const blink::WebSize& cumulative_scroll) { |
| 1026 bool is_main_thread = | 975 bool is_main_thread = |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 // be reserved for direct use by certain hardware. Thus, we set the limit so | 1153 // be reserved for direct use by certain hardware. Thus, we set the limit so |
| 1205 // that 1.6GB of reported physical memory on a 2GB device is enough to set the | 1154 // that 1.6GB of reported physical memory on a 2GB device is enough to set the |
| 1206 // limit at 16M pixels, which is a desirable value since 4K*4K is a relatively | 1155 // limit at 16M pixels, which is a desirable value since 4K*4K is a relatively |
| 1207 // common texture size. | 1156 // common texture size. |
| 1208 return base::SysInfo::AmountOfPhysicalMemory() / 25; | 1157 return base::SysInfo::AmountOfPhysicalMemory() / 25; |
| 1209 #else | 1158 #else |
| 1210 return noDecodedImageByteLimit; | 1159 return noDecodedImageByteLimit; |
| 1211 #endif | 1160 #endif |
| 1212 } | 1161 } |
| 1213 | 1162 |
| 1214 void BlinkPlatformImpl::SuspendSharedTimer() { | |
| 1215 ++shared_timer_suspended_; | |
| 1216 } | |
| 1217 | |
| 1218 void BlinkPlatformImpl::ResumeSharedTimer() { | |
| 1219 DCHECK_GT(shared_timer_suspended_, 0); | |
| 1220 | |
| 1221 // The shared timer may have fired or been adjusted while we were suspended. | |
| 1222 if (--shared_timer_suspended_ == 0 && | |
| 1223 (!shared_timer_.IsRunning() || | |
| 1224 shared_timer_fire_time_was_set_while_suspended_)) { | |
| 1225 shared_timer_fire_time_was_set_while_suspended_ = false; | |
| 1226 setSharedTimerFireInterval( | |
| 1227 shared_timer_fire_time_ - monotonicallyIncreasingTime()); | |
| 1228 } | |
| 1229 } | |
| 1230 | |
| 1231 scoped_refptr<base::SingleThreadTaskRunner> | 1163 scoped_refptr<base::SingleThreadTaskRunner> |
| 1232 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() { | 1164 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() { |
| 1233 if (main_thread_task_runner_.get() && | 1165 if (main_thread_task_runner_.get() && |
| 1234 main_thread_task_runner_->BelongsToCurrentThread()) { | 1166 main_thread_task_runner_->BelongsToCurrentThread()) { |
| 1235 return main_thread_task_runner_; | 1167 return main_thread_task_runner_; |
| 1236 } else { | 1168 } else { |
| 1237 return base::MessageLoopProxy::current(); | 1169 return base::MessageLoopProxy::current(); |
| 1238 } | 1170 } |
| 1239 } | 1171 } |
| 1240 | 1172 |
| 1241 WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) { | 1173 WebString BlinkPlatformImpl::domCodeStringFromEnum(int dom_code) { |
| 1242 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString( | 1174 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString( |
| 1243 static_cast<ui::DomCode>(dom_code))); | 1175 static_cast<ui::DomCode>(dom_code))); |
| 1244 } | 1176 } |
| 1245 | 1177 |
| 1246 int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) { | 1178 int BlinkPlatformImpl::domEnumFromCodeString(const WebString& code) { |
| 1247 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode( | 1179 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode( |
| 1248 code.utf8().data())); | 1180 code.utf8().data())); |
| 1249 } | 1181 } |
| 1250 | 1182 |
| 1251 } // namespace content | 1183 } // namespace content |
| OLD | NEW |