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

Side by Side Diff: ppapi/shared_impl/time_conversion.cc

Issue 11567013: Fix PPAPI time conversion code to handle epoch times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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 | « ppapi/ppapi_tests.gypi ('k') | ppapi/shared_impl/time_conversion_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/shared_impl/time_conversion.h" 5 #include "ppapi/shared_impl/time_conversion.h"
6 6
7 namespace ppapi { 7 namespace ppapi {
8 8
9 namespace { 9 namespace {
10 10
(...skipping 12 matching lines...) Expand all
23 return time_to_ticks_delta_seconds; 23 return time_to_ticks_delta_seconds;
24 } 24 }
25 25
26 } // namespace 26 } // namespace
27 27
28 PP_Time TimeToPPTime(base::Time t) { 28 PP_Time TimeToPPTime(base::Time t) {
29 return t.ToDoubleT(); 29 return t.ToDoubleT();
30 } 30 }
31 31
32 base::Time PPTimeToTime(PP_Time t) { 32 base::Time PPTimeToTime(PP_Time t) {
33 // The time code handles exact "0" values as special, and produces
34 // a "null" Time object. But calling code would expect t==0 to represent the
35 // epoch (according to the description of PP_Time). Hence we just return the
36 // epoch in this case.
37 if (t == 0.0)
38 return base::Time::UnixEpoch();
33 return base::Time::FromDoubleT(t); 39 return base::Time::FromDoubleT(t);
34 } 40 }
35 41
36 PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t) { 42 PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t) {
37 return static_cast<double>(t.ToInternalValue()) / 43 return static_cast<double>(t.ToInternalValue()) /
38 base::Time::kMicrosecondsPerSecond; 44 base::Time::kMicrosecondsPerSecond;
39 } 45 }
40 46
41 PP_TimeTicks EventTimeToPPTimeTicks(double event_time) { 47 PP_TimeTicks EventTimeToPPTimeTicks(double event_time) {
42 return event_time + GetTimeToTimeTicksDeltaInSeconds(); 48 return event_time + GetTimeToTimeTicksDeltaInSeconds();
43 } 49 }
44 50
45 double PPTimeTicksToEventTime(PP_TimeTicks t) { 51 double PPTimeTicksToEventTime(PP_TimeTicks t) {
46 return t - GetTimeToTimeTicksDeltaInSeconds(); 52 return t - GetTimeToTimeTicksDeltaInSeconds();
47 } 53 }
48 54
49 } // namespace ppapi 55 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/ppapi_tests.gypi ('k') | ppapi/shared_impl/time_conversion_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698