servo: Merge #10868 - Add `NetworkError::LoadCancelled` variant (from frewsxcv:loadcancelled); r=Ms2ger
authorCorey Farwell <coreyf@rwell.org>
Wed, 27 Apr 2016 01:26:05 -0700
changeset 338640 b087ea82eba19cfc2a1ff519565aa965b256716e
parent 338639 d4b4439e3b7cc40f39946c82be076b3638078949
child 338641 f9e07407a68c9a523c6cf27dcc10aa93a45ff73a
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #10868 - Add `NetworkError::LoadCancelled` variant (from frewsxcv:loadcancelled); r=Ms2ger Source-Repo: https://github.com/servo/servo Source-Revision: ad77d40360f4ccb0a1249d86e5a48357f74295ea
servo/components/msg/constellation_msg.rs
servo/components/net/file_loader.rs
servo/components/net/http_loader.rs
servo/components/net_traits/lib.rs
servo/tests/unit/net/resource_thread.rs
--- a/servo/components/msg/constellation_msg.rs
+++ b/servo/components/msg/constellation_msg.rs
@@ -395,9 +395,8 @@ impl ConvertPipelineIdFromWebRender for 
 #[derive(HeapSizeOf, Clone, Deserialize, Serialize)]
 pub enum ReferrerPolicy {
     NoReferrer,
     NoRefWhenDowngrade,
     OriginOnly,
     OriginWhenCrossOrigin,
     UnsafeUrl,
 }
-
--- a/servo/components/net/file_loader.rs
+++ b/servo/components/net/file_loader.rs
@@ -45,17 +45,17 @@ fn read_block(reader: &mut File) -> Resu
 fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener: &CancellationListener)
             -> Result<LoadResult, String> {
     while !cancel_listener.is_cancelled() {
         match try!(read_block(reader)) {
             ReadStatus::Partial(buf) => progress_chan.send(Payload(buf)).unwrap(),
             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)
 }
 
 fn get_progress_chan(load_data: LoadData, file_path: PathBuf,
                      senders: LoadConsumer, classifier: Arc<MIMEClassifier>, buf: &[u8])
                      -> Result<ProgressSender, ()> {
     let mut metadata = Metadata::default(load_data.url);
     let mime_type = guess_mime_type(file_path.as_path());
@@ -87,17 +87,17 @@ pub fn factory(load_data: LoadData,
                 let load_data_404 = LoadData::new(load_data.context, url, None, None, None);
                 about_loader::factory(load_data_404, senders, classifier, cancel_listener);
                 return;
             }
         };
         if cancel_listener.is_cancelled() {
             if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
                                                          senders, classifier, &[]) {
-                let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
+                let _ = progress_chan.send(Done(Err(NetworkError::LoadCancelled)));
             }
             return;
         }
         match read_block(reader) {
             Ok(ReadStatus::Partial(buf)) => {
                 let progress_chan = get_progress_chan(load_data, file_path,
                                                       senders, classifier, &buf).ok().unwrap();
                 progress_chan.send(Payload(buf)).unwrap();
--- a/servo/components/net/http_loader.rs
+++ b/servo/components/net/http_loader.rs
@@ -155,16 +155,17 @@ fn load_for_consumer(load_data: LoadData
                devtools_chan, &factory,
                user_agent, &cancel_listener) {
         Err(error) => {
             match error.error {
                 LoadErrorType::ConnectionAborted { .. } => unreachable!(),
                 LoadErrorType::Ssl { .. } => send_error(error.url.clone(),
                                                         NetworkError::SslValidation(error.url),
                                                         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)
             }
         }
         Ok(mut load_response) => {
             let metadata = load_response.metadata.clone();
             send_data(load_data.context, &mut load_response, start_chan, metadata, classifier, &cancel_listener)
         }
     }
@@ -978,17 +979,17 @@ fn send_data<R: Read>(context: LoadConte
             Ok(p) => p,
             _ => return
         };
         (p, buf)
     };
 
     loop {
         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;
         }
 
         if progress_chan.send(Payload(chunk)).is_err() {
             // The send errors when the receiver is out of scope,
             // which will happen if the fetch has timed out (or has been aborted)
             // so we don't need to continue with the loading of the file here.
             return;
--- a/servo/components/net_traits/lib.rs
+++ b/servo/components/net_traits/lib.rs
@@ -432,14 +432,14 @@ pub struct ResourceId(pub u32);
 pub enum ConstellationMsg {
     /// Queries whether a pipeline or its ancestors are private
     IsPrivate(PipelineId, Sender<bool>),
 }
 
 /// Network errors that have to be exported out of the loaders
 #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, HeapSizeOf)]
 pub enum NetworkError {
-    /// Could be any of the internal errors, like unsupported scheme, load
-    /// cancellation, connection errors, etc.
+    /// Could be any of the internal errors, like unsupported scheme, connection errors, etc.
     Internal(String),
+    LoadCancelled,
     /// SSL validation error that has to be handled in the HTML parser
     SslValidation(Url),
 }
--- a/servo/tests/unit/net/resource_thread.rs
+++ b/servo/tests/unit/net/resource_thread.rs
@@ -215,11 +215,11 @@ fn test_cancelled_listener() {
     // synchronize with the resource_thread loop, so that we don't simply send everything at once!
     resource_thread.send(ControlMsg::Synchronize(sync_sender)).unwrap();
     let _ = sync_receiver.recv();
     // now, let's send the body, because the connection is still active and data would be loaded
     // (but, the loading has been cancelled)
     let _ = body_sender.send(body);
     let response = receiver.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();
 }