From 5c56e661cad495ee5efb392c5ef914322758d39c Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sun, 8 Dec 2019 18:24:44 +0530 Subject: [PATCH 1/4] `worker_id` type changed to uuid Fixes #6631 `worker_id` is now generate as uuid and saved as string. --- components/devtools/lib.rs | 2 +- components/devtools_traits/lib.rs | 5 +++-- components/script/Cargo.toml | 2 +- components/script/dom/globalscope.rs | 9 ++++----- components/script/serviceworker_manager.rs | 3 ++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index 63e4c7aea15..cc37ed7c4b0 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -307,7 +307,7 @@ fn run_server( let worker = WorkerActor { name: actors.new_name("worker"), console: console.name(), - id: id, + id: id.clone(), }; actor_workers.insert((pipeline, id), worker.name.clone()); actors.register(Box::new(worker)); diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 0e0872e7663..c71693dff40 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -25,6 +25,7 @@ use msg::constellation_msg::PipelineId; use servo_url::ServoUrl; use std::net::TcpStream; use time::{self, Duration, Tm}; +//use uuid::Uuid; // Information would be attached to NewGlobal to be received and show in devtools. // Extend these fields if we need more information. @@ -356,5 +357,5 @@ impl PreciseTime { } } -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] -pub struct WorkerId(pub u32); +#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] +pub struct WorkerId(pub String); diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index cfa02f3363e..3889402a346 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -110,7 +110,7 @@ time = "0.1.12" unicode-segmentation = "1.1.0" url = "2.0" utf-8 = "0.7" -uuid = {version = "0.8", features = ["v4"]} +uuid = {version = "0.8", features = ["v4", "serde"]} xml5ever = "0.16" webdriver = "0.40" webgpu = {path = "../webgpu"} diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 8af14654342..067cf6cc009 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -80,6 +80,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use time::{get_time, Timespec}; +use uuid::Uuid; #[derive(JSTraceable)] pub struct AutoCloseWorker(Arc); @@ -94,7 +95,7 @@ impl Drop for AutoCloseWorker { pub struct GlobalScope { eventtarget: EventTarget, crypto: MutNullableDom, - next_worker_id: Cell, + next_worker_id: WorkerId, /// The message-port router id for this global, if it is managing ports. message_port_state: DomRefCell, @@ -347,7 +348,7 @@ impl GlobalScope { message_port_state: DomRefCell::new(MessagePortState::UnManaged), eventtarget: EventTarget::new_inherited(), crypto: Default::default(), - next_worker_id: Cell::new(WorkerId(0)), + next_worker_id: WorkerId(Uuid::new_v4().to_string()), pipeline_id, devtools_wants_updates: Default::default(), console_timers: DomRefCell::new(Default::default()), @@ -928,9 +929,7 @@ impl GlobalScope { /// Get next worker id. pub fn get_next_worker_id(&self) -> WorkerId { - let worker_id = self.next_worker_id.get(); - let WorkerId(id_num) = worker_id; - self.next_worker_id.set(WorkerId(id_num + 1)); + let worker_id = self.next_worker_id.clone(); worker_id } diff --git a/components/script/serviceworker_manager.rs b/components/script/serviceworker_manager.rs index 109628ae94e..4323ef45f59 100644 --- a/components/script/serviceworker_manager.rs +++ b/components/script/serviceworker_manager.rs @@ -98,8 +98,9 @@ impl ServiceWorkerManager { title: title, url: scope_things.script_url.clone(), }; + let worker_id = scope_things.worker_id.clone(); let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal( - (scope_things.init.pipeline_id, Some(scope_things.worker_id)), + (scope_things.init.pipeline_id, Some(worker_id)), devtools_sender, page_info, )); From d5475fbc9f4662a8a1db3a8184784ffa0ebe7fb6 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Mon, 9 Dec 2019 23:42:00 +0530 Subject: [PATCH 2/4] `WorkerId` changed to type UUID. --- Cargo.lock | 2 ++ components/devtools_traits/Cargo.toml | 1 + components/devtools_traits/lib.rs | 6 +++--- components/malloc_size_of/Cargo.toml | 1 + components/malloc_size_of/lib.rs | 4 +++- components/script/dom/globalscope.rs | 11 +---------- components/script/dom/serviceworkerregistration.rs | 4 +++- components/script/dom/worker.rs | 5 +++-- components/script/dom/workerglobalscope.rs | 3 ++- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d33fbf85da..3494d94074b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1146,6 +1146,7 @@ dependencies = [ "serde", "servo_url", "time", + "uuid", ] [[package]] @@ -3142,6 +3143,7 @@ dependencies = [ "thin-slice", "time", "url", + "uuid", "void", "webrender_api", "xml5ever", diff --git a/components/devtools_traits/Cargo.toml b/components/devtools_traits/Cargo.toml index 4750e3708fe..53287d05b33 100644 --- a/components/devtools_traits/Cargo.toml +++ b/components/devtools_traits/Cargo.toml @@ -20,3 +20,4 @@ msg = {path = "../msg"} serde = "1.0" servo_url = {path = "../url"} time = "0.1" +uuid = {version = "0.8", features = ["v4", "serde"]} diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index c71693dff40..5396d64fade 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -25,7 +25,7 @@ use msg::constellation_msg::PipelineId; use servo_url::ServoUrl; use std::net::TcpStream; use time::{self, Duration, Tm}; -//use uuid::Uuid; +use uuid::Uuid; // Information would be attached to NewGlobal to be received and show in devtools. // Extend these fields if we need more information. @@ -357,5 +357,5 @@ impl PreciseTime { } } -#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] -pub struct WorkerId(pub String); +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] +pub struct WorkerId(pub Uuid); diff --git a/components/malloc_size_of/Cargo.toml b/components/malloc_size_of/Cargo.toml index 2e112805067..faf2f460893 100644 --- a/components/malloc_size_of/Cargo.toml +++ b/components/malloc_size_of/Cargo.toml @@ -47,3 +47,4 @@ url = { version = "2.0", optional = true } webrender_api = { git = "https://github.com/servo/webrender", optional = true } xml5ever = { version = "0.16", optional = true } void = "1.0.2" +uuid = {version = "0.8", features = ["v4", "serde"]} diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 1d5cbeaff1e..520c4da4a8b 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -75,6 +75,7 @@ extern crate thin_slice; extern crate time; #[cfg(feature = "url")] extern crate url; +extern crate uuid; extern crate void; #[cfg(feature = "webrender_api")] extern crate webrender_api; @@ -90,6 +91,7 @@ use std::mem::size_of; use std::ops::Range; use std::ops::{Deref, DerefMut}; use std::os::raw::c_void; +use uuid::Uuid; use void::Void; /// A C function that takes a pointer to a heap allocation and returns its size. @@ -820,7 +822,7 @@ macro_rules! malloc_size_of_is_0( ); ); -malloc_size_of_is_0!(bool, char, str); +malloc_size_of_is_0!(bool, char, str, Uuid); malloc_size_of_is_0!(u8, u16, u32, u64, u128, usize); malloc_size_of_is_0!(i8, i16, i32, i64, i128, isize); malloc_size_of_is_0!(f32, f64); diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 067cf6cc009..080ea85dceb 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -46,7 +46,7 @@ use crate::task_source::TaskSourceName; use crate::timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle}; use crate::timers::{OneshotTimers, TimerCallback}; use content_security_policy::CspList; -use devtools_traits::{PageError, ScriptToDevtoolsControlMsg, WorkerId}; +use devtools_traits::{PageError, ScriptToDevtoolsControlMsg}; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; @@ -80,7 +80,6 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use time::{get_time, Timespec}; -use uuid::Uuid; #[derive(JSTraceable)] pub struct AutoCloseWorker(Arc); @@ -95,7 +94,6 @@ impl Drop for AutoCloseWorker { pub struct GlobalScope { eventtarget: EventTarget, crypto: MutNullableDom, - next_worker_id: WorkerId, /// The message-port router id for this global, if it is managing ports. message_port_state: DomRefCell, @@ -348,7 +346,6 @@ impl GlobalScope { message_port_state: DomRefCell::new(MessagePortState::UnManaged), eventtarget: EventTarget::new_inherited(), crypto: Default::default(), - next_worker_id: WorkerId(Uuid::new_v4().to_string()), pipeline_id, devtools_wants_updates: Default::default(), console_timers: DomRefCell::new(Default::default()), @@ -927,12 +924,6 @@ impl GlobalScope { self.crypto.or_init(|| Crypto::new(self)) } - /// Get next worker id. - pub fn get_next_worker_id(&self) -> WorkerId { - let worker_id = self.next_worker_id.clone(); - worker_id - } - pub fn live_devtools_updates(&self) -> bool { self.devtools_wants_updates.get() } diff --git a/components/script/dom/serviceworkerregistration.rs b/components/script/dom/serviceworkerregistration.rs index a2165a82115..00f65f3f2a0 100644 --- a/components/script/dom/serviceworkerregistration.rs +++ b/components/script/dom/serviceworkerregistration.rs @@ -16,10 +16,12 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::navigationpreloadmanager::NavigationPreloadManager; use crate::dom::serviceworker::ServiceWorker; use crate::dom::workerglobalscope::prepare_workerscope_init; +use devtools_traits::WorkerId; use dom_struct::dom_struct; use script_traits::{ScopeThings, WorkerScriptLoadOrigin}; use servo_url::ServoUrl; use std::cell::Cell; +use uuid::Uuid; #[dom_struct] pub struct ServiceWorkerRegistration { @@ -111,7 +113,7 @@ impl ServiceWorkerRegistration { pipeline_id: Some(global.pipeline_id()), }; - let worker_id = global.get_next_worker_id(); + let worker_id = WorkerId(Uuid::new_v4()); let devtools_chan = global.devtools_chan().cloned(); let init = prepare_workerscope_init(&global, None); ScopeThings { diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index f08bdcab79e..9cec5edf72d 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -26,7 +26,7 @@ use crate::dom::workerglobalscope::prepare_workerscope_init; use crate::script_runtime::JSContext; use crate::task::TaskOnce; use crossbeam_channel::{unbounded, Sender}; -use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; +use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg, WorkerId}; use dom_struct::dom_struct; use ipc_channel::ipc; use js::jsapi::{Heap, JSObject, JS_RequestInterruptCallback}; @@ -36,6 +36,7 @@ use script_traits::{StructuredSerializedData, WorkerScriptLoadOrigin}; use std::cell::Cell; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use uuid::Uuid; pub type TrustedWorkerAddress = Trusted; @@ -100,7 +101,7 @@ impl Worker { }; let (devtools_sender, devtools_receiver) = ipc::channel().unwrap(); - let worker_id = global.get_next_worker_id(); + let worker_id = WorkerId(Uuid::new_v4()); if let Some(ref chan) = global.devtools_chan() { let pipeline_id = global.pipeline_id(); let title = format!("Worker for {}", worker_url); diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index e943b6b0ef4..8624208423e 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -58,6 +58,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use time::precise_time_ns; +use uuid::Uuid; pub fn prepare_workerscope_init( global: &GlobalScope, @@ -71,7 +72,7 @@ pub fn prepare_workerscope_init( from_devtools_sender: devtools_sender, script_to_constellation_chan: global.script_to_constellation_chan().clone(), scheduler_chan: global.scheduler_chan().clone(), - worker_id: global.get_next_worker_id(), + worker_id: WorkerId(Uuid::new_v4()), pipeline_id: global.pipeline_id(), origin: global.origin().immutable().clone(), is_headless: global.is_headless(), From d60f7d87c8145eb0b573e5a9b0108532aab47dc8 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Tue, 10 Dec 2019 13:09:45 +0530 Subject: [PATCH 3/4] Undo changes done to change worker_id type to string --- components/devtools/lib.rs | 2 +- components/script/serviceworker_manager.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index cc37ed7c4b0..63e4c7aea15 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -307,7 +307,7 @@ fn run_server( let worker = WorkerActor { name: actors.new_name("worker"), console: console.name(), - id: id.clone(), + id: id, }; actor_workers.insert((pipeline, id), worker.name.clone()); actors.register(Box::new(worker)); diff --git a/components/script/serviceworker_manager.rs b/components/script/serviceworker_manager.rs index 4323ef45f59..109628ae94e 100644 --- a/components/script/serviceworker_manager.rs +++ b/components/script/serviceworker_manager.rs @@ -98,9 +98,8 @@ impl ServiceWorkerManager { title: title, url: scope_things.script_url.clone(), }; - let worker_id = scope_things.worker_id.clone(); let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal( - (scope_things.init.pipeline_id, Some(worker_id)), + (scope_things.init.pipeline_id, Some(scope_things.worker_id)), devtools_sender, page_info, )); From a892102d4648a3e43bd458c3e106f241444ffc1f Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Tue, 10 Dec 2019 21:31:27 +0530 Subject: [PATCH 4/4] Make uuid optional and hide it behind servo feature in malloc_size_of --- components/malloc_size_of/Cargo.toml | 3 ++- components/malloc_size_of/lib.rs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/malloc_size_of/Cargo.toml b/components/malloc_size_of/Cargo.toml index faf2f460893..d2068a30e9b 100644 --- a/components/malloc_size_of/Cargo.toml +++ b/components/malloc_size_of/Cargo.toml @@ -22,6 +22,7 @@ servo = [ "webrender_api", "xml5ever", "content-security-policy", + "uuid" ] [dependencies] @@ -47,4 +48,4 @@ url = { version = "2.0", optional = true } webrender_api = { git = "https://github.com/servo/webrender", optional = true } xml5ever = { version = "0.16", optional = true } void = "1.0.2" -uuid = {version = "0.8", features = ["v4", "serde"]} +uuid = {version = "0.8", features = ["v4"], optional = true} diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 520c4da4a8b..8593ccc3622 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -75,6 +75,7 @@ extern crate thin_slice; extern crate time; #[cfg(feature = "url")] extern crate url; +#[cfg(feature = "servo")] extern crate uuid; extern crate void; #[cfg(feature = "webrender_api")] @@ -91,6 +92,7 @@ use std::mem::size_of; use std::ops::Range; use std::ops::{Deref, DerefMut}; use std::os::raw::c_void; +#[cfg(feature = "servo")] use uuid::Uuid; use void::Void; @@ -822,7 +824,7 @@ macro_rules! malloc_size_of_is_0( ); ); -malloc_size_of_is_0!(bool, char, str, Uuid); +malloc_size_of_is_0!(bool, char, str); malloc_size_of_is_0!(u8, u16, u32, u64, u128, usize); malloc_size_of_is_0!(i8, i16, i32, i64, i128, isize); malloc_size_of_is_0!(f32, f64); @@ -842,6 +844,9 @@ malloc_size_of_is_0!(cssparser::RGBA, cssparser::TokenSerializationType); #[cfg(feature = "servo")] malloc_size_of_is_0!(csp::Destination); +#[cfg(feature = "servo")] +malloc_size_of_is_0!(Uuid); + #[cfg(feature = "url")] impl MallocSizeOf for url::Host { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {