Skip to content
Permalink
Browse files

Rustfmt the constellation

  • Loading branch information
cbrewster committed Jul 21, 2018
1 parent a97d8b9 commit a2064cef28a5d5695149a7c3f79d45820d580112
@@ -34,11 +34,11 @@ pub struct BrowsingContext {
impl BrowsingContext {
/// Create a new browsing context.
/// Note this just creates the browsing context, it doesn't add it to the constellation's set of browsing contexts.
pub fn new(id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId,
pipeline_id: PipelineId)
-> BrowsingContext
{
pub fn new(
id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId,
pipeline_id: PipelineId,
) -> BrowsingContext {
let mut pipelines = HashSet::new();
pipelines.insert(pipeline_id);
BrowsingContext {
@@ -84,19 +84,25 @@ impl<'a> Iterator for FullyActiveBrowsingContextsIterator<'a> {
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context,
None => {
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id);
warn!(
"BrowsingContext {:?} iterated after closure.",
browsing_context_id
);
continue;
},
};
let pipeline = match self.pipelines.get(&browsing_context.pipeline_id) {
Some(pipeline) => pipeline,
None => {
warn!("Pipeline {:?} iterated after closure.", browsing_context.pipeline_id);
warn!(
"Pipeline {:?} iterated after closure.",
browsing_context.pipeline_id
);
continue;
},
};
self.stack.extend(pipeline.children.iter());
return Some(browsing_context)
return Some(browsing_context);
}
}
}
@@ -126,15 +132,20 @@ impl<'a> Iterator for AllBrowsingContextsIterator<'a> {
let browsing_context = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context,
None => {
warn!("BrowsingContext {:?} iterated after closure.", browsing_context_id);
warn!(
"BrowsingContext {:?} iterated after closure.",
browsing_context_id
);
continue;
},
};
let child_browsing_context_ids = browsing_context.pipelines.iter()
let child_browsing_context_ids = browsing_context
.pipelines
.iter()
.filter_map(|pipeline_id| pipelines.get(&pipeline_id))
.flat_map(|pipeline| pipeline.children.iter());
self.stack.extend(child_browsing_context_ids);
return Some(browsing_context)
return Some(browsing_context);
}
}
}

Large diffs are not rendered by default.

@@ -20,7 +20,9 @@ pub struct EventLoop {

impl Drop for EventLoop {
fn drop(&mut self) {
let _ = self.script_chan.send(ConstellationControlMsg::ExitScriptThread);
let _ = self
.script_chan
.send(ConstellationControlMsg::ExitScriptThread);
}
}

@@ -43,4 +45,3 @@ impl EventLoop {
self.script_chan.clone()
}
}

@@ -32,7 +32,8 @@ extern crate net;
extern crate net_traits;
extern crate profile_traits;
extern crate script_traits;
#[macro_use] extern crate serde;
#[macro_use]
extern crate serde;
extern crate servo_config;
extern crate servo_rand;
extern crate servo_remutex;
@@ -27,17 +27,19 @@ pub struct NetworkListener {
}

impl NetworkListener {
pub fn new(req_init: RequestInit,
pipeline_id: PipelineId,
resource_threads: ResourceThreads,
sender: Sender<(PipelineId, FetchResponseMsg)>) -> NetworkListener {
pub fn new(
req_init: RequestInit,
pipeline_id: PipelineId,
resource_threads: ResourceThreads,
sender: Sender<(PipelineId, FetchResponseMsg)>,
) -> NetworkListener {
NetworkListener {
res_init: None,
req_init,
pipeline_id,
resource_threads,
sender,
should_send: false
should_send: false,
}
}

@@ -55,35 +57,40 @@ impl NetworkListener {

let msg = match self.res_init {
Some(ref res_init_) => CoreResourceMsg::FetchRedirect(
self.req_init.clone(),
res_init_.clone(),
ipc_sender, None),
self.req_init.clone(),
res_init_.clone(),
ipc_sender,
None,
),
None => {
set_default_accept(Destination::Document, &mut listener.req_init.headers);
set_default_accept_language(&mut listener.req_init.headers);

CoreResourceMsg::Fetch(
listener.req_init.clone(),
FetchChannels::ResponseMsg(ipc_sender, cancel_chan))
}
listener.req_init.clone(),
FetchChannels::ResponseMsg(ipc_sender, cancel_chan),
)
},
};

ROUTER.add_route(ipc_receiver.to_opaque(), Box::new(move |message| {
let msg = message.to();
match msg {
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
Ok(msg_) => listener.send(msg_),
Err(e) => warn!("Error while receiving network listener message: {}", e),
};
}));
ROUTER.add_route(
ipc_receiver.to_opaque(),
Box::new(move |message| {
let msg = message.to();
match msg {
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
Ok(msg_) => listener.send(msg_),
Err(e) => warn!("Error while receiving network listener message: {}", e),
};
}),
);

if let Err(e) = self.resource_threads.sender().send(msg) {
warn!("Resource thread unavailable ({})", e);
}
}

fn check_redirect(&mut self,
message: Result<(FetchMetadata), NetworkError>) {
fn check_redirect(&mut self, message: Result<(FetchMetadata), NetworkError>) {
match message {
Ok(res_metadata) => {
let metadata = match res_metadata {
@@ -118,20 +125,23 @@ impl NetworkListener {
// Response should be processed by script thread.
self.should_send = true;
self.send(FetchResponseMsg::ProcessResponse(Ok(res_metadata.clone())));
}
},
};
},
Err(e) => {
self.should_send = true;
self.send(FetchResponseMsg::ProcessResponse(Err(e)))
}
},
};
}

fn send(&mut self, msg: FetchResponseMsg) {
if self.should_send {
if let Err(e) = self.sender.send((self.pipeline_id, msg)) {
warn!("Failed to forward network message to pipeline {}: {:?}", self.pipeline_id, e);
warn!(
"Failed to forward network message to pipeline {}: {:?}",
self.pipeline_id, e
);
}
}
}

0 comments on commit a2064ce

Please sign in to comment.
You can’t perform that action at this time.