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

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