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