servo: Merge #14586 - Remove-ResponseAction (from deror1869107:Remove-ResponseAction); r=jdm
authorderor1869107 <sungyuanyao@gmail.com>
Wed, 14 Dec 2016 20:34:01 -0800
changeset 340345 7c4bad74fb17f3a35542979223de3ca59f1dcb76
parent 340344 f3078fb59bf35db25822eb2acef693b6717d7967
child 340346 ab82f5bf49fdc10831e577ccddd8aa5632a32f11
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)
reviewersjdm
servo: Merge #14586 - Remove-ResponseAction (from deror1869107:Remove-ResponseAction); r=jdm <!-- Please describe your changes on the following line: --> Remove the old Enum ResponseAction and use net_traits::FetchResponseMsg instead. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13717 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because @KiChjang said so. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: fde9ac176887f802fe38da114c1bca9ac660769e
servo/components/net/image_cache_thread.rs
--- a/servo/components/net/image_cache_thread.rs
+++ b/servo/components/net/image_cache_thread.rs
@@ -220,27 +220,18 @@ impl ImageListener {
         let msg = ImageCacheResult {
             responder: self.responder.clone(),
             image_response: image_response,
         };
         sender.send(msg).ok();
     }
 }
 
-/// A legacy type that's mostly redundant with FetchResponseMsg.
-// FIXME(#13717): remove this type.
-#[derive(Deserialize, Serialize)]
-enum ResponseAction {
-    HeadersAvailable(Result<Metadata, NetworkError>),
-    DataAvailable(Vec<u8>),
-    ResponseComplete(Result<(), NetworkError>)
-}
-
 struct ResourceLoadInfo {
-    action: ResponseAction,
+    action: FetchResponseMsg,
     key: LoadKey,
 }
 
 /// Implementation of the image cache
 struct ImageCache {
     progress_sender: Sender<ResourceLoadInfo>,
 
     decoder_sender: Sender<DecoderMsg>,
@@ -412,34 +403,36 @@ impl ImageCache {
         };
 
         None
     }
 
     // Handle progress messages from the resource thread
     fn handle_progress(&mut self, msg: ResourceLoadInfo) {
         match (msg.action, msg.key) {
-            (ResponseAction::HeadersAvailable(_), _) => {}
-            (ResponseAction::DataAvailable(data), _) => {
+            (FetchResponseMsg::ProcessRequestBody, _) |
+            (FetchResponseMsg::ProcessRequestEOF, _) => return,
+            (FetchResponseMsg::ProcessResponse(_), _) => {}
+            (FetchResponseMsg::ProcessResponseChunk(data), _) => {
                 let pending_load = self.pending_loads.get_by_key_mut(&msg.key).unwrap();
                 pending_load.bytes.extend_from_slice(&data);
                 //jmr0 TODO: possibly move to another task?
                 if let None = pending_load.metadata {
                     if let Ok(metadata) = load_from_buf(&pending_load.bytes) {
                         let dimensions = metadata.dimensions();
                         let img_metadata = ImageMetadata { width: dimensions.width,
                                                          height: dimensions.height };
                         pending_load.metadata = Some(img_metadata.clone());
                         for listener in &pending_load.listeners {
                             listener.notify(ImageResponse::MetadataLoaded(img_metadata.clone()).clone());
                         }
                     }
                 }
             }
-            (ResponseAction::ResponseComplete(result), key) => {
+            (FetchResponseMsg::ProcessResponseEOF(result), key) => {
                 match result {
                     Ok(()) => {
                         let pending_load = self.pending_loads.get_by_key_mut(&msg.key).unwrap();
                         pending_load.result = Some(result);
                         let bytes = mem::replace(&mut pending_load.bytes, vec!());
                         let sender = self.decoder_sender.clone();
 
                         self.thread_pool.execute(move || {
@@ -545,30 +538,17 @@ impl ImageCache {
                             .. RequestInit::default()
                         };
 
                         let progress_sender = self.progress_sender.clone();
                         fetch_async(request, &self.core_resource_thread, move |action| {
                             let action = match action {
                                 FetchResponseMsg::ProcessRequestBody |
                                 FetchResponseMsg::ProcessRequestEOF => return,
-                                FetchResponseMsg::ProcessResponse(meta_result) => {
-                                    ResponseAction::HeadersAvailable(meta_result.map(|m| {
-                                        match m {
-                                            FetchMetadata::Unfiltered(m) => m,
-                                            FetchMetadata::Filtered { unsafe_, .. } => unsafe_
-                                        }
-                                    }))
-                                }
-                                FetchResponseMsg::ProcessResponseChunk(new_bytes) => {
-                                    ResponseAction::DataAvailable(new_bytes)
-                                }
-                                FetchResponseMsg::ProcessResponseEOF(response) => {
-                                    ResponseAction::ResponseComplete(response)
-                                }
+                                a => a
                             };
                             progress_sender.send(ResourceLoadInfo {
                                 action: action,
                                 key: load_key,
                             }).unwrap();
                         });
                     }
                     CacheResult::Hit => {
@@ -625,22 +605,22 @@ impl ImageCache {
         }
     }
 
     fn store_decode_image(&mut self,
                           ref_url: ServoUrl,
                           loaded_bytes: Vec<u8>) {
         let (cache_result, load_key, _) = self.pending_loads.get_cached(ref_url.clone());
         assert!(cache_result == CacheResult::Miss);
-        let action = ResponseAction::DataAvailable(loaded_bytes);
+        let action = FetchResponseMsg::ProcessResponseChunk(loaded_bytes);
         let _ = self.progress_sender.send(ResourceLoadInfo {
             action: action,
             key: load_key,
         });
-        let action = ResponseAction::ResponseComplete(Ok(()));
+        let action = FetchResponseMsg::ProcessResponseEOF(Ok(()));
         let _ = self.progress_sender.send(ResourceLoadInfo {
             action: action,
             key: load_key,
         });
     }
 }
 
 /// Create a new image cache.