From e39b52c17091e7dc8dccc3c26ef3982bc050c676 Mon Sep 17 00:00:00 2001 From: cobalt-github-releaser-bot <95661244+cobalt-github-releaser-bot@users.noreply.github.com> Date: Fri, 31 May 2024 18:08:33 -0700 Subject: [PATCH] Cherry pick PR #3345: Remove starboard/common/time usage above Starboard (#3414) Refer to the original PR: https://github.com/youtube/cobalt/pull/3345 Remove starboard/common/time usage above Starboard b/322248630 Change-Id: I5bf55bee02d4af2fd2e5cf48a435e33896151f64 Co-authored-by: iuriionishchenko <136322748+iuriionishchenko@users.noreply.github.com> --- cobalt/bindings/testing/date_bindings_test.cc | 7 ++-- cobalt/browser/browser_module.cc | 3 +- cobalt/dom/html_element.cc | 12 ++++-- cobalt/dom/html_link_element.cc | 7 ++-- cobalt/dom/html_style_element.cc | 7 ++-- cobalt/dom/performance_lifecycle_timing.cc | 5 +-- cobalt/dom/serialized_algorithm_runner.h | 10 +++-- cobalt/dom/source_buffer_metrics.cc | 7 ++-- cobalt/media_session/media_session.h | 3 +- cobalt/media_session/media_session_client.cc | 4 +- cobalt/media_session/media_session_state.h | 6 +-- cobalt/media_session/media_session_test.cc | 1 - cobalt/network/custom/url_fetcher_core.cc | 6 +-- .../renderer/backend/graphics_system_test.cc | 19 +++++----- .../skia/skia/src/ports/SkTime_cobalt.cc | 3 +- cobalt/system_window/system_window.cc | 4 +- cobalt/updater/unzipper.cc | 9 ++--- cobalt/watchdog/watchdog.cc | 38 ++++++++++++------- cobalt/web/event.cc | 17 +++++---- .../cobalt_slot_management_test.cc | 4 +- .../zlib/google/compression_utils_unittest.cc | 9 ++--- 21 files changed, 98 insertions(+), 83 deletions(-) diff --git a/cobalt/bindings/testing/date_bindings_test.cc b/cobalt/bindings/testing/date_bindings_test.cc index d96ddbfadbed..86683eedfdf1 100644 --- a/cobalt/bindings/testing/date_bindings_test.cc +++ b/cobalt/bindings/testing/date_bindings_test.cc @@ -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" @@ -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); } @@ -106,8 +105,8 @@ TEST_F(DateBindingsTest, StarboardTimeZone) { } TEST_F(DateBindingsTest, TimezoneOffset) { - EzTimeT ezttnow = static_cast(starboard::CurrentPosixTime() / - base::Time::kMicrosecondsPerSecond); + EzTimeT ezttnow = static_cast( + (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 diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index c4d69c0861c1..a46635c66b86 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -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" @@ -89,7 +88,7 @@ NonTrivialGlobalVariables::NonTrivialGlobalVariables() { SbAtomicNoBarrier_Exchange64( last_render_timestamp, static_cast( - starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()))); + base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds(); } base::LazyInstance::DestructorAtExit diff --git a/cobalt/dom/html_element.cc b/cobalt/dom/html_element.cc index 58b124b988bb..1d9d335c8f14 100644 --- a/cobalt/dom/html_element.cc +++ b/cobalt/dom/html_element.cc @@ -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" @@ -94,7 +93,10 @@ const char* kPerformanceResourceTimingInitiatorType = "img"; void UiNavCallbackHelper(scoped_refptr task_runner, base::Callback callback) { task_runner->PostTask( - FROM_HERE, base::Bind(callback, starboard::CurrentMonotonicTime())); + FROM_HERE, + base::Bind( + callback, + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())); } struct NonTrivialStaticFields { @@ -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; @@ -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(); } } diff --git a/cobalt/dom/html_link_element.cc b/cobalt/dom/html_link_element.cc index 70dbca13bf7e..04bc36c24a98 100644 --- a/cobalt/dom/html_link_element.cc +++ b/cobalt/dom/html_link_element.cc @@ -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 { @@ -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 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. diff --git a/cobalt/dom/html_style_element.cc b/cobalt/dom/html_style_element.cc index cfeb76d91ef6..2dd705f06865 100644 --- a/cobalt/dom/html_style_element.cc +++ b/cobalt/dom/html_style_element.cc @@ -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 { @@ -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 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 && diff --git a/cobalt/dom/performance_lifecycle_timing.cc b/cobalt/dom/performance_lifecycle_timing.cc index 779e69af1535..14d7f7753180 100644 --- a/cobalt/dom/performance_lifecycle_timing.cc +++ b/cobalt/dom/performance_lifecycle_timing.cc @@ -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 { @@ -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( diff --git a/cobalt/dom/serialized_algorithm_runner.h b/cobalt/dom/serialized_algorithm_runner.h index d1e00276fe6b..c9fafc3bac1d 100644 --- a/cobalt/dom/serialized_algorithm_runner.h +++ b/cobalt/dom/serialized_algorithm_runner.h @@ -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 { @@ -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 = @@ -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(); } diff --git a/cobalt/dom/source_buffer_metrics.cc b/cobalt/dom/source_buffer_metrics.cc index a8f9e209fd6c..3587cd537457 100644 --- a/cobalt/dom/source_buffer_metrics.cc +++ b/cobalt/dom/source_buffer_metrics.cc @@ -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 { @@ -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) } @@ -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; diff --git a/cobalt/media_session/media_session.h b/cobalt/media_session/media_session.h index ec9598fb3dc4..33d7b6dfd8b8 100644 --- a/cobalt/media_session/media_session.h +++ b/cobalt/media_session/media_session.h @@ -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 { @@ -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_; diff --git a/cobalt/media_session/media_session_client.cc b/cobalt/media_session/media_session_client.cc index ad93e31de6af..5babc10a60c6 100644 --- a/cobalt/media_session/media_session_client.cc +++ b/cobalt/media_session/media_session_client.cc @@ -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 { @@ -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()); } diff --git a/cobalt/media_session/media_session_state.h b/cobalt/media_session/media_session_state.h index 09b48aa57a08..bcab1565a1e4 100644 --- a/cobalt/media_session/media_session_state.h +++ b/cobalt/media_session/media_session_state.h @@ -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 { @@ -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 diff --git a/cobalt/media_session/media_session_test.cc b/cobalt/media_session/media_session_test.cc index ba3f56d9730f..a672f69a2592 100644 --- a/cobalt/media_session/media_session_test.cc +++ b/cobalt/media_session/media_session_test.cc @@ -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" diff --git a/cobalt/network/custom/url_fetcher_core.cc b/cobalt/network/custom/url_fetcher_core.cc index 6cebf8565548..b10656ed6834 100644 --- a/cobalt/network/custom/url_fetcher_core.cc +++ b/cobalt/network/custom/url_fetcher_core.cc @@ -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" @@ -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(); diff --git a/cobalt/renderer/backend/graphics_system_test.cc b/cobalt/renderer/backend/graphics_system_test.cc index 62297535c097..0823b720f8de 100644 --- a/cobalt/renderer/backend/graphics_system_test.cc +++ b/cobalt/renderer/backend/graphics_system_test.cc @@ -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" @@ -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 @@ -63,11 +63,11 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsSystemCanBeInitializedOften) { std::max(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 @@ -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(); @@ -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 @@ -112,7 +113,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { std::max(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(); @@ -120,7 +121,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { 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 diff --git a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc index 1e11ae0bbbf7..1ac140e2884b 100644 --- a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc +++ b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc @@ -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 { @@ -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; } diff --git a/cobalt/system_window/system_window.cc b/cobalt/system_window/system_window.cc index 37e5961c25f4..9c62f222b8a1 100644 --- a/cobalt/system_window/system_window.cc +++ b/cobalt/system_window/system_window.cc @@ -20,9 +20,9 @@ #include "base/logging.h" #include "base/strings/stringprintf.h" +#include "base/time/time.h" #include "cobalt/base/event_dispatcher.h" #include "cobalt/system_window/input_event.h" -#include "starboard/common/time.h" #include "starboard/system.h" namespace cobalt { @@ -123,7 +123,7 @@ void SystemWindow::DispatchInputEvent(const SbEvent* event, // Use the current time unless it was overridden. int64_t timestamp = event->timestamp; if (timestamp == 0) { - timestamp = starboard::CurrentMonotonicTime(); + timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } // Starboard handily uses the Microsoft key mapping, which is also what Cobalt // uses. diff --git a/cobalt/updater/unzipper.cc b/cobalt/updater/unzipper.cc index 71e8c0319b45..211de33f228d 100644 --- a/cobalt/updater/unzipper.cc +++ b/cobalt/updater/unzipper.cc @@ -10,7 +10,6 @@ #include "base/files/file_path.h" #include "base/logging.h" #include "base/time/time.h" -#include "starboard/common/time.h" #include "third_party/zlib/google/zip.h" namespace cobalt { @@ -24,10 +23,10 @@ class UnzipperImpl : public update_client::Unzipper { void Unzip(const base::FilePath& zip_path, const base::FilePath& output_path, UnzipCompleteCallback callback) override { - int64_t time_before_unzip = starboard::CurrentMonotonicTime(); + int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); std::move(callback).Run(zip::Unzip(zip_path, output_path)); int64_t time_unzip_took_usec = - starboard::CurrentMonotonicTime() - time_before_unzip; + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip; LOG(INFO) << "Unzip file path = " << zip_path; LOG(INFO) << "output_path = " << output_path; LOG(INFO) << "Unzip took " @@ -38,10 +37,10 @@ class UnzipperImpl : public update_client::Unzipper { #if defined(IN_MEMORY_UPDATES) void Unzip(const std::string& zip_str, const base::FilePath& output_path, UnzipCompleteCallback callback) override { - int64_t time_before_unzip = starboard::CurrentMonotonicTime(); + int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); std::move(callback).Run(zip::Unzip(zip_str, output_path)); int64_t time_unzip_took_usec = - starboard::CurrentMonotonicTime() - time_before_unzip; + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip; LOG(INFO) << "Unzip from string"; LOG(INFO) << "output_path = " << output_path; LOG(INFO) << "Unzip took " diff --git a/cobalt/watchdog/watchdog.cc b/cobalt/watchdog/watchdog.cc index db3fa2863e6d..d30f419f1f6e 100644 --- a/cobalt/watchdog/watchdog.cc +++ b/cobalt/watchdog/watchdog.cc @@ -27,7 +27,6 @@ #include "base/logging.h" #include "base/time/time.h" #include "starboard/common/file.h" -#include "starboard/common/time.h" #include "starboard/configuration_constants.h" #if defined(_DEBUG) @@ -196,14 +195,16 @@ void Watchdog::WriteWatchdogViolations() { watchdog_file.WriteAll(watchdog_json.c_str(), static_cast(watchdog_json.size())); pending_write_ = false; - time_last_written_microseconds_ = starboard::CurrentMonotonicTime(); + time_last_written_microseconds_ = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } void* Watchdog::Monitor(void* context) { pthread_setname_np(pthread_self(), "Watchdog"); base::AutoLock scoped_lock(static_cast(context)->mutex_); while (1) { - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); bool watchdog_violation = false; // Iterates through client map to monitor all name registered clients. @@ -310,7 +311,8 @@ void Watchdog::UpdateViolationsMap(void* context, Client* client, violation.SetKey("timestampLastPingedMilliseconds", base::Value(std::to_string( client->time_last_pinged_microseconds / 1000))); - int64_t current_timestamp_millis = starboard::CurrentPosixTime() / 1000; + int64_t current_timestamp_millis = + (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds(); violation.SetKey("timestampViolationMilliseconds", base::Value(std::to_string(current_timestamp_millis))); violation.SetKey( @@ -444,7 +446,7 @@ void Watchdog::EvictWatchdogViolation(void* context) { } void Watchdog::MaybeWriteWatchdogViolations(void* context) { - if (starboard::CurrentMonotonicTime() > + if ((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() > static_cast(context)->time_last_written_microseconds_ + static_cast(context)->write_wait_time_microseconds_) { static_cast(context)->WriteWatchdogViolations(); @@ -468,8 +470,10 @@ bool Watchdog::Register(std::string name, std::string description, base::AutoLock scoped_lock(mutex_); - int64_t current_time = starboard::CurrentPosixTime(); - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_time = + (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); // If replace is PING or ALL, handles already registered cases. if (replace != NONE) { @@ -512,8 +516,10 @@ std::shared_ptr Watchdog::RegisterByClient( base::AutoLock scoped_lock(mutex_); - int64_t current_time = starboard::CurrentPosixTime(); - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_time = + (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); // Creates new client. std::shared_ptr client = CreateClient( @@ -652,8 +658,10 @@ bool Watchdog::PingHelper(Client* client, const std::string& name, return false; } - int64_t current_time = starboard::CurrentPosixTime(); - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_time = + (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); // Updates last ping. client->time_last_pinged_microseconds = current_time; @@ -719,7 +727,8 @@ std::string Watchdog::GetWatchdogViolations( } void Watchdog::EvictOldWatchdogViolations() { - int64_t current_timestamp_millis = starboard::CurrentPosixTime() / 1000; + int64_t current_timestamp_millis = + (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds(); int64_t cutoff_timestamp_millis = current_timestamp_millis - kWatchdogMaxViolationsAge; std::vector empty_violations; @@ -848,10 +857,11 @@ void Watchdog::MaybeInjectDebugDelay(const std::string& name) { if (name != delay_name_) return; - if (starboard::CurrentMonotonicTime() > + if ((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() > time_last_delayed_microseconds_ + delay_wait_time_microseconds_) { usleep(delay_sleep_time_microseconds_); - time_last_delayed_microseconds_ = starboard::CurrentMonotonicTime(); + time_last_delayed_microseconds_ = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } } #endif // defined(_DEBUG) diff --git a/cobalt/web/event.cc b/cobalt/web/event.cc index 4a530c6675a8..6d8ec96324b6 100644 --- a/cobalt/web/event.cc +++ b/cobalt/web/event.cc @@ -17,14 +17,14 @@ #include "base/compiler_specific.h" #include "base/time/time.h" #include "cobalt/web/event_target.h" -#include "starboard/common/time.h" namespace cobalt { namespace web { Event::Event(UninitializedFlag uninitialized_flag) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { InitEventInternal(base_token::Token(), false, false); } @@ -32,20 +32,23 @@ Event::Event(const char* type) : Event(base_token::Token(type)) {} Event::Event(const std::string& type) : Event(base_token::Token(type)) {} Event::Event(base_token::Token type) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { InitEventInternal(type, false, false); } Event::Event(const std::string& type, const EventInit& init_dict) : Event(base_token::Token(type), init_dict) {} Event::Event(base_token::Token type, Bubbles bubbles, Cancelable cancelable) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { InitEventInternal(type, bubbles == kBubbles, cancelable == kCancelable); } Event::Event(base_token::Token type, const EventInit& init_dict) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { SB_DCHECK(init_dict.has_bubbles()); SB_DCHECK(init_dict.has_cancelable()); if (init_dict.time_stamp() != 0) { @@ -101,8 +104,8 @@ void Event::TraceMembers(script::Tracer* tracer) { uint64 Event::GetEventTime(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)); // For now, continue using the old specification which specifies real time diff --git a/components/update_client/cobalt_slot_management_test.cc b/components/update_client/cobalt_slot_management_test.cc index 6790005827a3..47e3434be6b6 100644 --- a/components/update_client/cobalt_slot_management_test.cc +++ b/components/update_client/cobalt_slot_management_test.cc @@ -20,8 +20,8 @@ #include #include "base/strings/string_util.h" +#include "base/time/time.h" #include "starboard/common/file.h" -#include "starboard/common/time.h" #include "starboard/extension/free_space.h" #include "starboard/loader_app/app_key_files.h" #include "starboard/loader_app/drain_file.h" @@ -206,7 +206,7 @@ TEST_F(CobaltSlotManagementTest, ConfirmSlotBailsIfOtherAppStartedDrainFirst) { // In order to be higher ranked, the other app's drain file needs to be older // but not expired. int64_t current_time_us = - starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()); + base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds(); starboard::loader_app::ScopedDrainFile racing_drain_file( slot_path, kTestAppKey2, current_time_us - (kDrainFileMaximumAgeUsec / 2)); diff --git a/third_party/zlib/google/compression_utils_unittest.cc b/third_party/zlib/google/compression_utils_unittest.cc index 12a9ea8e7c54..4c415596d608 100644 --- a/third_party/zlib/google/compression_utils_unittest.cc +++ b/third_party/zlib/google/compression_utils_unittest.cc @@ -12,7 +12,6 @@ #include "base/logging.h" #include "base/stl_util.h" #include "starboard/common/log.h" -#include "starboard/common/time.h" #include "testing/gtest/include/gtest/gtest.h" namespace compression { @@ -102,22 +101,22 @@ TEST(CompressionUtilsTest, OutputCompressionAndDecompressionDuration) { for (size_t i = 0; i < kSize; ++i) data[i] = static_cast(i & 0xFF); - int64_t begin = starboard::CurrentPosixTime(); + int64_t begin = (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); std::string compressed_data; EXPECT_TRUE(GzipCompress(data, &compressed_data)); SB_LOG(INFO) << "GzipCompress() of 32MiB took " - << (starboard::CurrentPosixTime() - begin) / 1000 + << ((base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds() - begin) / 1000 << " milliseconds."; - begin = starboard::CurrentPosixTime(); + begin = (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); std::string uncompressed_data; EXPECT_TRUE(GzipUncompress(compressed_data, &uncompressed_data)); SB_LOG(INFO) << "GzipUncompress() of 32MiB took " - << (starboard::CurrentPosixTime() - begin) / 1000 + << ((base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds() - begin) / 1000 << " milliseconds."; } #endif