mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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>
This commit is contained in:
parent
095590e224
commit
bc8d8b62c3
18 changed files with 88 additions and 103 deletions
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue