Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify fetching code. #13571

Merged
merged 6 commits into from Oct 4, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Refactor away PendingAsyncLoad.

  • Loading branch information
Ms2ger committed Oct 4, 2016
commit 86fdab2edc366e4c3a71b14f414a3123c6521c47
@@ -44,7 +44,6 @@ use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use request::{Request, RequestInit};
use response::{HttpsState, Response};
use std::io::Error as IOError;
use std::thread;
use storage_thread::StorageThreadMsg;
use url::Url;
use websocket::header;
@@ -467,35 +466,13 @@ pub enum CoreResourceMsg {
/// Initialized but unsent request. Encapsulates everything necessary to instruct
/// the resource thread to make a new request. The `load` method *must* be called before
/// destruction or the thread will panic.

This comment has been minimized.

@jdm

jdm Oct 4, 2016

Member

This comment no longer applies.

struct PendingAsyncLoad {
core_resource_thread: CoreResourceThread,
url: Url,
struct LoadOriginData {
pipeline: Option<PipelineId>,
guard: PendingLoadGuard,
context: LoadContext,
referrer_policy: Option<ReferrerPolicy>,
referrer_url: Option<Url>
}

struct PendingLoadGuard {
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 {
impl LoadOrigin for LoadOriginData {
fn referrer_url(&self) -> Option<Url> {
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.
pub fn load_async(context: LoadContext,
core_resource_thread: CoreResourceThread,
@@ -546,13 +492,14 @@ pub fn load_async(context: LoadContext,
referrer_policy: Option<ReferrerPolicy>,
referrer_url: Option<Url>,
listener: AsyncResponseTarget) {
let load = PendingAsyncLoad::new(context,
core_resource_thread,
url,
pipeline,
referrer_policy,
referrer_url);
load.load_async(listener);
let load = LoadOriginData {
pipeline: pipeline,
referrer_policy: referrer_policy,
referrer_url: referrer_url
};
let load_data = LoadData::new(context, url, &load);
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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.