diff options
author | Taym Haddadi <haddadi.taym@gmail.com> | 2024-01-10 20:23:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 19:23:47 +0000 |
commit | 92196d985dceb0ca708b097e2a847b255d8387c8 (patch) | |
tree | 65ddaf307c5d78fe0a8e41b9594fe1a00f440006 /components/shared/net/lib.rs | |
parent | e3e0d8f2c41e5d3b7ec46c851a9754fe4e486dae (diff) | |
download | servo-92196d985dceb0ca708b097e2a847b255d8387c8.tar.gz servo-92196d985dceb0ca708b097e2a847b255d8387c8.zip |
Replace time with std::time in components/metrics & components/shared (#31020)
Diffstat (limited to 'components/shared/net/lib.rs')
-rw-r--r-- | components/shared/net/lib.rs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/components/shared/net/lib.rs b/components/shared/net/lib.rs index b8b32725a25..63f4e7d8710 100644 --- a/components/shared/net/lib.rs +++ b/components/shared/net/lib.rs @@ -4,6 +4,8 @@ #![deny(unsafe_code)] +use std::time::{SystemTime, UNIX_EPOCH}; + use cookie::Cookie; use headers::{ContentType, HeaderMapExt, ReferrerPolicy as ReferrerPolicyHeader}; use http::{Error as HttpError, HeaderMap, StatusCode}; @@ -18,11 +20,11 @@ use malloc_size_of::malloc_size_of_is_0; use malloc_size_of_derive::MallocSizeOf; use mime::Mime; use msg::constellation_msg::HistoryStateId; +use num_traits::Zero; use rustls::Certificate; use serde::{Deserialize, Serialize}; use servo_rand::RngCore; use servo_url::{ImmutableOrigin, ServoUrl}; -use time::precise_time_ns; use webrender_api::{ImageData, ImageDescriptor, ImageKey}; use crate::filemanager_thread::FileManagerThreadMsg; @@ -594,15 +596,19 @@ impl ResourceFetchTiming { if !self.timing_check_passed && !should_attribute_always_be_updated { return; } + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64; match attribute { - ResourceAttribute::DomainLookupStart => self.domain_lookup_start = precise_time_ns(), + ResourceAttribute::DomainLookupStart => self.domain_lookup_start = now, ResourceAttribute::RedirectCount(count) => self.redirect_count = count, - ResourceAttribute::RequestStart => self.request_start = precise_time_ns(), - ResourceAttribute::ResponseStart => self.response_start = precise_time_ns(), + ResourceAttribute::RequestStart => self.request_start = now, + ResourceAttribute::ResponseStart => self.response_start = now, ResourceAttribute::RedirectStart(val) => match val { RedirectStartValue::Zero => self.redirect_start = 0, RedirectStartValue::FetchStart => { - if self.redirect_start == 0 { + if self.redirect_start.is_zero() { self.redirect_start = self.fetch_start } }, @@ -611,16 +617,14 @@ impl ResourceFetchTiming { RedirectEndValue::Zero => self.redirect_end = 0, RedirectEndValue::ResponseEnd => self.redirect_end = self.response_end, }, - ResourceAttribute::FetchStart => self.fetch_start = precise_time_ns(), + ResourceAttribute::FetchStart => self.fetch_start = now, ResourceAttribute::ConnectStart(val) => self.connect_start = val, ResourceAttribute::ConnectEnd(val) => self.connect_end = val, - ResourceAttribute::SecureConnectionStart => { - self.secure_connection_start = precise_time_ns() - }, - ResourceAttribute::ResponseEnd => self.response_end = precise_time_ns(), + ResourceAttribute::SecureConnectionStart => self.secure_connection_start = now, + ResourceAttribute::ResponseEnd => self.response_end = now, ResourceAttribute::StartTime(val) => match val { ResourceTimeValue::RedirectStart - if self.redirect_start == 0 || !self.timing_check_passed => {}, + if self.redirect_start.is_zero() || !self.timing_check_passed => {}, _ => self.start_time = self.get_time_value(val), }, } @@ -629,7 +633,10 @@ impl ResourceFetchTiming { fn get_time_value(&self, time: ResourceTimeValue) -> u64 { match time { ResourceTimeValue::Zero => 0, - ResourceTimeValue::Now => precise_time_ns(), + ResourceTimeValue::Now => SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64, ResourceTimeValue::FetchStart => self.fetch_start, ResourceTimeValue::RedirectStart => self.redirect_start, } |