Chromium Code Reviews| 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 // Provides global database of differential decompression dictionaries for the | 5 // Provides global database of differential decompression dictionaries for the |
| 6 // SDCH filter (processes sdch enconded content). | 6 // SDCH filter (processes sdch enconded content). |
| 7 | 7 |
| 8 // Exactly one instance of SdchManager is built, and all references are made | 8 // Exactly one instance of SdchManager is built, and all references are made |
| 9 // into that collection. | 9 // into that collection. |
| 10 // | 10 // |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include <string> | 25 #include <string> |
| 26 | 26 |
| 27 #include "base/gtest_prod_util.h" | 27 #include "base/gtest_prod_util.h" |
| 28 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
| 29 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
| 30 #include "base/threading/non_thread_safe.h" | 30 #include "base/threading/non_thread_safe.h" |
| 31 #include "base/time/time.h" | 31 #include "base/time/time.h" |
| 32 #include "net/base/net_export.h" | 32 #include "net/base/net_export.h" |
| 33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 34 | 34 |
| 35 namespace base { | |
| 36 class Value; | |
| 37 } | |
| 38 | |
| 35 namespace net { | 39 namespace net { |
| 36 | 40 |
| 41 class BoundNetLog; | |
| 42 | |
| 37 //------------------------------------------------------------------------------ | 43 //------------------------------------------------------------------------------ |
| 38 // Create a public interface to help us load SDCH dictionaries. | 44 // Create a public interface to help us load SDCH dictionaries. |
| 39 // The SdchManager class allows registration to support this interface. | 45 // The SdchManager class allows registration to support this interface. |
| 40 // A browser may register a fetcher that is used by the dictionary managers to | 46 // A browser may register a fetcher that is used by the dictionary managers to |
| 41 // get data from a specified URL. This allows us to use very high level browser | 47 // get data from a specified URL. This allows us to use very high level browser |
| 42 // functionality in this base (when the functionality can be provided). | 48 // functionality in this base (when the functionality can be provided). |
| 43 class NET_EXPORT SdchFetcher { | 49 class NET_EXPORT SdchFetcher { |
| 44 public: | 50 public: |
| 51 enum ScheduleResult { | |
|
Randy Smith (Not in Mondays)
2014/09/18 20:55:51
So this (the enum, switching Schedule() to return
baranovich
2014/09/19 12:42:44
Sure, I'll try.
baranovich
2014/09/30 13:16:52
Done.
| |
| 52 SCHEDULE_OK, | |
| 53 ALREADY_SCHEDULED, | |
| 54 ALREADY_TRIED, | |
| 55 }; | |
| 56 | |
| 45 class NET_EXPORT Delegate { | 57 class NET_EXPORT Delegate { |
| 46 public: | 58 public: |
| 47 virtual ~Delegate() {} | 59 virtual ~Delegate() {} |
| 48 | 60 |
| 49 // Called whenever the SdchFetcher has successfully retrieved a | 61 // Called whenever the SdchFetcher has successfully retrieved a |
| 50 // dictionary. |dictionary_text| contains the body of the dictionary | 62 // dictionary. |dictionary_text| contains the body of the dictionary |
| 51 // retrieved from |dictionary_url|. | 63 // retrieved from |dictionary_url|. |
| 52 virtual void AddSdchDictionary(const std::string& dictionary_text, | 64 virtual void AddSdchDictionary(const std::string& dictionary_text, |
| 53 const GURL& dictionary_url) = 0; | 65 const GURL& dictionary_url, |
| 66 const BoundNetLog& net_log) = 0; | |
| 54 }; | 67 }; |
| 55 | 68 |
| 56 SdchFetcher() {} | 69 SdchFetcher() {} |
| 57 virtual ~SdchFetcher() {} | 70 virtual ~SdchFetcher() {} |
| 58 | 71 |
| 59 // The Schedule() method is called when there is a need to get a dictionary | 72 // The Schedule() method is called when there is a need to get a dictionary |
| 60 // from a server. The callee is responsible for getting that dictionary_text, | 73 // from a server. The callee is responsible for getting that dictionary_text, |
| 61 // and then calling back to AddSdchDictionary() in the Delegate instance. | 74 // and then calling back to AddSdchDictionary() in the Delegate instance. |
| 62 virtual void Schedule(const GURL& dictionary_url) = 0; | 75 virtual ScheduleResult Schedule(const GURL& dictionary_url) = 0; |
| 63 | 76 |
| 64 // The Cancel() method is called to cancel all pending dictionary fetches. | 77 // The Cancel() method is called to cancel all pending dictionary fetches. |
| 65 // This is used for implementation of ClearData() below. | 78 // This is used for implementation of ClearData() below. |
| 66 virtual void Cancel() = 0; | 79 virtual void Cancel() = 0; |
| 67 | 80 |
| 68 private: | 81 private: |
| 69 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); | 82 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); |
| 70 }; | 83 }; |
| 71 | 84 |
| 72 //------------------------------------------------------------------------------ | 85 //------------------------------------------------------------------------------ |
| 73 | 86 |
| 74 class NET_EXPORT SdchManager | 87 class NET_EXPORT SdchManager |
| 75 : public SdchFetcher::Delegate, | 88 : public SdchFetcher::Delegate, |
| 76 public NON_EXPORTED_BASE(base::NonThreadSafe) { | 89 public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 77 public: | 90 public: |
| 78 // A list of errors that appeared and were either resolved, or used to turn | 91 // A list of errors that appeared and were either resolved, or used to turn |
| 79 // off sdch encoding. | 92 // off sdch encoding. |
| 80 enum ProblemCodes { | 93 enum ProblemCodes { |
| 81 MIN_PROBLEM_CODE, | 94 PROBLEM_CODE_OK = 0, |
| 82 | 95 |
| 83 // Content-encoding correction problems. | 96 #define SDCH_PROBLEM_CODE(label, value) label = value, |
| 84 ADDED_CONTENT_ENCODING = 1, | 97 #include "net/base/sdch_problem_code_list.h" |
| 85 FIXED_CONTENT_ENCODING = 2, | 98 #undef SDCH_PROBLEM_CODE |
| 86 FIXED_CONTENT_ENCODINGS = 3, | |
| 87 | |
| 88 // Content decoding errors. | |
| 89 DECODE_HEADER_ERROR = 4, | |
| 90 DECODE_BODY_ERROR = 5, | |
| 91 | |
| 92 // More content-encoding correction problems. | |
| 93 OPTIONAL_GUNZIP_ENCODING_ADDED = 6, | |
| 94 | |
| 95 // Content encoding correction when we're not even tagged as HTML!?! | |
| 96 BINARY_ADDED_CONTENT_ENCODING = 7, | |
| 97 BINARY_FIXED_CONTENT_ENCODING = 8, | |
| 98 BINARY_FIXED_CONTENT_ENCODINGS = 9, | |
| 99 | |
| 100 // Dictionary selection for use problems. | |
| 101 DICTIONARY_FOUND_HAS_WRONG_DOMAIN = 10, | |
| 102 DICTIONARY_FOUND_HAS_WRONG_PORT_LIST = 11, | |
| 103 DICTIONARY_FOUND_HAS_WRONG_PATH = 12, | |
| 104 DICTIONARY_FOUND_HAS_WRONG_SCHEME = 13, | |
| 105 DICTIONARY_HASH_NOT_FOUND = 14, | |
| 106 DICTIONARY_HASH_MALFORMED = 15, | |
| 107 | |
| 108 // Dictionary saving problems. | |
| 109 DICTIONARY_HAS_NO_HEADER = 20, | |
| 110 DICTIONARY_HEADER_LINE_MISSING_COLON = 21, | |
| 111 DICTIONARY_MISSING_DOMAIN_SPECIFIER = 22, | |
| 112 DICTIONARY_SPECIFIES_TOP_LEVEL_DOMAIN = 23, | |
| 113 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24, | |
| 114 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25, | |
| 115 DICTIONARY_HAS_NO_TEXT = 26, | |
| 116 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27, | |
| 117 | |
| 118 // Dictionary loading problems. | |
| 119 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30, | |
| 120 DICTIONARY_SELECTED_FOR_SSL = 31, | |
| 121 DICTIONARY_ALREADY_LOADED = 32, | |
| 122 DICTIONARY_SELECTED_FROM_NON_HTTP = 33, | |
| 123 DICTIONARY_IS_TOO_LARGE= 34, | |
| 124 DICTIONARY_COUNT_EXCEEDED = 35, | |
| 125 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36, | |
| 126 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37, | |
| 127 | |
| 128 // Failsafe hack. | |
| 129 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40, | |
| 130 | |
| 131 | |
| 132 // Content-Encoding problems detected, with no action taken. | |
| 133 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50, | |
| 134 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51, | |
| 135 | |
| 136 // Dictionary manager issues. | |
| 137 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61, | |
| 138 | |
| 139 // Problematic decode recovery methods. | |
| 140 META_REFRESH_RECOVERY = 70, // Dictionary not found. | |
| 141 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED. | |
| 142 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED. | |
| 143 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus | |
| 144 // RESPONSE_TENTATIVE_SDCH in ../filter/sdch_filter.cc. | |
| 145 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error. | |
| 146 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache. | |
| 147 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash. | |
| 148 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded. | |
| 149 PASS_THROUGH_404_CODE = 78, // URL not found message passing through. | |
| 150 | |
| 151 // This next report is very common, and not really an error scenario, but | |
| 152 // it exercises the error recovery logic. | |
| 153 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content. | |
| 154 | |
| 155 // Common decoded recovery methods. | |
| 156 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading. | |
| 157 // defunct = 81, // Now tracked by ResponseCorruptionDetectionCause histo. | |
| 158 | |
| 159 // Non SDCH problems, only accounted for to make stat counting complete | |
| 160 // (i.e., be able to be sure all dictionary advertisements are accounted | |
| 161 // for). | |
| 162 | |
| 163 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining. | |
| 164 // defunct = 91, // MISSING_TIME_STATS (Should never happen.) | |
| 165 CACHE_DECODED = 92, // No timing stats recorded. | |
| 166 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.) | |
| 167 UNINITIALIZED = 94, // Filter never even got initialized. | |
| 168 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector. | |
| 169 DECODE_ERROR = 96, // Something went wrong during decode. | |
| 170 | |
| 171 // Problem during the latency test. | |
| 172 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before! | |
| 173 | |
| 174 MAX_PROBLEM_CODE // Used to bound histogram. | |
| 175 }; | 99 }; |
| 176 | 100 |
| 177 // Use the following static limits to block DOS attacks until we implement | 101 // Use the following static limits to block DOS attacks until we implement |
| 178 // a cached dictionary evicition strategy. | 102 // a cached dictionary evicition strategy. |
| 179 static const size_t kMaxDictionarySize; | 103 static const size_t kMaxDictionarySize; |
| 180 static const size_t kMaxDictionaryCount; | 104 static const size_t kMaxDictionaryCount; |
| 181 | 105 |
| 182 // There is one instance of |Dictionary| for each memory-cached SDCH | 106 // There is one instance of |Dictionary| for each memory-cached SDCH |
| 183 // dictionary. | 107 // dictionary. |
| 184 class NET_EXPORT_PRIVATE Dictionary : public base::RefCounted<Dictionary> { | 108 class NET_EXPORT_PRIVATE Dictionary : public base::RefCounted<Dictionary> { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 199 const std::string& client_hash, | 123 const std::string& client_hash, |
| 200 const GURL& url, | 124 const GURL& url, |
| 201 const std::string& domain, | 125 const std::string& domain, |
| 202 const std::string& path, | 126 const std::string& path, |
| 203 const base::Time& expiration, | 127 const base::Time& expiration, |
| 204 const std::set<int>& ports); | 128 const std::set<int>& ports); |
| 205 virtual ~Dictionary(); | 129 virtual ~Dictionary(); |
| 206 | 130 |
| 207 const GURL& url() const { return url_; } | 131 const GURL& url() const { return url_; } |
| 208 const std::string& client_hash() const { return client_hash_; } | 132 const std::string& client_hash() const { return client_hash_; } |
| 133 const std::string& domain() const { return domain_; } | |
| 134 const std::string& path() const { return path_; } | |
| 135 const base::Time& expiration() const { return expiration_; } | |
| 136 const std::set<int>& ports() const { return ports_; } | |
| 209 | 137 |
| 210 // Security method to check if we can advertise this dictionary for use | 138 // Security method to check if we can advertise this dictionary for use |
| 211 // if the |target_url| returns SDCH compressed data. | 139 // if the |target_url| returns SDCH compressed data. |
| 212 bool CanAdvertise(const GURL& target_url); | 140 ProblemCodes CanAdvertise(const GURL& target_url) const; |
| 213 | 141 |
| 214 // Security methods to check if we can establish a new dictionary with the | 142 // Security methods to check if we can establish a new dictionary with the |
| 215 // given data, that arrived in response to get of dictionary_url. | 143 // given data, that arrived in response to get of dictionary_url. |
| 216 static bool CanSet(const std::string& domain, const std::string& path, | 144 static ProblemCodes CanSet(const std::string& domain, |
| 217 const std::set<int>& ports, const GURL& dictionary_url); | 145 const std::string& path, |
| 146 const std::set<int>& ports, | |
| 147 const GURL& dictionary_url); | |
| 218 | 148 |
| 219 // Security method to check if we can use a dictionary to decompress a | 149 // Security method to check if we can use a dictionary to decompress a |
| 220 // target that arrived with a reference to this dictionary. | 150 // target that arrived with a reference to this dictionary. |
| 221 bool CanUse(const GURL& referring_url); | 151 ProblemCodes CanUse(const GURL& referring_url) const; |
| 222 | 152 |
| 223 // Compare paths to see if they "match" for dictionary use. | 153 // Compare paths to see if they "match" for dictionary use. |
| 224 static bool PathMatch(const std::string& path, | 154 static bool PathMatch(const std::string& path, |
| 225 const std::string& restriction); | 155 const std::string& restriction); |
| 226 | 156 |
| 227 // Compare domains to see if the "match" for dictionary use. | 157 // Compare domains to see if the "match" for dictionary use. |
| 228 static bool DomainMatch(const GURL& url, const std::string& restriction); | 158 static bool DomainMatch(const GURL& url, const std::string& restriction); |
| 229 | 159 |
| 230 | |
| 231 // The actual text of the dictionary. | 160 // The actual text of the dictionary. |
| 232 std::string text_; | 161 std::string text_; |
| 233 | 162 |
| 234 // Part of the hash of text_ that the client uses to advertise the fact that | 163 // Part of the hash of text_ that the client uses to advertise the fact that |
| 235 // it has a specific dictionary pre-cached. | 164 // it has a specific dictionary pre-cached. |
| 236 std::string client_hash_; | 165 std::string client_hash_; |
| 237 | 166 |
| 238 // The GURL that arrived with the text_ in a URL request to specify where | 167 // The GURL that arrived with the text_ in a URL request to specify where |
| 239 // this dictionary may be used. | 168 // this dictionary may be used. |
| 240 const GURL url_; | 169 const GURL url_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 // Unit test only: indicate how many more times a domain will be blacklisted. | 224 // Unit test only: indicate how many more times a domain will be blacklisted. |
| 296 int BlackListDomainCount(const std::string& domain); | 225 int BlackListDomainCount(const std::string& domain); |
| 297 | 226 |
| 298 // Unit test only: Indicate what current blacklist increment is for a domain. | 227 // Unit test only: Indicate what current blacklist increment is for a domain. |
| 299 int BlacklistDomainExponential(const std::string& domain); | 228 int BlacklistDomainExponential(const std::string& domain); |
| 300 | 229 |
| 301 // Check to see if SDCH is enabled (globally), and the given URL is in a | 230 // Check to see if SDCH is enabled (globally), and the given URL is in a |
| 302 // supported domain (i.e., not blacklisted, and either the specific supported | 231 // supported domain (i.e., not blacklisted, and either the specific supported |
| 303 // domain, or all domains were assumed supported). If it is blacklist, reduce | 232 // domain, or all domains were assumed supported). If it is blacklist, reduce |
| 304 // by 1 the number of times it will be reported as blacklisted. | 233 // by 1 the number of times it will be reported as blacklisted. |
| 305 bool IsInSupportedDomain(const GURL& url); | 234 ProblemCodes IsInSupportedDomain(const GURL& url); |
| 306 | 235 |
| 307 // Schedule the URL fetching to load a dictionary. This will always return | 236 // Schedule the URL fetching to load a dictionary. This will always return |
| 308 // before the dictionary is actually loaded and added. | 237 // before the dictionary is actually loaded and added. |
| 309 // After the implied task does completes, the dictionary will have been | 238 // After the implied task does completes, the dictionary will have been |
| 310 // cached in memory. | 239 // cached in memory. |
| 311 void FetchDictionary(const GURL& request_url, const GURL& dictionary_url); | 240 ProblemCodes FetchDictionary(const GURL& request_url, |
| 241 const GURL& dictionary_url); | |
| 312 | 242 |
| 313 // Security test function used before initiating a FetchDictionary. | 243 // Security test function used before initiating a FetchDictionary. |
| 314 // Return true if fetch is legal. | 244 // Return PROBLEM_CODE_OK if fetch is legal. |
| 315 bool CanFetchDictionary(const GURL& referring_url, | 245 ProblemCodes CanFetchDictionary(const GURL& referring_url, |
| 316 const GURL& dictionary_url) const; | 246 const GURL& dictionary_url) const; |
| 317 | 247 |
| 318 // Find the vcdiff dictionary (the body of the sdch dictionary that appears | 248 // Find the vcdiff dictionary (the body of the sdch dictionary that appears |
| 319 // after the meta-data headers like Domain:...) with the given |server_hash| | 249 // after the meta-data headers like Domain:...) with the given |server_hash| |
| 320 // to use to decompreses data that arrived as SDCH encoded content. Check to | 250 // to use to decompreses data that arrived as SDCH encoded content. Check to |
| 321 // be sure the returned |dictionary| can be used for decoding content supplied | 251 // be sure the returned |dictionary| can be used for decoding content supplied |
| 322 // in response to a request for |referring_url|. | 252 // in response to a request for |referring_url|. |
| 323 // Return null in |dictionary| if there is no matching legal dictionary. | 253 // Return null in |dictionary| if there is no matching legal dictionary. |
| 324 void GetVcdiffDictionary(const std::string& server_hash, | 254 // Returns PROBLEM_CODE_OK if dictionary is not found, SDCH(-over-https) is |
| 325 const GURL& referring_url, | 255 // disabled, or if matching legal dictionary exists. Otherwise returns the |
| 326 scoped_refptr<Dictionary>* dictionary); | 256 // corresponding problem code. |
| 257 ProblemCodes GetVcdiffDictionary(const std::string& server_hash, | |
| 258 const GURL& referring_url, | |
| 259 scoped_refptr<Dictionary>* dictionary); | |
| 327 | 260 |
| 328 // Get list of available (pre-cached) dictionaries that we have already loaded | 261 // Get list of available (pre-cached) dictionaries that we have already loaded |
| 329 // into memory. The list is a comma separated list of (client) hashes per | 262 // into memory. The list is a comma separated list of (client) hashes per |
| 330 // the SDCH spec. | 263 // the SDCH spec. |
| 331 void GetAvailDictionaryList(const GURL& target_url, std::string* list); | 264 void GetAvailDictionaryList(const GURL& target_url, std::string* list); |
| 332 | 265 |
| 333 // Construct the pair of hashes for client and server to identify an SDCH | 266 // Construct the pair of hashes for client and server to identify an SDCH |
| 334 // dictionary. This is only made public to facilitate unit testing, but is | 267 // dictionary. This is only made public to facilitate unit testing, but is |
| 335 // otherwise private | 268 // otherwise private |
| 336 static void GenerateHash(const std::string& dictionary_text, | 269 static void GenerateHash(const std::string& dictionary_text, |
| 337 std::string* client_hash, std::string* server_hash); | 270 std::string* client_hash, std::string* server_hash); |
| 338 | 271 |
| 339 // For Latency testing only, we need to know if we've succeeded in doing a | 272 // For Latency testing only, we need to know if we've succeeded in doing a |
| 340 // round trip before starting our comparative tests. If ever we encounter | 273 // round trip before starting our comparative tests. If ever we encounter |
| 341 // problems with SDCH, we opt-out of the test unless/until we perform a | 274 // problems with SDCH, we opt-out of the test unless/until we perform a |
| 342 // complete SDCH decoding. | 275 // complete SDCH decoding. |
| 343 bool AllowLatencyExperiment(const GURL& url) const; | 276 bool AllowLatencyExperiment(const GURL& url) const; |
| 344 | 277 |
| 345 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 278 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
| 346 | 279 |
| 280 base::Value* SdchInfoToValue() const; | |
| 281 | |
| 347 int GetFetchesCountForTesting() const { | 282 int GetFetchesCountForTesting() const { |
| 348 return fetches_count_for_testing_; | 283 return fetches_count_for_testing_; |
| 349 } | 284 } |
| 350 | 285 |
| 351 // Implementation of SdchFetcher::Delegate. | 286 // Implementation of SdchFetcher::Delegate. |
| 352 | 287 |
| 353 // Add an SDCH dictionary to our list of availible | 288 // Add an SDCH dictionary to our list of availible |
| 354 // dictionaries. This addition will fail if addition is illegal | 289 // dictionaries. This addition will fail if addition is illegal |
| 355 // (data in the dictionary is not acceptable from the | 290 // (data in the dictionary is not acceptable from the |
| 356 // dictionary_url; dictionary already added, etc.). | 291 // dictionary_url; dictionary already added, etc.). |
| 357 virtual void AddSdchDictionary(const std::string& dictionary_text, | 292 virtual void AddSdchDictionary(const std::string& dictionary_text, |
| 358 const GURL& dictionary_url) OVERRIDE; | 293 const GURL& dictionary_url, |
| 294 const BoundNetLog& net_log) OVERRIDE; | |
| 359 | 295 |
| 360 private: | 296 private: |
| 361 struct BlacklistInfo { | 297 struct BlacklistInfo { |
| 362 BlacklistInfo() | 298 BlacklistInfo() : count(0), exponential_count(0), reason(PROBLEM_CODE_OK) {} |
| 363 : count(0), | |
| 364 exponential_count(0), | |
| 365 reason(MIN_PROBLEM_CODE) {} | |
| 366 | 299 |
| 367 int count; // # of times to refuse SDCH advertisement. | 300 int count; // # of times to refuse SDCH advertisement. |
| 368 int exponential_count; // Current exponential backoff ratchet. | 301 int exponential_count; // Current exponential backoff ratchet. |
| 369 ProblemCodes reason; // Why domain was blacklisted. | 302 ProblemCodes reason; // Why domain was blacklisted. |
| 370 | 303 |
| 371 }; | 304 }; |
| 372 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo; | 305 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo; |
| 373 typedef std::set<std::string> ExperimentSet; | 306 typedef std::set<std::string> ExperimentSet; |
| 374 | 307 |
| 375 // A map of dictionaries info indexed by the hash that the server provides. | 308 // A map of dictionaries info indexed by the hash that the server provides. |
| 376 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; | 309 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; |
| 377 | 310 |
| 378 // Support SDCH compression, by advertising in headers. | 311 // Support SDCH compression, by advertising in headers. |
| 379 static bool g_sdch_enabled_; | 312 static bool g_sdch_enabled_; |
| 380 | 313 |
| 381 // Support SDCH compression for HTTPS requests and responses. When supported, | 314 // Support SDCH compression for HTTPS requests and responses. When supported, |
| 382 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. | 315 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. |
| 383 static bool g_secure_scheme_supported_; | 316 static bool g_secure_scheme_supported_; |
| 384 | 317 |
| 385 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. | 318 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. |
| 386 static void UrlSafeBase64Encode(const std::string& input, | 319 static void UrlSafeBase64Encode(const std::string& input, |
| 387 std::string* output); | 320 std::string* output); |
| 321 | |
| 322 // Helper function to write histogram and add event to net log. | |
| 323 static void LogDictionaryError(ProblemCodes error, | |
| 324 const GURL& url, | |
| 325 bool is_error, | |
| 326 const BoundNetLog& net_log); | |
| 327 | |
| 388 DictionaryMap dictionaries_; | 328 DictionaryMap dictionaries_; |
| 389 | 329 |
| 390 // An instance that can fetch a dictionary given a URL. | 330 // An instance that can fetch a dictionary given a URL. |
| 391 scoped_ptr<SdchFetcher> fetcher_; | 331 scoped_ptr<SdchFetcher> fetcher_; |
| 392 | 332 |
| 393 // List domains where decode failures have required disabling sdch. | 333 // List domains where decode failures have required disabling sdch. |
| 394 DomainBlacklistInfo blacklisted_domains_; | 334 DomainBlacklistInfo blacklisted_domains_; |
| 395 | 335 |
| 396 // List of hostnames for which a latency experiment is allowed (because a | 336 // List of hostnames for which a latency experiment is allowed (because a |
| 397 // round trip test has recently passed). | 337 // round trip test has recently passed). |
| 398 ExperimentSet allow_latency_experiment_; | 338 ExperimentSet allow_latency_experiment_; |
| 399 | 339 |
| 400 int fetches_count_for_testing_; | 340 int fetches_count_for_testing_; |
| 401 | 341 |
| 402 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 342 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
| 403 }; | 343 }; |
| 404 | 344 |
| 405 } // namespace net | 345 } // namespace net |
| 406 | 346 |
| 407 #endif // NET_BASE_SDCH_MANAGER_H_ | 347 #endif // NET_BASE_SDCH_MANAGER_H_ |
| OLD | NEW |