| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // SdchFilter applies open_vcdiff content decoding to a datastream. | 5 // SdchFilter applies open_vcdiff content decoding to a datastream. |
| 6 // This decoding uses a pre-cached dictionary of text fragments to decode | 6 // This decoding uses a pre-cached dictionary of text fragments to decode |
| 7 // (expand) the stream back to its original contents. | 7 // (expand) the stream back to its original contents. |
| 8 // | 8 // |
| 9 // This SdchFilter internally uses open_vcdiff/vcdec library to do decoding. | 9 // This SdchFilter internally uses open_vcdiff/vcdec library to do decoding. |
| 10 // | 10 // |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Decode the pre-filter data and writes the output into |dest_buffer| | 37 // Decode the pre-filter data and writes the output into |dest_buffer| |
| 38 // The function returns FilterStatus. See filter.h for its description. | 38 // The function returns FilterStatus. See filter.h for its description. |
| 39 // | 39 // |
| 40 // Upon entry, *dest_len is the total size (in number of chars) of the | 40 // Upon entry, *dest_len is the total size (in number of chars) of the |
| 41 // destination buffer. Upon exit, *dest_len is the actual number of chars | 41 // destination buffer. Upon exit, *dest_len is the actual number of chars |
| 42 // written into the destination buffer. | 42 // written into the destination buffer. |
| 43 FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len) override; | 43 FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len) override; |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 // Internal status. Once we enter an error state, we stop processing data. | 46 // Internal status. Once we enter an error state, we stop processing data. |
| 47 enum DecodingStatus { | 47 enum DecodingStatus { |
| 48 DECODING_UNINITIALIZED, | 48 DECODING_UNINITIALIZED, |
| 49 WAITING_FOR_DICTIONARY_SELECTION, | 49 WAITING_FOR_DICTIONARY_SELECTION, |
| 50 DECODING_IN_PROGRESS, | 50 DECODING_IN_PROGRESS, |
| 51 DECODING_ERROR, | 51 DECODING_ERROR, |
| 52 META_REFRESH_RECOVERY, // Decoding error being handled by a meta-refresh. | 52 META_REFRESH_RECOVERY, // Decoding error being handled by a meta-refresh. |
| 53 PASS_THROUGH, // Non-sdch content being passed without alteration. | 53 PASS_THROUGH, // Non-sdch content being passed without alteration. |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Only to be instantiated by Filter::Factory. | 56 // Only to be instantiated by Filter::Factory. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 // ReadFilteredData. | 80 // ReadFilteredData. |
| 81 scoped_ptr<open_vcdiff::VCDiffStreamingDecoder> vcdiff_streaming_decoder_; | 81 scoped_ptr<open_vcdiff::VCDiffStreamingDecoder> vcdiff_streaming_decoder_; |
| 82 | 82 |
| 83 // In case we need to assemble the hash piecemeal, we have a place to store | 83 // In case we need to assemble the hash piecemeal, we have a place to store |
| 84 // a part of the hash until we "get all 8 bytes plus a null." | 84 // a part of the hash until we "get all 8 bytes plus a null." |
| 85 std::string dictionary_hash_; | 85 std::string dictionary_hash_; |
| 86 | 86 |
| 87 // After assembling an entire dictionary hash (the first 9 bytes of the | 87 // After assembling an entire dictionary hash (the first 9 bytes of the |
| 88 // sdch payload, we check to see if it is plausible, meaning it has a null | 88 // sdch payload, we check to see if it is plausible, meaning it has a null |
| 89 // termination, and has 8 characters that are possible in a net-safe base64 | 89 // termination, and has 8 characters that are possible in a net-safe base64 |
| 90 // encoding. If the hash is not plausible, then the payload is probably not | 90 // encoding. If the hash is not plausible, then the payload is probably not |
| 91 // an SDCH encoded bundle, and various error recovery strategies can be | 91 // an SDCH encoded bundle, and various error recovery strategies can be |
| 92 // attempted. | 92 // attempted. |
| 93 bool dictionary_hash_is_plausible_; | 93 bool dictionary_hash_is_plausible_; |
| 94 | 94 |
| 95 // We hold an in-memory copy of the dictionary during the entire decoding, as | 95 // Validity of this pointer is guaranteed by either the FilterContext holding |
| 96 // it is used directly by the VC-DIFF decoding system. | 96 // a containing SdchManager::DictionarySet, or this object holding a |
| 97 // That char* data is part of the dictionary_ we hold a reference to. | 97 // container in |unexpected_dictionary_handle_| below. |
| 98 scoped_refptr<SdchManager::Dictionary> dictionary_; | 98 const SdchManager::Dictionary *dictionary_; |
| 99 | 99 |
| 100 // We keep a copy of the URLRequestContext for use in the destructor, (at | 100 // We keep a copy of the URLRequestContext for use in the destructor, (at |
| 101 // which point GetURLRequestContext() will likely return null because of | 101 // which point GetURLRequestContext() will likely return null because of |
| 102 // the disassociation of the URLRequest from the URLRequestJob). This is | 102 // the disassociation of the URLRequest from the URLRequestJob). This is |
| 103 // safe because the URLRequestJob (and any filters) are guaranteed to be | 103 // safe because the URLRequestJob (and any filters) are guaranteed to be |
| 104 // deleted before the URLRequestContext is destroyed. | 104 // deleted before the URLRequestContext is destroyed. |
| 105 const URLRequestContext* const url_request_context_; | 105 const URLRequestContext* const url_request_context_; |
| 106 | 106 |
| 107 // The decoder may demand a larger output buffer than the target of | 107 // The decoder may demand a larger output buffer than the target of |
| 108 // ReadFilteredData so we buffer the excess output between calls. | 108 // ReadFilteredData so we buffer the excess output between calls. |
| 109 std::string dest_buffer_excess_; | 109 std::string dest_buffer_excess_; |
| 110 // To avoid moving strings around too much, we save the index into | 110 // To avoid moving strings around too much, we save the index into |
| 111 // dest_buffer_excess_ that has the next byte to output. | 111 // dest_buffer_excess_ that has the next byte to output. |
| 112 size_t dest_buffer_excess_index_; | 112 size_t dest_buffer_excess_index_; |
| 113 | 113 |
| 114 // To get stats on activities, we keep track of source and target bytes. | 114 // To get stats on activities, we keep track of source and target bytes. |
| 115 // Visit about:histograms/Sdch to see histogram data. | 115 // Visit about:histograms/Sdch to see histogram data. |
| 116 size_t source_bytes_; | 116 size_t source_bytes_; |
| 117 size_t output_bytes_; | 117 size_t output_bytes_; |
| 118 | 118 |
| 119 // Error recovery in content type may add an sdch filter type, in which case | 119 // Error recovery in content type may add an sdch filter type, in which case |
| 120 // we should gracefully perform pass through if the format is incorrect, or | 120 // we should gracefully perform pass through if the format is incorrect, or |
| 121 // an applicable dictionary can't be found. | 121 // an applicable dictionary can't be found. |
| 122 bool possible_pass_through_; | 122 bool possible_pass_through_; |
| 123 | 123 |
| 124 // The URL that is currently being filtered. | 124 // The URL that is currently being filtered. |
| 125 // This is used to restrict use of a dictionary to a specific URL or path. | 125 // This is used to restrict use of a dictionary to a specific URL or path. |
| 126 GURL url_; | 126 GURL url_; |
| 127 | 127 |
| 128 // To facilitate error recovery, allow filter to know if content is text/html | 128 // To facilitate error recovery, allow filter to know if content is text/html |
| 129 // by checking within this mime type (we may do a meta-refresh via html). | 129 // by checking within this mime type (we may do a meta-refresh via html). |
| 130 std::string mime_type_; | 130 std::string mime_type_; |
| 131 | 131 |
| 132 // If the response was encoded with a dictionary different than those |
| 133 // advertised (e.g. a cached response using an old dictionary), this |
| 134 // variable preserves that dictionary from deletion during decoding. |
| 135 scoped_ptr<SdchManager::DictionarySet> unexpected_dictionary_handle_; |
| 136 |
| 132 DISALLOW_COPY_AND_ASSIGN(SdchFilter); | 137 DISALLOW_COPY_AND_ASSIGN(SdchFilter); |
| 133 }; | 138 }; |
| 134 | 139 |
| 135 } // namespace net | 140 } // namespace net |
| 136 | 141 |
| 137 #endif // NET_FILTER_SDCH_FILTER_H_ | 142 #endif // NET_FILTER_SDCH_FILTER_H_ |
| OLD | NEW |