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

Side by Side Diff: webkit/glue/webkitclient_impl.cc

Issue 196053: When converting between units of time or data types of different precision,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include <math.h>
5 #include "config.h" 6 #include "config.h"
6 7
7 #include "FrameView.h" 8 #include "FrameView.h"
8 #include "ScrollView.h" 9 #include "ScrollView.h"
9 #include <wtf/Assertions.h> 10 #include <wtf/Assertions.h>
10 #undef LOG 11 #undef LOG
11 12
12 #include "webkit/glue/webkitclient_impl.h" 13 #include "webkit/glue/webkitclient_impl.h"
13 14
14 #include "base/file_path.h" 15 #include "base/file_path.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 259
259 double WebKitClientImpl::currentTime() { 260 double WebKitClientImpl::currentTime() {
260 return base::Time::Now().ToDoubleT(); 261 return base::Time::Now().ToDoubleT();
261 } 262 }
262 263
263 void WebKitClientImpl::setSharedTimerFiredFunction(void (*func)()) { 264 void WebKitClientImpl::setSharedTimerFiredFunction(void (*func)()) {
264 shared_timer_func_ = func; 265 shared_timer_func_ = func;
265 } 266 }
266 267
267 void WebKitClientImpl::setSharedTimerFireTime(double fire_time) { 268 void WebKitClientImpl::setSharedTimerFireTime(double fire_time) {
268 int interval = static_cast<int>((fire_time - currentTime()) * 1000); 269 // By converting between double and int64 representation, we run the risk
270 // of losing precision due to rounding errors. Performing computations in
271 // microseconds reduces this risk somewhat. But there still is the potential
272 // of us computing a fire time for the timer that is shorter than what we
273 // need.
274 // As the event loop will check event deadlines prior to actually firing
275 // them, there is a risk of needlessly rescheduling events and of
276 // needlessly looping if sleep times are too short even by small amounts.
277 // This results in measurable performance degradation unless we use ceil() to
278 // always round up the sleep times.
279 int64 interval = static_cast<int64>(
280 ceil((fire_time - currentTime()) * base::Time::kMicrosecondsPerSecond));
269 if (interval < 0) 281 if (interval < 0)
270 interval = 0; 282 interval = 0;
271 283
272 shared_timer_.Stop(); 284 shared_timer_.Stop();
273 shared_timer_.Start(base::TimeDelta::FromMilliseconds(interval), this, 285 shared_timer_.Start(base::TimeDelta::FromMicroseconds(interval), this,
274 &WebKitClientImpl::DoTimeout); 286 &WebKitClientImpl::DoTimeout);
275 } 287 }
276 288
277 void WebKitClientImpl::stopSharedTimer() { 289 void WebKitClientImpl::stopSharedTimer() {
278 shared_timer_.Stop(); 290 shared_timer_.Stop();
279 } 291 }
280 292
281 void WebKitClientImpl::callOnMainThread(void (*func)()) { 293 void WebKitClientImpl::callOnMainThread(void (*func)()) {
282 main_loop_->PostTask(FROM_HERE, NewRunnableFunction(func)); 294 main_loop_->PostTask(FROM_HERE, NewRunnableFunction(func));
283 } 295 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 ChromeClientImpl* chrome_client = ToChromeClient(widget); 468 ChromeClientImpl* chrome_client = ToChromeClient(widget);
457 if (chrome_client) 469 if (chrome_client)
458 chrome_client->focus(); 470 chrome_client->focus();
459 } 471 }
460 472
461 WebCore::WorkerContextProxy* WebKitClientImpl::createWorkerContextProxy( 473 WebCore::WorkerContextProxy* WebKitClientImpl::createWorkerContextProxy(
462 WebCore::Worker* worker) { 474 WebCore::Worker* worker) {
463 return WebWorkerClientImpl::createWorkerContextProxy(worker); 475 return WebWorkerClientImpl::createWorkerContextProxy(worker);
464 } 476 }
465 } // namespace webkit_glue 477 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698