Skip to content

Commit

Permalink
Cherry pick PR #3345: Remove starboard/common/time usage above Starbo…
Browse files Browse the repository at this point in the history
…ard (#3414)

Refer to the original PR: #3345

Remove starboard/common/time usage above Starboard

b/322248630

Change-Id: I5bf55bee02d4af2fd2e5cf48a435e33896151f64

Co-authored-by: iuriionishchenko <[email protected]>
  • Loading branch information
1 parent 37ab83c commit e39b52c
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 83 deletions.
7 changes: 3 additions & 4 deletions cobalt/bindings/testing/date_bindings_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "cobalt/bindings/testing/bindings_test_base.h"
#include "cobalt/bindings/testing/interface_with_date.h"
#include "starboard/client_porting/eztime/eztime.h"
#include "starboard/common/time.h"
#include "starboard/time_zone.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -79,7 +78,7 @@ TEST_F(DateBindingsTest, PosixEpoch) {
EvaluateScript("Date.now();", &result);
auto js_now_ms = std::stoll(result);
auto posix_now_ms =
starboard::CurrentPosixTime() / base::Time::kMicrosecondsPerMillisecond;
(base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds();
EXPECT_LT(std::abs(posix_now_ms - js_now_ms), 1000);
}

Expand All @@ -106,8 +105,8 @@ TEST_F(DateBindingsTest, StarboardTimeZone) {
}

TEST_F(DateBindingsTest, TimezoneOffset) {
EzTimeT ezttnow = static_cast<EzTimeT>(starboard::CurrentPosixTime() /
base::Time::kMicrosecondsPerSecond);
EzTimeT ezttnow = static_cast<EzTimeT>(
(base::Time::Now() - base::Time::UnixEpoch()).InSeconds());
EzTimeExploded ez_exploded_local;
EzTimeTExplodeLocal(&ezttnow, &ez_exploded_local);
// ez_exploded_local is already local time, use UTC method to convert to
Expand Down
3 changes: 1 addition & 2 deletions cobalt/browser/browser_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#include "cobalt/web/navigator_ua_data.h"
#include "starboard/atomic.h"
#include "starboard/common/string.h"
#include "starboard/common/time.h"
#include "starboard/configuration.h"
#include "starboard/extension/graphics.h"
#include "starboard/system.h"
Expand Down Expand Up @@ -89,7 +88,7 @@ NonTrivialGlobalVariables::NonTrivialGlobalVariables() {
SbAtomicNoBarrier_Exchange64(
last_render_timestamp,
static_cast<SbAtomic64>(
starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime())));
base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds();
}

base::LazyInstance<NonTrivialGlobalVariables>::DestructorAtExit
Expand Down
12 changes: 8 additions & 4 deletions cobalt/dom/html_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "cobalt/loader/resource_cache.h"
#include "cobalt/math/clamp.h"
#include "cobalt/web/csp_delegate.h"
#include "starboard/common/time.h"
#include "third_party/icu/source/common/unicode/uchar.h"
#include "third_party/icu/source/common/unicode/utf8.h"

Expand Down Expand Up @@ -94,7 +93,10 @@ const char* kPerformanceResourceTimingInitiatorType = "img";
void UiNavCallbackHelper(scoped_refptr<base::SequencedTaskRunner> task_runner,
base::Callback<void(int64_t)> callback) {
task_runner->PostTask(
FROM_HERE, base::Bind(callback, starboard::CurrentMonotonicTime()));
FROM_HERE,
base::Bind(
callback,
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds()));
}

struct NonTrivialStaticFields {
Expand Down Expand Up @@ -1498,7 +1500,8 @@ void HTMLElement::UpdateUiNavigationFocus() {
// Focus call for this HTMLElement as a result of OnUiNavBlur / OnUiNavFocus
// callbacks that result from initiating the UI navigation focus change.
if (node_document()->TrySetUiNavFocusElement(
html_element, starboard::CurrentMonotonicTime())) {
html_element,
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) {
html_element->ui_nav_item_->Focus();
}
break;
Expand Down Expand Up @@ -2300,7 +2303,8 @@ void HTMLElement::ReleaseUiNavigationItem() {
node_document()->set_ui_nav_needs_layout(true);
if (node_document()->ui_nav_focus_element() == this) {
if (node_document()->TrySetUiNavFocusElement(
nullptr, starboard::CurrentMonotonicTime())) {
nullptr, (base::TimeTicks::Now() - base::TimeTicks())
.InMicroseconds())) {
ui_nav_item_->UnfocusAll();
}
}
Expand Down
7 changes: 4 additions & 3 deletions cobalt/dom/html_link_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "cobalt/dom/window.h"
#include "cobalt/network/disk_cache/resource_type.h"
#include "cobalt/web/csp_delegate.h"
#include "starboard/common/time.h"
#include "url/gurl.h"

namespace cobalt {
Expand Down Expand Up @@ -319,11 +318,13 @@ void HTMLLinkElement::OnSplashscreenLoaded(Document* document,

void HTMLLinkElement::OnStylesheetLoaded(Document* document,
const std::string& content) {
auto before_parse_micros = starboard::CurrentMonotonicTime();
auto before_parse_micros =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
scoped_refptr<cssom::CSSStyleSheet> css_style_sheet =
document->html_element_context()->css_parser()->ParseStyleSheet(
content, base::SourceLocation(href(), 1, 1));
auto after_parse_micros = starboard::CurrentMonotonicTime();
auto after_parse_micros =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
auto css_kb = content.length() / 1000;
// Only measure non-trivial CSS sizes and ignore non-HTTP schemes (e.g.,
// file://), which are primarily used for debug purposes.
Expand Down
7 changes: 4 additions & 3 deletions cobalt/dom/html_style_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "cobalt/dom/document.h"
#include "cobalt/dom/html_element_context.h"
#include "cobalt/web/csp_delegate.h"
#include "starboard/common/time.h"

namespace cobalt {
namespace dom {
Expand Down Expand Up @@ -92,11 +91,13 @@ void HTMLStyleElement::Process() {
const std::string& text = content.value_or(base::EmptyString());
if (bypass_csp || csp_delegate->AllowInline(web::CspDelegate::kStyle,
inline_style_location_, text)) {
auto before_parse_micros = starboard::CurrentMonotonicTime();
auto before_parse_micros =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
scoped_refptr<cssom::CSSStyleSheet> css_style_sheet =
document->html_element_context()->css_parser()->ParseStyleSheet(
text, inline_style_location_);
auto after_parse_micros = starboard::CurrentMonotonicTime();
auto after_parse_micros =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
auto css_kb = text.length() / 1000;
// Only measure non-trivial css sizes and inlined HTML style elements.
if (css_kb > 0 &&
Expand Down
5 changes: 2 additions & 3 deletions cobalt/dom/performance_lifecycle_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "cobalt/dom/performance_lifecycle_timing.h"

#include "cobalt/dom/performance.h"
#include "starboard/common/time.h"

namespace cobalt {
namespace dom {
Expand Down Expand Up @@ -45,8 +44,8 @@ DOMHighResTimeStamp ConvertMonotonicTimestampToDOMHiResTimeStamp(
const DOMHighResTimeStamp time_origin, int64_t monotonic_time) {
// Current delta from Windows epoch.
int64_t time_delta =
starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()) -
starboard::CurrentMonotonicTime();
base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds() -
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
base::Time base_time = base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(time_delta + monotonic_time));
return ClampTimeStampMinimumResolution(
Expand Down
10 changes: 6 additions & 4 deletions cobalt/dom/serialized_algorithm_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "starboard/common/time.h"

namespace cobalt {
namespace dom {
Expand Down Expand Up @@ -92,7 +91,8 @@ class SerializedAlgorithmRunner {
// Crash if we are trying to re-acquire again on the same thread.
CHECK(!pthread_equal(acquired_thread_id_, pthread_self()));

int64_t start_usec = starboard::CurrentMonotonicTime();
int64_t start_usec =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
int64_t wait_interval_usec =
1 * base::Time::kMicrosecondsPerMillisecond;
constexpr int64_t kMaxWaitIntervalUsec =
Expand All @@ -108,8 +108,10 @@ class SerializedAlgorithmRunner {
wait_interval_usec =
std::min(wait_interval_usec * 2, kMaxWaitIntervalUsec);
// Crash if we've been waiting for too long (1 second).
CHECK_LT(starboard::CurrentMonotonicTime() - start_usec,
1 * base::Time::kMicrosecondsPerSecond);
CHECK_LT(
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() -
start_usec,
1 * base::Time::kMicrosecondsPerSecond);
}
acquired_thread_id_ = pthread_self();
}
Expand Down
7 changes: 4 additions & 3 deletions cobalt/dom/source_buffer_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "cobalt/base/statistics.h"
#include "starboard/common/once.h"
#include "starboard/common/string.h"
#include "starboard/common/time.h"
#include "starboard/types.h"

namespace cobalt {
Expand Down Expand Up @@ -79,7 +78,8 @@ void SourceBufferMetrics::StartTracking(SourceBufferMetricsAction action) {
wall_start_time_ = clock_->NowTicks();

#if !defined(COBALT_BUILD_TYPE_GOLD)
thread_start_time_ = starboard::CurrentMonotonicThreadTime();
thread_start_time_ =
(base::ThreadTicks::Now() - base::ThreadTicks()).InMicroseconds();
#endif // !defined(COBALT_BUILD_TYPE_GOLD)
}

Expand All @@ -101,7 +101,8 @@ void SourceBufferMetrics::EndTracking(SourceBufferMetricsAction action,

#if !defined(COBALT_BUILD_TYPE_GOLD)
int64_t thread_duration =
starboard::CurrentMonotonicThreadTime() - thread_start_time_;
(base::ThreadTicks::Now() - base::ThreadTicks()).InMicroseconds() -
thread_start_time_;

total_wall_time_ += wall_duration.InMicroseconds();
total_thread_time_ += thread_duration;
Expand Down
3 changes: 1 addition & 2 deletions cobalt/media_session/media_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "cobalt/script/callback_function.h"
#include "cobalt/script/script_value.h"
#include "cobalt/script/wrappable.h"
#include "starboard/common/time.h"

namespace cobalt {
namespace media_session {
Expand Down Expand Up @@ -97,7 +96,7 @@ class MediaSession : public script::Wrappable {

// Returns a time representing right now - may be overridden for testing.
virtual int64_t GetMonotonicNow() const {
return starboard::CurrentMonotonicTime();
return (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
}

ActionMap action_map_;
Expand Down
4 changes: 2 additions & 2 deletions cobalt/media_session/media_session_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "base/logging.h"
#include "cobalt/media_session/media_image.h"
#include "cobalt/script/sequence.h"
#include "starboard/common/time.h"

namespace cobalt {
namespace media_session {
Expand Down Expand Up @@ -70,7 +69,8 @@ void GuessMediaPositionState(MediaSessionState* session_state,
position_state.set_position((*guess_player)->GetCurrentTime());

*session_state = MediaSessionState(
session_state->metadata(), starboard::CurrentMonotonicTime(),
session_state->metadata(),
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(),
position_state, session_state->actual_playback_state(),
session_state->available_actions());
}
Expand Down
6 changes: 3 additions & 3 deletions cobalt/media_session/media_session_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "cobalt/media_session/media_position_state.h"
#include "cobalt/media_session/media_session_action.h"
#include "cobalt/media_session/media_session_playback_state.h"
#include "starboard/common/time.h"

namespace cobalt {
namespace media_session {
Expand Down Expand Up @@ -61,11 +60,12 @@ class MediaSessionState {
// https://wicg.github.io/mediasession/#current-playback-position
// Returns the position
int64_t current_playback_position() const {
return GetCurrentPlaybackPosition(starboard::CurrentMonotonicTime());
return GetCurrentPlaybackPosition(
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds());
}

// Returns the position of the current playback, given the current time.
// This may be used for testing without calling |CurrentMonotonicTime|.
// This may be used for testing without calling |base::TimeTicks::Now|.
int64_t GetCurrentPlaybackPosition(int64_t monotonic_now) const;

// Returns a coefficient of the current playback rate. e.g. 1.0 is normal
Expand Down
1 change: 0 additions & 1 deletion cobalt/media_session/media_session_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "cobalt/script/script_value.h"
#include "cobalt/script/testing/fake_script_value.h"
#include "cobalt/script/wrappable.h"
#include "starboard/common/time.h"
#include "starboard/extension/media_session.h"
#include "starboard/thread.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down
6 changes: 3 additions & 3 deletions cobalt/network/custom/url_fetcher_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_throttler_manager.h"
#include "starboard/common/time.h"
#include "starboard/types.h"
#include "url/origin.h"

Expand Down Expand Up @@ -546,13 +545,14 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request, int bytes_read) {
#if defined(STARBOARD)
// Prime it to the current time so it is only called after the loop, or every
// time when the loop takes |kInformDownloadProgressIntervalUsec|.
int64_t download_progress_informed_at = starboard::CurrentMonotonicTime();
int64_t download_progress_informed_at =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
bool did_read_after_inform_download_progress = false;

while (bytes_read > 0) {
current_response_bytes_ += bytes_read;
did_read_after_inform_download_progress = true;
auto now = starboard::CurrentMonotonicTime();
auto now = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
if (now - download_progress_informed_at >
kInformDownloadProgressIntervalUsec) {
InformDelegateDownloadProgress();
Expand Down
19 changes: 10 additions & 9 deletions cobalt/renderer/backend/graphics_system_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "base/time/time.h"
#include "cobalt/renderer/backend/default_graphics_system.h"
#include "cobalt/renderer/backend/graphics_context.h"
#include "starboard/common/time.h"
#include "starboard/log.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -45,13 +44,14 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsSystemCanBeInitializedOften) {
graphics_system = CreateDefaultGraphicsSystem();
graphics_system.reset();

int64_t start = starboard::CurrentMonotonicTime();
int64_t start = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
for (int i = 0; i < kReferenceCount; ++i) {
graphics_system = CreateDefaultGraphicsSystem();
graphics_system.reset();
}
int64_t time_per_initialization_usec =
(starboard::CurrentMonotonicTime() - start) / kReferenceCount;
((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - start) /
kReferenceCount;
LOG(INFO) << "Measured duration "
<< time_per_initialization_usec /
base::Time::kMicrosecondsPerMillisecond
Expand All @@ -63,11 +63,11 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsSystemCanBeInitializedOften) {
std::max<int64_t>(3 * time_per_initialization_usec,
250 * base::Time::kMicrosecondsPerMillisecond);

int64_t last = starboard::CurrentMonotonicTime();
int64_t last = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
for (int i = 0; i < 20; ++i) {
graphics_system = CreateDefaultGraphicsSystem();
graphics_system.reset();
int64_t now = starboard::CurrentMonotonicTime();
int64_t now = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
int64_t elapsed_time_usec = now - last;
LOG(INFO) << "Test duration "
<< elapsed_time_usec / base::Time::kMicrosecondsPerMillisecond
Expand All @@ -90,7 +90,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) {
graphics_context.reset();
graphics_system.reset();

int64_t start = starboard::CurrentMonotonicTime();
int64_t start = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
for (int i = 0; i < kReferenceCount; ++i) {
graphics_system = CreateDefaultGraphicsSystem();
graphics_context = graphics_system->CreateGraphicsContext();
Expand All @@ -100,7 +100,8 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) {
}
int64_t time_per_initialization_usec =
base::Time::kMicrosecondsPerMillisecond +
(starboard::CurrentMonotonicTime() - start) / kReferenceCount;
((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - start) /
kReferenceCount;
LOG(INFO) << "Measured duration "
<< time_per_initialization_usec /
base::Time::kMicrosecondsPerMillisecond
Expand All @@ -112,15 +113,15 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) {
std::max<int64_t>(3 * time_per_initialization_usec,
250 * base::Time::kMicrosecondsPerMillisecond);

int64_t last = starboard::CurrentMonotonicTime();
int64_t last = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
for (int i = 0; i < 20; ++i) {
graphics_system = CreateDefaultGraphicsSystem();
graphics_context = graphics_system->CreateGraphicsContext();

graphics_context.reset();
graphics_system.reset();

int64_t now = starboard::CurrentMonotonicTime();
int64_t now = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
int64_t elapsed_time_usec = now - last;
LOG(INFO) << "Test duration "
<< elapsed_time_usec / base::Time::kMicrosecondsPerMillisecond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "SkTime.h"
#include "SkTypes.h"
#include "base/time/time.h"
#include "starboard/common/time.h"

// Taken from SkTime.cpp.
void SkTime::DateTime::toISO8601(SkString* dst) const {
Expand Down Expand Up @@ -52,6 +51,6 @@ void SkTime::GetDateTime(DateTime* dt) {
}

double SkTime::GetNSecs() {
return starboard::CurrentMonotonicTime() *
return (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() *
base::Time::kNanosecondsPerMicrosecond;
}
Loading

0 comments on commit e39b52c

Please sign in to comment.