OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_FILTER_SDCH_POLICY_DELEGATE_H_ |
| 6 #define NET_FILTER_SDCH_POLICY_DELEGATE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/supports_user_data.h" |
| 13 #include "net/base/net_export.h" |
| 14 #include "net/base/sdch_manager.h" |
| 15 #include "net/filter/sdch_source_stream.h" |
| 16 #include "net/log/net_log.h" |
| 17 #include "net/log/net_log_with_source.h" |
| 18 #include "url/gurl.h" |
| 19 |
| 20 namespace open_vcdiff { |
| 21 class VCDiffStreamingDecoder; |
| 22 } |
| 23 |
| 24 namespace net { |
| 25 |
| 26 class SdchSourceStream; |
| 27 |
| 28 // This class implements the SdchSourceStream::Delegate interface to perform |
| 29 // the SDCH error handling and stats gathering. The Context object supplies |
| 30 // details about the request needed for this object to make error-handling |
| 31 // decisions. See the SdchSourceStream::Delegate documentation for more details. |
| 32 class NET_EXPORT_PRIVATE SdchPolicyDelegate |
| 33 : public SdchSourceStream::Delegate { |
| 34 public: |
| 35 enum StatisticSelector { |
| 36 SDCH_DECODE, |
| 37 SDCH_PASSTHROUGH, |
| 38 SDCH_EXPERIMENT_DECODE, |
| 39 SDCH_EXPERIMENT_HOLDBACK, |
| 40 }; |
| 41 |
| 42 SdchPolicyDelegate(std::string mime_type, |
| 43 const GURL& url, |
| 44 bool is_cached_content, |
| 45 SdchManager* sdch_manager, |
| 46 std::unique_ptr<SdchManager::DictionarySet> dictionary_set, |
| 47 int response_code, |
| 48 const NetLogWithSource& net_log); |
| 49 |
| 50 ~SdchPolicyDelegate() override; |
| 51 |
| 52 // Logs an SDCH failure to UMA and |netlog|. |
| 53 static void LogSdchProblem(NetLogWithSource netlog, SdchProblemCode problem); |
| 54 |
| 55 // Sdch specific hacks to fix up encoding types. |
| 56 static void FixUpSdchContentEncodings( |
| 57 const NetLogWithSource& net_log, |
| 58 const std::string& mime_type, |
| 59 SdchManager::DictionarySet* dictionary_set, |
| 60 std::vector<SourceStream::SourceType>* types); |
| 61 |
| 62 // SdchSourceStream::Delegate implementation. |
| 63 ErrorRecovery OnDictionaryIdError(bool possible_pass_through, |
| 64 std::string* replace_output) override; |
| 65 ErrorRecovery OnGetDictionaryError(bool possible_pass_through, |
| 66 std::string* replace_output) override; |
| 67 ErrorRecovery OnDecodingError(std::string* replace_output) override; |
| 68 bool OnGetDictionary(const std::string& server_id, |
| 69 const std::string** text) override; |
| 70 |
| 71 void OnStreamDestroyed(SdchSourceStream::InputState input_state, |
| 72 const std::string& buffered_output, |
| 73 open_vcdiff::VCDiffStreamingDecoder* decoder) override; |
| 74 |
| 75 private: |
| 76 // Disambiguate various types of responses that trigger a meta-refresh, |
| 77 // failure, or fallback to pass-through. |
| 78 enum ResponseCorruptionDetectionCause { |
| 79 RESPONSE_NONE, |
| 80 |
| 81 // 404 Http Response Code |
| 82 RESPONSE_404 = 1, |
| 83 |
| 84 // Not a 200 Http Response Code |
| 85 RESPONSE_NOT_200 = 2, |
| 86 |
| 87 // Cached before dictionary retrieved. |
| 88 RESPONSE_OLD_UNENCODED = 3, |
| 89 |
| 90 // Speculative but incorrect SDCH filtering was added added. |
| 91 RESPONSE_TENTATIVE_SDCH = 4, |
| 92 |
| 93 // Missing correct dict for decoding. |
| 94 RESPONSE_NO_DICTIONARY = 5, |
| 95 |
| 96 // Not an SDCH response but should be. |
| 97 RESPONSE_CORRUPT_SDCH = 6, |
| 98 |
| 99 // No dictionary was advertised with the request, the server claims |
| 100 // to have encoded with SDCH anyway, but it isn't an SDCH response. |
| 101 RESPONSE_ENCODING_LIE = 7, |
| 102 |
| 103 RESPONSE_MAX, |
| 104 }; |
| 105 |
| 106 // Issues a meta-refresh if the context's MIME type supports it, and returns |
| 107 // whether a refresh was issued. As a side-effect, blacklists the context's |
| 108 // domain either temporarily or permanently. |
| 109 ErrorRecovery IssueMetaRefreshIfPossible(std::string* replace_output); |
| 110 |
| 111 // Logs ResponseCorruptionDetection cause. This is very similar to |
| 112 // LogSdchProblem(). TODO(xunjieli): Can we get rid of this? |
| 113 void LogCorruptionDetection(ResponseCorruptionDetectionCause cause); |
| 114 |
| 115 static const char* ResponseCorruptionDetectionCauseToString( |
| 116 ResponseCorruptionDetectionCause cause); |
| 117 |
| 118 static std::unique_ptr<base::Value> NetLogResponseCorruptionDetectionCallback( |
| 119 ResponseCorruptionDetectionCause cause, |
| 120 bool cached, |
| 121 NetLogCaptureMode capture_mode); |
| 122 |
| 123 const std::string mime_type_; |
| 124 const GURL url_; |
| 125 const bool is_cached_content_; |
| 126 SdchManager* sdch_manager_; |
| 127 std::unique_ptr<SdchManager::DictionarySet> dictionary_set_; |
| 128 const int response_code_; |
| 129 const NetLogWithSource net_log_; |
| 130 |
| 131 std::string server_id_; |
| 132 |
| 133 // If the response was encoded with a dictionary different than those |
| 134 // advertised (e.g. a cached response using an old dictionary), this |
| 135 // variable preserves that dictionary from deletion during decoding. |
| 136 std::unique_ptr<SdchManager::DictionarySet> unexpected_dictionary_set_; |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(SdchPolicyDelegate); |
| 139 }; |
| 140 |
| 141 } // namespace net |
| 142 |
| 143 #endif // NET_FILTER_SDCH_POLICY_DELEGATE_H_ |
OLD | NEW |