Auto merge of #25211 - kunalmohan:6631-Worker-Id, r=jdm

`worker_id` type changed to uuid

<!-- Please describe your changes on the following line: -->
Fixes #6631
`worker_id` is now generate as uuid and saved as string.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #6631  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2019-12-16 11:31:44 -05:00 committed by GitHub
commit c9baa5b9fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 24 additions and 17 deletions

2
Cargo.lock generated
View file

@ -1144,6 +1144,7 @@ dependencies = [
"serde",
"servo_url",
"time",
"uuid",
]
[[package]]
@ -3141,6 +3142,7 @@ dependencies = [
"thin-slice",
"time",
"url",
"uuid",
"void",
"webrender_api",
"xml5ever",

View file

@ -20,3 +20,4 @@ msg = {path = "../msg"}
serde = "1.0"
servo_url = {path = "../url"}
time = "0.1"
uuid = {version = "0.8", features = ["v4", "serde"]}

View file

@ -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.
@ -357,4 +358,4 @@ impl PreciseTime {
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
pub struct WorkerId(pub u32);
pub struct WorkerId(pub Uuid);

View file

@ -22,6 +22,7 @@ servo = [
"webrender_api",
"xml5ever",
"content-security-policy",
"uuid"
]
[dependencies]
@ -47,3 +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"], optional = true}

View file

@ -75,6 +75,8 @@ 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")]
extern crate webrender_api;
@ -90,6 +92,8 @@ 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;
/// A C function that takes a pointer to a heap allocation and returns its size.
@ -840,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 {

View file

@ -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"}

View file

@ -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;
@ -94,7 +94,6 @@ impl Drop for AutoCloseWorker {
pub struct GlobalScope {
eventtarget: EventTarget,
crypto: MutNullableDom<Crypto>,
next_worker_id: Cell<WorkerId>,
/// The message-port router id for this global, if it is managing ports.
message_port_state: DomRefCell<MessagePortState>,
@ -347,7 +346,6 @@ impl GlobalScope {
message_port_state: DomRefCell::new(MessagePortState::UnManaged),
eventtarget: EventTarget::new_inherited(),
crypto: Default::default(),
next_worker_id: Cell::new(WorkerId(0)),
pipeline_id,
devtools_wants_updates: Default::default(),
console_timers: DomRefCell::new(Default::default()),
@ -926,14 +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.get();
let WorkerId(id_num) = worker_id;
self.next_worker_id.set(WorkerId(id_num + 1));
worker_id
}
pub fn live_devtools_updates(&self) -> bool {
self.devtools_wants_updates.get()
}

View file

@ -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 {

View file

@ -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<Worker>;
@ -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);

View file

@ -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(),