summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 16:35:38 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 16:35:38 +0000
commit66250024d3dd14e94fcefa327944806fe3468644 (patch)
tree4233aca407ec69e1c54532cd85f5d38bc3a8c9df /webkit
parent368ca47678e6c2208bd1849e5c8ad6f954ff0989 (diff)
downloadchromium_src-66250024d3dd14e94fcefa327944806fe3468644.zip
chromium_src-66250024d3dd14e94fcefa327944806fe3468644.tar.gz
chromium_src-66250024d3dd14e94fcefa327944806fe3468644.tar.bz2
Make PP_TimeTicks actually be a tick counter rather than be the same as the
wall clock time. TEST=none BUG=57448 Review URL: http://codereview.chromium.org/7237044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/event_conversion.cc15
-rw-r--r--webkit/plugins/ppapi/file_callbacks.cc7
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc11
-rw-r--r--webkit/plugins/ppapi/plugin_module.h1
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.cc15
-rw-r--r--webkit/plugins/ppapi/ppb_file_ref_impl.cc5
-rw-r--r--webkit/plugins/ppapi/ppb_flash_file_impl.cc13
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl.cc3
-rw-r--r--webkit/plugins/ppapi/time_conversion.cc51
-rw-r--r--webkit/plugins/ppapi/time_conversion.h29
-rw-r--r--webkit/plugins/ppapi/time_conversion_unittest.cc52
-rw-r--r--webkit/tools/test_shell/test_shell.gypi1
13 files changed, 171 insertions, 34 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index ae8319d..8b0272e 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -310,6 +310,8 @@
'../plugins/ppapi/resource_creation_impl.h',
'../plugins/ppapi/resource_tracker.cc',
'../plugins/ppapi/resource_tracker.h',
+ '../plugins/ppapi/time_conversion.cc',
+ '../plugins/ppapi/time_conversion.h',
'../plugins/ppapi/string.cc',
'../plugins/ppapi/string.h',
'../plugins/ppapi/var.cc',
diff --git a/webkit/plugins/ppapi/event_conversion.cc b/webkit/plugins/ppapi/event_conversion.cc
index 5a05fd1..c0588e3 100644
--- a/webkit/plugins/ppapi/event_conversion.cc
+++ b/webkit/plugins/ppapi/event_conversion.cc
@@ -15,6 +15,7 @@
#include "ppapi/shared_impl/input_event_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "webkit/plugins/ppapi/common.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
using ppapi::InputEventData;
using WebKit::WebInputEvent;
@@ -63,10 +64,7 @@ PP_InputEvent_Type ConvertEventTypes(WebInputEvent::Type wetype) {
InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) {
InputEventData result;
result.event_type = ConvertEventTypes(web_event.type);
- // TODO(brettw) http://code.google.com/p/chromium/issues/detail?id=57448
- // This should use a tick count rather than the wall clock time that WebKit
- // uses.
- result.event_time_stamp = web_event.timeStampSeconds;
+ result.event_time_stamp = EventTimeToPPTimeTicks(web_event.timeStampSeconds);
return result;
}
@@ -167,7 +165,7 @@ WebKeyboardEvent* BuildKeyEvent(const PP_InputEvent& event) {
default:
NOTREACHED();
}
- key_event->timeStampSeconds = event.time_stamp;
+ key_event->timeStampSeconds = PPTimeTicksToEventTime(event.time_stamp);
key_event->modifiers = event.u.key.modifier;
key_event->windowsKeyCode = event.u.key.key_code;
return key_event;
@@ -176,7 +174,7 @@ WebKeyboardEvent* BuildKeyEvent(const PP_InputEvent& event) {
WebKeyboardEvent* BuildCharEvent(const PP_InputEvent& event) {
WebKeyboardEvent* key_event = new WebKeyboardEvent();
key_event->type = WebInputEvent::Char;
- key_event->timeStampSeconds = event.time_stamp;
+ key_event->timeStampSeconds = PPTimeTicksToEventTime(event.time_stamp);
key_event->modifiers = event.u.character.modifier;
// Make sure to not read beyond the buffer in case some bad code doesn't
@@ -220,7 +218,7 @@ WebMouseEvent* BuildMouseEvent(const PP_InputEvent& event) {
default:
NOTREACHED();
}
- mouse_event->timeStampSeconds = event.time_stamp;
+ mouse_event->timeStampSeconds = PPTimeTicksToEventTime(event.time_stamp);
mouse_event->modifiers = event.u.mouse.modifier;
mouse_event->button =
static_cast<WebMouseEvent::Button>(event.u.mouse.button);
@@ -233,7 +231,8 @@ WebMouseEvent* BuildMouseEvent(const PP_InputEvent& event) {
WebMouseWheelEvent* BuildMouseWheelEvent(const PP_InputEvent& event) {
WebMouseWheelEvent* mouse_wheel_event = new WebMouseWheelEvent();
mouse_wheel_event->type = WebInputEvent::MouseWheel;
- mouse_wheel_event->timeStampSeconds = event.time_stamp;
+ mouse_wheel_event->timeStampSeconds =
+ PPTimeTicksToEventTime(event.time_stamp);
mouse_wheel_event->modifiers = event.u.wheel.modifier;
mouse_wheel_event->deltaX = event.u.wheel.delta_x;
mouse_wheel_event->deltaY = event.u.wheel.delta_y;
diff --git a/webkit/plugins/ppapi/file_callbacks.cc b/webkit/plugins/ppapi/file_callbacks.cc
index de913f4..d7e00ea 100644
--- a/webkit/plugins/ppapi/file_callbacks.cc
+++ b/webkit/plugins/ppapi/file_callbacks.cc
@@ -14,6 +14,7 @@
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
namespace webkit {
namespace ppapi {
@@ -51,9 +52,9 @@ void FileCallbacks::DidReadMetadata(
DCHECK(info_);
DCHECK(file_system_);
info_->size = file_info.size;
- info_->creation_time = file_info.creation_time.ToDoubleT();
- info_->last_access_time = file_info.last_accessed.ToDoubleT();
- info_->last_modified_time = file_info.last_modified.ToDoubleT();
+ info_->creation_time = TimeToPPTime(file_info.creation_time);
+ info_->last_access_time = TimeToPPTime(file_info.last_accessed);
+ info_->last_modified_time = TimeToPPTime(file_info.last_modified);
info_->system_type = file_system_->type();
if (file_info.is_directory)
info_->type = PP_FILETYPE_DIRECTORY;
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 4fc1fd2..5daf60e 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -149,15 +149,12 @@ void MemFree(void* ptr) {
free(ptr);
}
-double GetTime() {
- return base::Time::Now().ToDoubleT();
+PP_Time GetTime() {
+ return TimeToPPTime(base::Time::Now());
}
-double GetTickTime() {
- // TODO(brettw) http://code.google.com/p/chromium/issues/detail?id=57448
- // This should be a tick timer rather than wall clock time, but needs to
- // match message times, which also currently use wall clock time.
- return GetTime();
+PP_TimeTicks GetTickTime() {
+ return TimeTicksToPPTimeTicks(base::TimeTicks::Now());
}
void CallOnMainThread(int delay_in_msec,
diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h
index 52865bfc..e9bf1fe 100644
--- a/webkit/plugins/ppapi/plugin_module.h
+++ b/webkit/plugins/ppapi/plugin_module.h
@@ -21,6 +21,7 @@
#include "ppapi/c/pp_module.h"
#include "ppapi/c/ppb.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
class FilePath;
class MessageLoop;
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc
index 1a19912..16a438a 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc
@@ -23,6 +23,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_FileIO_API;
@@ -111,16 +112,16 @@ int32_t PPB_FileIO_Impl::Query(PP_FileInfo* info,
}
int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time,
- PP_Time last_modified_time,
- PP_CompletionCallback callback) {
+ PP_Time last_modified_time,
+ PP_CompletionCallback callback) {
int32_t rv = CommonCallValidation(true, callback);
if (rv != PP_OK)
return rv;
if (!base::FileUtilProxy::Touch(
instance()->delegate()->GetFileThreadMessageLoopProxy(),
- file_, base::Time::FromDoubleT(last_access_time),
- base::Time::FromDoubleT(last_modified_time),
+ file_, PPTimeToTime(last_access_time),
+ PPTimeToTime(last_modified_time),
callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback)))
return PP_ERROR_FAILED;
@@ -285,9 +286,9 @@ void PPB_FileIO_Impl::QueryInfoCallback(
DCHECK(info_);
if (error_code == base::PLATFORM_FILE_OK) {
info_->size = file_info.size;
- info_->creation_time = file_info.creation_time.ToDoubleT();
- info_->last_access_time = file_info.last_accessed.ToDoubleT();
- info_->last_modified_time = file_info.last_modified.ToDoubleT();
+ info_->creation_time = TimeToPPTime(file_info.creation_time);
+ info_->last_access_time = TimeToPPTime(file_info.last_accessed);
+ info_->last_modified_time = TimeToPPTime(file_info.last_modified);
info_->system_type = file_system_type_;
if (file_info.is_directory)
info_->type = PP_FILETYPE_DIRECTORY;
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
index 207ebb1..547218e 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
@@ -17,6 +17,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
#include "webkit/plugins/ppapi/var.h"
using ppapi::thunk::EnterResourceNoLock;
@@ -181,8 +182,8 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time,
return PP_ERROR_NOACCESS;
if (!instance()->delegate()->Touch(
GetFileSystemURL(),
- base::Time::FromDoubleT(last_access_time),
- base::Time::FromDoubleT(last_modified_time),
+ PPTimeToTime(last_access_time),
+ PPTimeToTime(last_modified_time),
new FileCallbacks(instance()->module()->AsWeakPtr(),
GetReferenceNoAddRef(), callback,
NULL, NULL, NULL)))
diff --git a/webkit/plugins/ppapi/ppb_flash_file_impl.cc b/webkit/plugins/ppapi/ppb_flash_file_impl.cc
index 297b9ee..3438cdb 100644
--- a/webkit/plugins/ppapi/ppb_flash_file_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_file_impl.cc
@@ -20,6 +20,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
#if defined(OS_WIN)
#include "base/utf_string_conversions.h"
@@ -137,9 +138,9 @@ int32_t QueryModuleLocalFile(PP_Instance pp_instance,
&file_info);
if (result == base::PLATFORM_FILE_OK) {
info->size = file_info.size;
- info->creation_time = file_info.creation_time.ToDoubleT();
- info->last_access_time = file_info.last_accessed.ToDoubleT();
- info->last_modified_time = file_info.last_modified.ToDoubleT();
+ info->creation_time = TimeToPPTime(file_info.creation_time);
+ info->last_access_time = TimeToPPTime(file_info.last_accessed);
+ info->last_modified_time = TimeToPPTime(file_info.last_modified);
info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
if (file_info.is_directory)
info->type = PP_FILETYPE_DIRECTORY;
@@ -253,9 +254,9 @@ int32_t QueryFileRefFile(PP_Resource file_ref_id,
&file_info);
if (result == base::PLATFORM_FILE_OK) {
info->size = file_info.size;
- info->creation_time = file_info.creation_time.ToDoubleT();
- info->last_access_time = file_info.last_accessed.ToDoubleT();
- info->last_modified_time = file_info.last_modified.ToDoubleT();
+ info->creation_time = TimeToPPTime(file_info.creation_time);
+ info->last_access_time = TimeToPPTime(file_info.last_accessed);
+ info->last_modified_time = TimeToPPTime(file_info.last_modified);
info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
if (file_info.is_directory)
info->type = PP_FILETYPE_DIRECTORY;
diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc
index 46f9cd91..bf537b5 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_impl.cc
@@ -17,6 +17,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
#include "webkit/plugins/ppapi/var.h"
using ppapi::thunk::EnterResource;
@@ -95,7 +96,7 @@ double GetLocalTimeZoneOffset(PP_Instance pp_instance, PP_Time t) {
// We can't do the conversion here because on Linux, the localtime calls
// require filesystem access prohibited by the sandbox.
return instance->delegate()->GetLocalTimeZoneOffset(
- base::Time::FromDoubleT(t));
+ PPTimeToTime(t));
}
PP_Var GetCommandLineArgs(PP_Module pp_module) {
diff --git a/webkit/plugins/ppapi/time_conversion.cc b/webkit/plugins/ppapi/time_conversion.cc
new file mode 100644
index 0000000..d5f1282
--- /dev/null
+++ b/webkit/plugins/ppapi/time_conversion.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/ppapi/time_conversion.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+// Since WebKit doesn't use ticks for event times, we have to compute what
+// the time ticks would be assuming the wall clock time doesn't change.
+//
+// This should only be used for WebKit times which we can't change the
+// definition of.
+double GetTimeToTimeTicksDeltaInSeconds() {
+ static double time_to_ticks_delta_seconds = 0.0;
+ if (time_to_ticks_delta_seconds == 0.0) {
+ double wall_clock = TimeToPPTime(base::Time::Now());
+ double ticks = TimeTicksToPPTimeTicks(base::TimeTicks::Now());
+ time_to_ticks_delta_seconds = ticks - wall_clock;
+ }
+ return time_to_ticks_delta_seconds;
+}
+
+} // namespace
+
+PP_Time TimeToPPTime(base::Time t) {
+ return t.ToDoubleT();
+}
+
+base::Time PPTimeToTime(PP_Time t) {
+ return base::Time::FromDoubleT(t);
+}
+
+PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t) {
+ return static_cast<double>(t.ToInternalValue() /
+ base::Time::kMicrosecondsPerSecond);
+}
+
+PP_TimeTicks EventTimeToPPTimeTicks(double event_time) {
+ return event_time + GetTimeToTimeTicksDeltaInSeconds();
+}
+
+double PPTimeTicksToEventTime(PP_TimeTicks t) {
+ return t - GetTimeToTimeTicksDeltaInSeconds();
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/time_conversion.h b/webkit/plugins/ppapi/time_conversion.h
new file mode 100644
index 0000000..13050e4
--- /dev/null
+++ b/webkit/plugins/ppapi/time_conversion.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_PLUGINS_PPAPI_TIME_CONVERSION_H_
+#define WEBKIT_PLUGINS_PPAPI_TIME_CONVERSION_H_
+
+#include "base/time.h"
+#include "ppapi/c/pp_time.h"
+
+namespace webkit {
+namespace ppapi {
+
+PP_Time TimeToPPTime(base::Time t);
+base::Time PPTimeToTime(PP_Time t);
+
+PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t);
+
+// Converts between WebKit event times and time ticks. WebKit event times are
+// currently expressed in terms of wall clock time. This function does the
+// proper mapping to time ticks, assuming the wall clock time doesn't change
+// (which isn't necessarily the case).
+PP_TimeTicks EventTimeToPPTimeTicks(double event_time);
+double PPTimeTicksToEventTime(PP_TimeTicks t);
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_TIME_CONVERSION_H_
diff --git a/webkit/plugins/ppapi/time_conversion_unittest.cc b/webkit/plugins/ppapi/time_conversion_unittest.cc
new file mode 100644
index 0000000..50fc116
--- /dev/null
+++ b/webkit/plugins/ppapi/time_conversion_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/plugins/ppapi/time_conversion.h"
+
+namespace webkit {
+namespace ppapi {
+
+// Slop we'll allow in two Time "internal values" to consider them equal.
+// Double conversion can introduce rounding errors. The internal values are in
+// microseconds, so an error here is very small.
+static const int kTimeInternalValueSlop = 2;
+
+// Same as above in double-precision seconds units.
+static const double kTimeSecondsSlop =
+ static_cast<double>(kTimeInternalValueSlop) /
+ base::Time::kMicrosecondsPerSecond;
+
+TEST(TimeConversion, Time) {
+ // Should be able to round-trip.
+ base::Time now = base::Time::Now();
+ base::Time converted = PPTimeToTime(TimeToPPTime(now));
+ EXPECT_GE(kTimeInternalValueSlop,
+ abs(static_cast<int>((converted - now).ToInternalValue())));
+
+ // Units should be in seconds.
+ base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
+ EXPECT_EQ(1.0, TimeToPPTime(one_second_from_now) - TimeToPPTime(now));
+}
+
+TEST(TimeConversion, EventTime) {
+ // Should be able to round-trip.
+ base::Time now = base::Time::Now();
+ double event_now = now.ToDoubleT();
+ double converted = EventTimeToPPTimeTicks(PPTimeTicksToEventTime(event_now));
+ EXPECT_GE(kTimeSecondsSlop, fabs(converted - event_now));
+
+ // Units should be in seconds.
+ base::Time one_second_from_now = now + base::TimeDelta::FromSeconds(1);
+ double event_one_second_from_now = one_second_from_now.ToDoubleT();
+ EXPECT_GE(kTimeSecondsSlop,
+ 1.0 - EventTimeToPPTimeTicks(event_one_second_from_now) -
+ EventTimeToPPTimeTicks(event_now));
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index d6b335f..99eb955 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -442,6 +442,7 @@
'../../plugins/ppapi/ppapi_unittest.cc',
'../../plugins/ppapi/ppapi_unittest.h',
'../../plugins/ppapi/resource_tracker_unittest.cc',
+ '../../plugins/ppapi/time_conversion_unittest.cc',
'../../plugins/ppapi/url_request_info_unittest.cc',
'../../quota/mock_special_storage_policy.cc',
'../../quota/mock_special_storage_policy.h',