| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_BASE_SDCH_MANAGER_H_ | 5 #ifndef NET_BASE_SDCH_MANAGER_H_ |
| 6 #define NET_BASE_SDCH_MANAGER_H_ | 6 #define NET_BASE_SDCH_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24, | 73 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24, |
| 74 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25, | 74 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25, |
| 75 DICTIONARY_HAS_NO_TEXT = 26, | 75 DICTIONARY_HAS_NO_TEXT = 26, |
| 76 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27, | 76 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27, |
| 77 | 77 |
| 78 // Dictionary loading problems. | 78 // Dictionary loading problems. |
| 79 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30, | 79 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30, |
| 80 DICTIONARY_SELECTED_FOR_SSL = 31, | 80 DICTIONARY_SELECTED_FOR_SSL = 31, |
| 81 DICTIONARY_ALREADY_LOADED = 32, | 81 DICTIONARY_ALREADY_LOADED = 32, |
| 82 DICTIONARY_SELECTED_FROM_NON_HTTP = 33, | 82 DICTIONARY_SELECTED_FROM_NON_HTTP = 33, |
| 83 DICTIONARY_IS_TOO_LARGE= 34, | 83 DICTIONARY_IS_TOO_LARGE = 34, |
| 84 DICTIONARY_COUNT_EXCEEDED = 35, | 84 DICTIONARY_COUNT_EXCEEDED = 35, |
| 85 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36, | 85 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36, |
| 86 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37, | 86 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37, |
| 87 DICTIONARY_FETCH_READ_FAILED = 38, | 87 DICTIONARY_FETCH_READ_FAILED = 38, |
| 88 | 88 |
| 89 // Failsafe hack. | 89 // Failsafe hack. |
| 90 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40, | 90 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40, |
| 91 | 91 |
| 92 | |
| 93 // Content-Encoding problems detected, with no action taken. | 92 // Content-Encoding problems detected, with no action taken. |
| 94 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50, | 93 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50, |
| 95 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51, | 94 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51, |
| 96 | 95 |
| 97 // Dictionary manager issues. | 96 // Dictionary manager issues. |
| 98 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61, | 97 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61, |
| 99 | 98 |
| 100 // Problematic decode recovery methods. | 99 // Problematic decode recovery methods. |
| 101 META_REFRESH_RECOVERY = 70, // Dictionary not found. | 100 META_REFRESH_RECOVERY = 70, // Dictionary not found. |
| 102 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED. | 101 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED. |
| 103 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED. | 102 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED. |
| 104 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus | 103 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus |
| 105 // RESPONSE_TENTATIVE_SDCH in ../filter/sdch_filter.cc. | 104 // RESPONSE_TENTATIVE_SDCH in ../filter/sdch_filter.cc. |
| 106 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error. | 105 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error. |
| 107 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache. | 106 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache. |
| 108 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash. | 107 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash. |
| 109 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded. | 108 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded. |
| 110 PASS_THROUGH_404_CODE = 78, // URL not found message passing through. | 109 PASS_THROUGH_404_CODE = 78, // URL not found message passing through. |
| 111 | 110 |
| 112 // This next report is very common, and not really an error scenario, but | 111 // This next report is very common, and not really an error scenario, but |
| 113 // it exercises the error recovery logic. | 112 // it exercises the error recovery logic. |
| 114 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content. | 113 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content. |
| 115 | 114 |
| 116 // Common decoded recovery methods. | 115 // Common decoded recovery methods. |
| 117 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading. | 116 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading. |
| 118 // defunct = 81, // Now tracked by ResponseCorruptionDetectionCause histo. | 117 // defunct = 81, // Now tracked by ResponseCorruptionDetectionCause histo. |
| 119 | 118 |
| 120 // Non SDCH problems, only accounted for to make stat counting complete | 119 // Non SDCH problems, only accounted for to make stat counting complete |
| 121 // (i.e., be able to be sure all dictionary advertisements are accounted | 120 // (i.e., be able to be sure all dictionary advertisements are accounted |
| 122 // for). | 121 // for). |
| 123 | 122 |
| 124 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining. | 123 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining. |
| 125 // defunct = 91, // MISSING_TIME_STATS (Should never happen.) | 124 // defunct = 91, // MISSING_TIME_STATS (Should never happen.) |
| 126 CACHE_DECODED = 92, // No timing stats recorded. | 125 CACHE_DECODED = 92, // No timing stats recorded. |
| 127 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.) | 126 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.) |
| 128 UNINITIALIZED = 94, // Filter never even got initialized. | 127 UNINITIALIZED = 94, // Filter never even got initialized. |
| 129 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector. | 128 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector. |
| 130 DECODE_ERROR = 96, // Something went wrong during decode. | 129 DECODE_ERROR = 96, // Something went wrong during decode. |
| 131 | 130 |
| 132 // Problem during the latency test. | 131 // Problem during the latency test. |
| 133 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before! | 132 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before! |
| 134 | 133 |
| 135 MAX_PROBLEM_CODE // Used to bound histogram. | 134 MAX_PROBLEM_CODE // Used to bound histogram. |
| 136 }; | 135 }; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 167 | 166 |
| 168 const GURL& url() const { return url_; } | 167 const GURL& url() const { return url_; } |
| 169 const std::string& client_hash() const { return client_hash_; } | 168 const std::string& client_hash() const { return client_hash_; } |
| 170 | 169 |
| 171 // Security method to check if we can advertise this dictionary for use | 170 // Security method to check if we can advertise this dictionary for use |
| 172 // if the |target_url| returns SDCH compressed data. | 171 // if the |target_url| returns SDCH compressed data. |
| 173 bool CanAdvertise(const GURL& target_url); | 172 bool CanAdvertise(const GURL& target_url); |
| 174 | 173 |
| 175 // Security methods to check if we can establish a new dictionary with the | 174 // Security methods to check if we can establish a new dictionary with the |
| 176 // given data, that arrived in response to get of dictionary_url. | 175 // given data, that arrived in response to get of dictionary_url. |
| 177 static bool CanSet(const std::string& domain, const std::string& path, | 176 static bool CanSet(const std::string& domain, |
| 178 const std::set<int>& ports, const GURL& dictionary_url); | 177 const std::string& path, |
| 178 const std::set<int>& ports, |
| 179 const GURL& dictionary_url); |
| 179 | 180 |
| 180 // Security method to check if we can use a dictionary to decompress a | 181 // Security method to check if we can use a dictionary to decompress a |
| 181 // target that arrived with a reference to this dictionary. | 182 // target that arrived with a reference to this dictionary. |
| 182 bool CanUse(const GURL& referring_url); | 183 bool CanUse(const GURL& referring_url); |
| 183 | 184 |
| 184 // Compare paths to see if they "match" for dictionary use. | 185 // Compare paths to see if they "match" for dictionary use. |
| 185 static bool PathMatch(const std::string& path, | 186 static bool PathMatch(const std::string& path, |
| 186 const std::string& restriction); | 187 const std::string& restriction); |
| 187 | 188 |
| 188 // Compare domains to see if the "match" for dictionary use. | 189 // Compare domains to see if the "match" for dictionary use. |
| 189 static bool DomainMatch(const GURL& url, const std::string& restriction); | 190 static bool DomainMatch(const GURL& url, const std::string& restriction); |
| 190 | 191 |
| 191 | |
| 192 // The actual text of the dictionary. | 192 // The actual text of the dictionary. |
| 193 std::string text_; | 193 std::string text_; |
| 194 | 194 |
| 195 // Part of the hash of text_ that the client uses to advertise the fact that | 195 // Part of the hash of text_ that the client uses to advertise the fact that |
| 196 // it has a specific dictionary pre-cached. | 196 // it has a specific dictionary pre-cached. |
| 197 std::string client_hash_; | 197 std::string client_hash_; |
| 198 | 198 |
| 199 // The GURL that arrived with the text_ in a URL request to specify where | 199 // The GURL that arrived with the text_ in a URL request to specify where |
| 200 // this dictionary may be used. | 200 // this dictionary may be used. |
| 201 const GURL url_; | 201 const GURL url_; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 // Get list of available (pre-cached) dictionaries that we have already loaded | 279 // Get list of available (pre-cached) dictionaries that we have already loaded |
| 280 // into memory. The list is a comma separated list of (client) hashes per | 280 // into memory. The list is a comma separated list of (client) hashes per |
| 281 // the SDCH spec. | 281 // the SDCH spec. |
| 282 void GetAvailDictionaryList(const GURL& target_url, std::string* list); | 282 void GetAvailDictionaryList(const GURL& target_url, std::string* list); |
| 283 | 283 |
| 284 // Construct the pair of hashes for client and server to identify an SDCH | 284 // Construct the pair of hashes for client and server to identify an SDCH |
| 285 // dictionary. This is only made public to facilitate unit testing, but is | 285 // dictionary. This is only made public to facilitate unit testing, but is |
| 286 // otherwise private | 286 // otherwise private |
| 287 static void GenerateHash(const std::string& dictionary_text, | 287 static void GenerateHash(const std::string& dictionary_text, |
| 288 std::string* client_hash, std::string* server_hash); | 288 std::string* client_hash, |
| 289 std::string* server_hash); |
| 289 | 290 |
| 290 // For Latency testing only, we need to know if we've succeeded in doing a | 291 // For Latency testing only, we need to know if we've succeeded in doing a |
| 291 // round trip before starting our comparative tests. If ever we encounter | 292 // round trip before starting our comparative tests. If ever we encounter |
| 292 // problems with SDCH, we opt-out of the test unless/until we perform a | 293 // problems with SDCH, we opt-out of the test unless/until we perform a |
| 293 // complete SDCH decoding. | 294 // complete SDCH decoding. |
| 294 bool AllowLatencyExperiment(const GURL& url) const; | 295 bool AllowLatencyExperiment(const GURL& url) const; |
| 295 | 296 |
| 296 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 297 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
| 297 | 298 |
| 298 // Add an SDCH dictionary to our list of availible | 299 // Add an SDCH dictionary to our list of availible |
| 299 // dictionaries. This addition will fail if addition is illegal | 300 // dictionaries. This addition will fail if addition is illegal |
| 300 // (data in the dictionary is not acceptable from the | 301 // (data in the dictionary is not acceptable from the |
| 301 // dictionary_url; dictionary already added, etc.). | 302 // dictionary_url; dictionary already added, etc.). |
| 302 void AddSdchDictionary(const std::string& dictionary_text, | 303 void AddSdchDictionary(const std::string& dictionary_text, |
| 303 const GURL& dictionary_url); | 304 const GURL& dictionary_url); |
| 304 | 305 |
| 305 // Registration for events generated by the SDCH subsystem. | 306 // Registration for events generated by the SDCH subsystem. |
| 306 void AddObserver(SdchObserver* observer); | 307 void AddObserver(SdchObserver* observer); |
| 307 void RemoveObserver(SdchObserver* observer); | 308 void RemoveObserver(SdchObserver* observer); |
| 308 | 309 |
| 309 private: | 310 private: |
| 310 struct BlacklistInfo { | 311 struct BlacklistInfo { |
| 311 BlacklistInfo() | 312 BlacklistInfo() |
| 312 : count(0), | 313 : count(0), exponential_count(0), reason(MIN_PROBLEM_CODE) {} |
| 313 exponential_count(0), | |
| 314 reason(MIN_PROBLEM_CODE) {} | |
| 315 | 314 |
| 316 int count; // # of times to refuse SDCH advertisement. | 315 int count; // # of times to refuse SDCH advertisement. |
| 317 int exponential_count; // Current exponential backoff ratchet. | 316 int exponential_count; // Current exponential backoff ratchet. |
| 318 ProblemCodes reason; // Why domain was blacklisted. | 317 ProblemCodes reason; // Why domain was blacklisted. |
| 319 | |
| 320 }; | 318 }; |
| 321 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo; | 319 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo; |
| 322 typedef std::set<std::string> ExperimentSet; | 320 typedef std::set<std::string> ExperimentSet; |
| 323 | 321 |
| 324 // Determines whether a "Get-Dictionary" header is legal (dictionary | 322 // Determines whether a "Get-Dictionary" header is legal (dictionary |
| 325 // url has appropriate relationship to referrer url) in the SDCH | 323 // url has appropriate relationship to referrer url) in the SDCH |
| 326 // protocol. Return true if fetch is legal. | 324 // protocol. Return true if fetch is legal. |
| 327 bool CanFetchDictionary(const GURL& referring_url, | 325 bool CanFetchDictionary(const GURL& referring_url, |
| 328 const GURL& dictionary_url) const; | 326 const GURL& dictionary_url) const; |
| 329 | 327 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 356 ObserverList<SdchObserver, true> observers_; | 354 ObserverList<SdchObserver, true> observers_; |
| 357 | 355 |
| 358 base::ThreadChecker thread_checker_; | 356 base::ThreadChecker thread_checker_; |
| 359 | 357 |
| 360 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 358 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
| 361 }; | 359 }; |
| 362 | 360 |
| 363 } // namespace net | 361 } // namespace net |
| 364 | 362 |
| 365 #endif // NET_BASE_SDCH_MANAGER_H_ | 363 #endif // NET_BASE_SDCH_MANAGER_H_ |
| OLD | NEW |