Auto merge of #10868 - frewsxcv:loadcancelled, r=Ms2ger

Add `NetworkError::LoadCancelled` variant.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10868)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-27 01:26:05 -07:00
commit ad77d40360
5 changed files with 7 additions and 7 deletions

View file

@ -400,4 +400,3 @@ pub enum ReferrerPolicy {
OriginWhenCrossOrigin, OriginWhenCrossOrigin,
UnsafeUrl, UnsafeUrl,
} }

View file

@ -50,7 +50,7 @@ fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener:
ReadStatus::EOF => return Ok(LoadResult::Finished), ReadStatus::EOF => return Ok(LoadResult::Finished),
} }
} }
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned())))); let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
Ok(LoadResult::Cancelled) Ok(LoadResult::Cancelled)
} }
@ -92,7 +92,7 @@ pub fn factory(load_data: LoadData,
if cancel_listener.is_cancelled() { if cancel_listener.is_cancelled() {
if let Ok(progress_chan) = get_progress_chan(load_data, file_path, if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
senders, classifier, &[]) { senders, classifier, &[]) {
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned())))); let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
} }
return; return;
} }

View file

@ -160,6 +160,7 @@ fn load_for_consumer(load_data: LoadData,
LoadErrorType::Ssl { .. } => send_error(error.url.clone(), LoadErrorType::Ssl { .. } => send_error(error.url.clone(),
NetworkError::SslValidation(error.url), NetworkError::SslValidation(error.url),
start_chan), start_chan),
LoadErrorType::Cancelled => send_error(error.url, NetworkError::LoadCancelled, start_chan),
_ => send_error(error.url, NetworkError::Internal(error.error.description().to_owned()), start_chan) _ => send_error(error.url, NetworkError::Internal(error.error.description().to_owned()), start_chan)
} }
} }
@ -983,7 +984,7 @@ fn send_data<R: Read>(context: LoadContext,
loop { loop {
if cancel_listener.is_cancelled() { if cancel_listener.is_cancelled() {
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned())))); let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
return; return;
} }

View file

@ -437,9 +437,9 @@ pub enum ConstellationMsg {
/// Network errors that have to be exported out of the loaders /// Network errors that have to be exported out of the loaders
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, HeapSizeOf)] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, HeapSizeOf)]
pub enum NetworkError { pub enum NetworkError {
/// Could be any of the internal errors, like unsupported scheme, load /// Could be any of the internal errors, like unsupported scheme, connection errors, etc.
/// cancellation, connection errors, etc.
Internal(String), Internal(String),
LoadCancelled,
/// SSL validation error that has to be handled in the HTML parser /// SSL validation error that has to be handled in the HTML parser
SslValidation(Url), SslValidation(Url),
} }

View file

@ -220,6 +220,6 @@ fn test_cancelled_listener() {
let _ = body_sender.send(body); let _ = body_sender.send(body);
let response = receiver.recv().unwrap(); let response = receiver.recv().unwrap();
assert_eq!(response.progress_port.recv().unwrap(), assert_eq!(response.progress_port.recv().unwrap(),
ProgressMsg::Done(Err(NetworkError::Internal("load cancelled".to_owned())))); ProgressMsg::Done(Err(NetworkError::LoadCancelled)));
resource_thread.send(ControlMsg::Exit).unwrap(); resource_thread.send(ControlMsg::Exit).unwrap();
} }