mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
create uuid before sending PromoteMemory message
This commit is contained in:
parent
34fda66dfa
commit
d9beca6fec
4 changed files with 20 additions and 56 deletions
|
@ -126,20 +126,8 @@ impl FileManager {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn promote_memory(
|
pub fn promote_memory(&self, id: Uuid, blob_buf: BlobBuf, set_valid: bool, origin: FileOrigin) {
|
||||||
&self,
|
self.store.promote_memory(id, blob_buf, set_valid, origin);
|
||||||
blob_buf: BlobBuf,
|
|
||||||
set_valid: bool,
|
|
||||||
sender: IpcSender<Result<Uuid, BlobURLStoreError>>,
|
|
||||||
origin: FileOrigin,
|
|
||||||
) {
|
|
||||||
let store = self.store.clone();
|
|
||||||
thread::Builder::new()
|
|
||||||
.name("transfer memory".to_owned())
|
|
||||||
.spawn(move || {
|
|
||||||
store.promote_memory(blob_buf, set_valid, sender, origin);
|
|
||||||
})
|
|
||||||
.expect("Thread spawning failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Message handler
|
/// Message handler
|
||||||
|
@ -168,8 +156,8 @@ impl FileManager {
|
||||||
FileManagerThreadMsg::ReadFile(sender, id, check_url_validity, origin) => {
|
FileManagerThreadMsg::ReadFile(sender, id, check_url_validity, origin) => {
|
||||||
self.read_file(sender, id, check_url_validity, origin);
|
self.read_file(sender, id, check_url_validity, origin);
|
||||||
},
|
},
|
||||||
FileManagerThreadMsg::PromoteMemory(blob_buf, set_valid, sender, origin) => {
|
FileManagerThreadMsg::PromoteMemory(id, blob_buf, set_valid, origin) => {
|
||||||
self.promote_memory(blob_buf, set_valid, sender, origin);
|
self.promote_memory(id, blob_buf, set_valid, origin);
|
||||||
},
|
},
|
||||||
FileManagerThreadMsg::AddSlicedURLEntry(id, rel_pos, sender, origin) => {
|
FileManagerThreadMsg::AddSlicedURLEntry(id, rel_pos, sender, origin) => {
|
||||||
self.store.add_sliced_url_entry(id, rel_pos, sender, origin);
|
self.store.add_sliced_url_entry(id, rel_pos, sender, origin);
|
||||||
|
@ -667,17 +655,10 @@ impl FileManagerStore {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn promote_memory(
|
fn promote_memory(&self, id: Uuid, blob_buf: BlobBuf, set_valid: bool, origin: FileOrigin) {
|
||||||
&self,
|
|
||||||
blob_buf: BlobBuf,
|
|
||||||
set_valid: bool,
|
|
||||||
sender: IpcSender<Result<Uuid, BlobURLStoreError>>,
|
|
||||||
origin: FileOrigin,
|
|
||||||
) {
|
|
||||||
match Url::parse(&origin) {
|
match Url::parse(&origin) {
|
||||||
// parse to check sanity
|
// parse to check sanity
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let id = Uuid::new_v4();
|
|
||||||
self.insert(
|
self.insert(
|
||||||
id,
|
id,
|
||||||
FileStoreEntry {
|
FileStoreEntry {
|
||||||
|
@ -687,12 +668,8 @@ impl FileManagerStore {
|
||||||
is_valid_url: AtomicBool::new(set_valid),
|
is_valid_url: AtomicBool::new(set_valid),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = sender.send(Ok(id));
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
let _ = sender.send(Err(BlobURLStoreError::InvalidOrigin));
|
|
||||||
},
|
},
|
||||||
|
Err(_) => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
// TODO write a struct that impls Handler for storing test values
|
// TODO write a struct that impls Handler for storing test values
|
||||||
|
|
||||||
|
@ -125,7 +126,6 @@ fn test_fetch_aboutblank() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fetch_blob() {
|
fn test_fetch_blob() {
|
||||||
use ipc_channel::ipc;
|
|
||||||
use net_traits::blob_url_store::BlobBuf;
|
use net_traits::blob_url_store::BlobBuf;
|
||||||
|
|
||||||
struct FetchResponseCollector {
|
struct FetchResponseCollector {
|
||||||
|
@ -160,11 +160,10 @@ fn test_fetch_blob() {
|
||||||
|
|
||||||
let origin = ServoUrl::parse("http://www.example.org/").unwrap();
|
let origin = ServoUrl::parse("http://www.example.org/").unwrap();
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let id = Uuid::new_v4();
|
||||||
context
|
context
|
||||||
.filemanager
|
.filemanager
|
||||||
.promote_memory(blob_buf, true, sender, "http://www.example.org".into());
|
.promote_memory(id.clone(), blob_buf, true, "http://www.example.org".into());
|
||||||
let id = receiver.recv().unwrap().unwrap();
|
|
||||||
let url = ServoUrl::parse(&format!("blob:{}{}", origin.as_str(), id.to_simple())).unwrap();
|
let url = ServoUrl::parse(&format!("blob:{}{}", origin.as_str(), id.to_simple())).unwrap();
|
||||||
|
|
||||||
let mut request = Request::new(url, Some(Origin::Origin(origin.origin())), None);
|
let mut request = Request::new(url, Some(Origin::Origin(origin.origin())), None);
|
||||||
|
|
|
@ -137,14 +137,8 @@ pub enum FileManagerThreadMsg {
|
||||||
FileOrigin,
|
FileOrigin,
|
||||||
),
|
),
|
||||||
|
|
||||||
/// Add an entry as promoted memory-based blob and send back the associated FileID
|
/// Add an entry as promoted memory-based blob
|
||||||
/// as part of a valid/invalid Blob URL depending on the boolean flag
|
PromoteMemory(Uuid, BlobBuf, bool, FileOrigin),
|
||||||
PromoteMemory(
|
|
||||||
BlobBuf,
|
|
||||||
bool,
|
|
||||||
IpcSender<Result<Uuid, BlobURLStoreError>>,
|
|
||||||
FileOrigin,
|
|
||||||
),
|
|
||||||
|
|
||||||
/// Add a sliced entry pointing to the parent FileID, and send back the associated FileID
|
/// Add a sliced entry pointing to the parent FileID, and send back the associated FileID
|
||||||
/// as part of a valid Blob URL
|
/// as part of a valid Blob URL
|
||||||
|
|
|
@ -238,23 +238,17 @@ impl Blob {
|
||||||
bytes: bytes.to_vec(),
|
bytes: bytes.to_vec(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (tx, rx) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
let id = Uuid::new_v4();
|
||||||
let msg = FileManagerThreadMsg::PromoteMemory(blob_buf, set_valid, tx, origin.clone());
|
let msg = FileManagerThreadMsg::PromoteMemory(id, blob_buf, set_valid, origin.clone());
|
||||||
self.send_to_file_manager(msg);
|
self.send_to_file_manager(msg);
|
||||||
|
|
||||||
match rx.recv().unwrap() {
|
*self.blob_impl.borrow_mut() = BlobImpl::File(FileBlob {
|
||||||
Ok(id) => {
|
id: id.clone(),
|
||||||
*self.blob_impl.borrow_mut() = BlobImpl::File(FileBlob {
|
name: None,
|
||||||
id: id.clone(),
|
cache: DomRefCell::new(Some(bytes.to_vec())),
|
||||||
name: None,
|
size: bytes.len() as u64,
|
||||||
cache: DomRefCell::new(Some(bytes.to_vec())),
|
});
|
||||||
size: bytes.len() as u64,
|
id
|
||||||
});
|
|
||||||
id
|
|
||||||
},
|
|
||||||
// Dummy id
|
|
||||||
Err(_) => Uuid::new_v4(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a FileID representing sliced parent-blob content
|
/// Get a FileID representing sliced parent-blob content
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue