mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Refactor away PendingAsyncLoad.
This commit is contained in:
parent
1a2db0b327
commit
86fdab2edc
1 changed files with 10 additions and 63 deletions
|
@ -44,7 +44,6 @@ use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||||
use request::{Request, RequestInit};
|
use request::{Request, RequestInit};
|
||||||
use response::{HttpsState, Response};
|
use response::{HttpsState, Response};
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
use std::thread;
|
|
||||||
use storage_thread::StorageThreadMsg;
|
use storage_thread::StorageThreadMsg;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use websocket::header;
|
use websocket::header;
|
||||||
|
@ -467,35 +466,13 @@ pub enum CoreResourceMsg {
|
||||||
/// Initialized but unsent request. Encapsulates everything necessary to instruct
|
/// Initialized but unsent request. Encapsulates everything necessary to instruct
|
||||||
/// the resource thread to make a new request. The `load` method *must* be called before
|
/// the resource thread to make a new request. The `load` method *must* be called before
|
||||||
/// destruction or the thread will panic.
|
/// destruction or the thread will panic.
|
||||||
struct PendingAsyncLoad {
|
struct LoadOriginData {
|
||||||
core_resource_thread: CoreResourceThread,
|
|
||||||
url: Url,
|
|
||||||
pipeline: Option<PipelineId>,
|
pipeline: Option<PipelineId>,
|
||||||
guard: PendingLoadGuard,
|
|
||||||
context: LoadContext,
|
|
||||||
referrer_policy: Option<ReferrerPolicy>,
|
referrer_policy: Option<ReferrerPolicy>,
|
||||||
referrer_url: Option<Url>
|
referrer_url: Option<Url>
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PendingLoadGuard {
|
impl LoadOrigin for LoadOriginData {
|
||||||
loaded: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PendingLoadGuard {
|
|
||||||
fn neuter(&mut self) {
|
|
||||||
self.loaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for PendingLoadGuard {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if !thread::panicking() {
|
|
||||||
assert!(self.loaded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LoadOrigin for PendingAsyncLoad {
|
|
||||||
fn referrer_url(&self) -> Option<Url> {
|
fn referrer_url(&self) -> Option<Url> {
|
||||||
self.referrer_url.clone()
|
self.referrer_url.clone()
|
||||||
}
|
}
|
||||||
|
@ -507,37 +484,6 @@ impl LoadOrigin for PendingAsyncLoad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PendingAsyncLoad {
|
|
||||||
fn new(context: LoadContext,
|
|
||||||
core_resource_thread: CoreResourceThread,
|
|
||||||
url: Url,
|
|
||||||
pipeline: Option<PipelineId>,
|
|
||||||
referrer_policy: Option<ReferrerPolicy>,
|
|
||||||
referrer_url: Option<Url>)
|
|
||||||
-> PendingAsyncLoad {
|
|
||||||
PendingAsyncLoad {
|
|
||||||
core_resource_thread: core_resource_thread,
|
|
||||||
url: url,
|
|
||||||
pipeline: pipeline,
|
|
||||||
guard: PendingLoadGuard { loaded: false, },
|
|
||||||
context: context,
|
|
||||||
referrer_policy: referrer_policy,
|
|
||||||
referrer_url: referrer_url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initiate the network request associated with this pending load, using the provided target.
|
|
||||||
fn load_async(mut self, listener: AsyncResponseTarget) {
|
|
||||||
self.guard.neuter();
|
|
||||||
|
|
||||||
let load_data = LoadData::new(self.context.clone(),
|
|
||||||
self.url.clone(),
|
|
||||||
&self);
|
|
||||||
let consumer = LoadConsumer::Listener(listener);
|
|
||||||
self.core_resource_thread.send(CoreResourceMsg::Load(load_data, consumer, None)).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Instruct the resource thread to make a new request.
|
/// Instruct the resource thread to make a new request.
|
||||||
pub fn load_async(context: LoadContext,
|
pub fn load_async(context: LoadContext,
|
||||||
core_resource_thread: CoreResourceThread,
|
core_resource_thread: CoreResourceThread,
|
||||||
|
@ -546,13 +492,14 @@ pub fn load_async(context: LoadContext,
|
||||||
referrer_policy: Option<ReferrerPolicy>,
|
referrer_policy: Option<ReferrerPolicy>,
|
||||||
referrer_url: Option<Url>,
|
referrer_url: Option<Url>,
|
||||||
listener: AsyncResponseTarget) {
|
listener: AsyncResponseTarget) {
|
||||||
let load = PendingAsyncLoad::new(context,
|
let load = LoadOriginData {
|
||||||
core_resource_thread,
|
pipeline: pipeline,
|
||||||
url,
|
referrer_policy: referrer_policy,
|
||||||
pipeline,
|
referrer_url: referrer_url
|
||||||
referrer_policy,
|
};
|
||||||
referrer_url);
|
let load_data = LoadData::new(context, url, &load);
|
||||||
load.load_async(listener);
|
let consumer = LoadConsumer::Listener(listener);
|
||||||
|
core_resource_thread.send(CoreResourceMsg::Load(load_data, consumer, None)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Message sent in response to `Load`. Contains metadata, and a port
|
/// Message sent in response to `Load`. Contains metadata, and a port
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue