diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-09-11 00:09:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-11 07:09:56 +0000 |
commit | bc8d8b62c3017dbdb413a636b80bc3a2df0172d6 (patch) | |
tree | 2f4de6402a0bfc56af023b4611bfe14fc59f8fa8 /components/net | |
parent | 095590e2247517cf22e4aea7956f341a9a38b206 (diff) | |
download | servo-bc8d8b62c3017dbdb413a636b80bc3a2df0172d6.tar.gz servo-bc8d8b62c3017dbdb413a636b80bc3a2df0172d6.zip |
Stop using `time@0.1` in Servo (#33394)
This removes the last few uses of `time@0.1` in Servo. There are still
dependencies from `style` and `webrender`, but they will be removed soon
as well. The uses of this version of `time` are replaced with
`std::time` types and `time@0.3` when negative `Duration` is necessary.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/net')
-rw-r--r-- | components/net/Cargo.toml | 2 | ||||
-rw-r--r-- | components/net/filemanager_thread.rs | 10 | ||||
-rw-r--r-- | components/net/hsts.rs | 22 | ||||
-rw-r--r-- | components/net/tests/hsts.rs | 19 |
4 files changed, 23 insertions, 30 deletions
diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 5495c515e8f..e8e0fe11e8c 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -56,8 +56,8 @@ servo_arc = { workspace = true } servo_config = { path = "../config" } servo_url = { path = "../url" } sha2 = "0.10" -time = { workspace = true } chrono = { workspace = true } +time_03 = { workspace = true } tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] } tokio-rustls = { workspace = true } tokio-stream = "0.1" diff --git a/components/net/filemanager_thread.rs b/components/net/filemanager_thread.rs index 0e86905fd0d..9ed08c9d85b 100644 --- a/components/net/filemanager_thread.rs +++ b/components/net/filemanager_thread.rs @@ -57,8 +57,6 @@ struct FileStoreEntry { #[derive(Clone)] struct FileMetaData { path: PathBuf, - /// Modified time in UNIX Epoch format - _modified: u64, size: u64, } @@ -639,11 +637,6 @@ impl FileManagerStore { let modified = metadata .modified() .map_err(|e| FileSystemError(e.to_string()))?; - let elapsed = modified - .elapsed() - .map_err(|e| FileSystemError(e.to_string()))?; - // Unix Epoch: https://doc.servo.org/std/time/constant.UNIX_EPOCH.html - let modified_epoch = elapsed.as_secs() * 1000 + elapsed.subsec_nanos() as u64 / 1000000; let file_size = metadata.len(); let file_name = file_path .file_name() @@ -651,7 +644,6 @@ impl FileManagerStore { let file_impl = FileImpl::MetaDataOnly(FileMetaData { path: file_path.to_path_buf(), - _modified: modified_epoch, size: file_size, }); @@ -678,7 +670,7 @@ impl FileManagerStore { Ok(SelectedFile { id, filename: filename_path.to_path_buf(), - modified: modified_epoch, + modified, size: file_size, type_string, }) diff --git a/components/net/hsts.rs b/components/net/hsts.rs index 7e8dca6ca82..a77d30c4689 100644 --- a/components/net/hsts.rs +++ b/components/net/hsts.rs @@ -4,7 +4,9 @@ use std::collections::HashMap; use std::net::{Ipv4Addr, Ipv6Addr}; +use std::time::Duration; +use base::cross_process_instant::CrossProcessInstant; use embedder_traits::resources::{self, Resource}; use headers::{HeaderMapExt, StrictTransportSecurity}; use http::HeaderMap; @@ -19,15 +21,15 @@ use servo_url::{Host, ServoUrl}; pub struct HstsEntry { pub host: String, pub include_subdomains: bool, - pub max_age: Option<u64>, - pub timestamp: Option<u64>, + pub max_age: Option<Duration>, + pub timestamp: Option<CrossProcessInstant>, } impl HstsEntry { pub fn new( host: String, subdomains: IncludeSubdomains, - max_age: Option<u64>, + max_age: Option<Duration>, ) -> Option<HstsEntry> { if host.parse::<Ipv4Addr>().is_ok() || host.parse::<Ipv6Addr>().is_ok() { None @@ -36,16 +38,14 @@ impl HstsEntry { host, include_subdomains: (subdomains == IncludeSubdomains::Included), max_age, - timestamp: Some(time::get_time().sec as u64), + timestamp: Some(CrossProcessInstant::now()), }) } } pub fn is_expired(&self) -> bool { match (self.max_age, self.timestamp) { - (Some(max_age), Some(timestamp)) => { - (time::get_time().sec as u64) - timestamp >= max_age - }, + (Some(max_age), Some(timestamp)) => CrossProcessInstant::now() - timestamp >= max_age, _ => false, } @@ -187,11 +187,9 @@ impl HstsList { IncludeSubdomains::NotIncluded }; - if let Some(entry) = HstsEntry::new( - host.to_owned(), - include_subdomains, - Some(header.max_age().as_secs()), - ) { + if let Some(entry) = + HstsEntry::new(host.to_owned(), include_subdomains, Some(header.max_age())) + { info!("adding host {} to the strict transport security list", host); info!("- max-age {}", header.max_age().as_secs()); if header.include_subdomains() { diff --git a/components/net/tests/hsts.rs b/components/net/tests/hsts.rs index a3bebb67fcf..e7fae4cf8a4 100644 --- a/components/net/tests/hsts.rs +++ b/components/net/tests/hsts.rs @@ -3,16 +3,19 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::collections::HashMap; +use std::time::Duration as StdDuration; +use base::cross_process_instant::CrossProcessInstant; use net::hsts::{HstsEntry, HstsList}; use net_traits::IncludeSubdomains; +use time_03::Duration; #[test] fn test_hsts_entry_is_not_expired_when_it_has_no_timestamp() { let entry = HstsEntry { host: "mozilla.org".to_owned(), include_subdomains: false, - max_age: Some(20), + max_age: Some(StdDuration::from_secs(20)), timestamp: None, }; @@ -25,7 +28,7 @@ fn test_hsts_entry_is_not_expired_when_it_has_no_max_age() { host: "mozilla.org".to_owned(), include_subdomains: false, max_age: None, - timestamp: Some(time::get_time().sec as u64), + timestamp: Some(CrossProcessInstant::now()), }; assert!(!entry.is_expired()); @@ -36,8 +39,8 @@ fn test_hsts_entry_is_expired_when_it_has_reached_its_max_age() { let entry = HstsEntry { host: "mozilla.org".to_owned(), include_subdomains: false, - max_age: Some(10), - timestamp: Some(time::get_time().sec as u64 - 20u64), + max_age: Some(StdDuration::from_secs(10)), + timestamp: Some(CrossProcessInstant::now() - Duration::seconds(20)), }; assert!(entry.is_expired()); @@ -106,7 +109,7 @@ fn test_push_entry_with_0_max_age_evicts_entry_from_list() { vec![HstsEntry::new( "mozilla.org".to_owned(), IncludeSubdomains::NotIncluded, - Some(500000u64), + Some(StdDuration::from_secs(500000)), ) .unwrap()], ); @@ -118,7 +121,7 @@ fn test_push_entry_with_0_max_age_evicts_entry_from_list() { HstsEntry::new( "mozilla.org".to_owned(), IncludeSubdomains::NotIncluded, - Some(0), + Some(StdDuration::ZERO), ) .unwrap(), ); @@ -367,8 +370,8 @@ fn test_hsts_list_with_expired_entry_is_not_is_host_secure() { vec![HstsEntry { host: "mozilla.org".to_owned(), include_subdomains: false, - max_age: Some(20), - timestamp: Some(time::get_time().sec as u64 - 100u64), + max_age: Some(StdDuration::from_secs(20)), + timestamp: Some(CrossProcessInstant::now() - Duration::seconds(100)), }], ); let hsts_list = HstsList { |