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 // |
11 // The SdchManager maintains a collection of memory resident dictionaries. It | 11 // The SdchManager maintains a collection of memory resident dictionaries. It |
12 // can find a dictionary (based on a server specification of a hash), store a | 12 // can find a dictionary (based on a server specification of a hash), store a |
13 // dictionary, and make judgements about what URLs can use, set, etc. a | 13 // dictionary, and make judgements about what URLs can use, set, etc. a |
14 // dictionary. | 14 // dictionary. |
15 | 15 |
16 // These dictionaries are acquired over the net, and include a header | 16 // These dictionaries are acquired over the net, and include a header |
17 // (containing metadata) as well as a VCDIFF dictionary (for use by a VCDIFF | 17 // (containing metadata) as well as a VCDIFF dictionary (for use by a VCDIFF |
18 // module) to decompress data. | 18 // module) to decompress data. |
19 | 19 |
20 #ifndef NET_BASE_SDCH_MANAGER_H_ | 20 #ifndef NET_BASE_SDCH_MANAGER_H_ |
21 #define NET_BASE_SDCH_MANAGER_H_ | 21 #define NET_BASE_SDCH_MANAGER_H_ |
22 | 22 |
23 #include <map> | 23 #include <map> |
24 #include <set> | 24 #include <set> |
25 #include <string> | 25 #include <string> |
| 26 #include <vector> |
26 | 27 |
27 #include "base/gtest_prod_util.h" | 28 #include "base/gtest_prod_util.h" |
28 #include "base/memory/ref_counted.h" | 29 #include "base/memory/ref_counted.h" |
29 #include "base/memory/scoped_ptr.h" | 30 #include "base/memory/scoped_ptr.h" |
30 #include "base/threading/non_thread_safe.h" | 31 #include "base/threading/non_thread_safe.h" |
31 #include "base/time/time.h" | 32 #include "base/time/time.h" |
32 #include "net/base/net_export.h" | 33 #include "net/base/net_export.h" |
33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
34 | 35 |
| 36 namespace base { |
| 37 class Value; |
| 38 class DictionaryValue; |
| 39 } |
| 40 |
35 namespace net { | 41 namespace net { |
36 | 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 functionaity can be provided). | 48 // functionality in this base (when the functionaity can be provided). |
43 class NET_EXPORT SdchFetcher { | 49 class NET_EXPORT SdchFetcher { |
44 public: | 50 public: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 const GURL& url() const { return url_; } | 199 const GURL& url() const { return url_; } |
194 const std::string& client_hash() const { return client_hash_; } | 200 const std::string& client_hash() const { return client_hash_; } |
195 | 201 |
196 // Security method to check if we can advertise this dictionary for use | 202 // Security method to check if we can advertise this dictionary for use |
197 // if the |target_url| returns SDCH compressed data. | 203 // if the |target_url| returns SDCH compressed data. |
198 bool CanAdvertise(const GURL& target_url); | 204 bool CanAdvertise(const GURL& target_url); |
199 | 205 |
200 // Security methods to check if we can establish a new dictionary with the | 206 // Security methods to check if we can establish a new dictionary with the |
201 // given data, that arrived in response to get of dictionary_url. | 207 // given data, that arrived in response to get of dictionary_url. |
202 static bool CanSet(const std::string& domain, const std::string& path, | 208 static bool CanSet(const std::string& domain, const std::string& path, |
203 const std::set<int>& ports, const GURL& dictionary_url); | 209 const std::set<int>& ports, const GURL& dictionary_url, |
| 210 SdchManager* sdch_manager); |
204 | 211 |
205 // Security method to check if we can use a dictionary to decompress a | 212 // Security method to check if we can use a dictionary to decompress a |
206 // target that arrived with a reference to this dictionary. | 213 // target that arrived with a reference to this dictionary. |
207 bool CanUse(const GURL& referring_url); | 214 bool CanUse(const GURL& referring_url, SdchManager* sdch_manager); |
208 | 215 |
209 // Compare paths to see if they "match" for dictionary use. | 216 // Compare paths to see if they "match" for dictionary use. |
210 static bool PathMatch(const std::string& path, | 217 static bool PathMatch(const std::string& path, |
211 const std::string& restriction); | 218 const std::string& restriction); |
212 | 219 |
213 // Compare domains to see if the "match" for dictionary use. | 220 // Compare domains to see if the "match" for dictionary use. |
214 static bool DomainMatch(const GURL& url, const std::string& restriction); | 221 static bool DomainMatch(const GURL& url, const std::string& restriction); |
215 | 222 |
| 223 base::DictionaryValue* DictionaryInfoToValue() const; |
216 | 224 |
217 // The actual text of the dictionary. | 225 // The actual text of the dictionary. |
218 std::string text_; | 226 std::string text_; |
219 | 227 |
220 // Part of the hash of text_ that the client uses to advertise the fact that | 228 // Part of the hash of text_ that the client uses to advertise the fact that |
221 // it has a specific dictionary pre-cached. | 229 // it has a specific dictionary pre-cached. |
222 std::string client_hash_; | 230 std::string client_hash_; |
223 | 231 |
224 // The GURL that arrived with the text_ in a URL request to specify where | 232 // The GURL that arrived with the text_ in a URL request to specify where |
225 // this dictionary may be used. | 233 // this dictionary may be used. |
(...skipping 10 matching lines...) Expand all Loading... |
236 DISALLOW_COPY_AND_ASSIGN(Dictionary); | 244 DISALLOW_COPY_AND_ASSIGN(Dictionary); |
237 }; | 245 }; |
238 | 246 |
239 SdchManager(); | 247 SdchManager(); |
240 ~SdchManager(); | 248 ~SdchManager(); |
241 | 249 |
242 // Clear data (for browser data removal). | 250 // Clear data (for browser data removal). |
243 void ClearData(); | 251 void ClearData(); |
244 | 252 |
245 // Record stats on various errors. | 253 // Record stats on various errors. |
246 static void SdchErrorRecovery(ProblemCodes problem); | 254 void SdchErrorRecovery(ProblemCodes problem, const GURL& url) const; |
247 | 255 |
248 // Register a fetcher that this class can use to obtain dictionaries. | 256 // Register a fetcher that this class can use to obtain dictionaries. |
249 void set_sdch_fetcher(SdchFetcher* fetcher); | 257 void set_sdch_fetcher(SdchFetcher* fetcher); |
250 | 258 |
251 // Enables or disables SDCH compression. | 259 // Enables or disables SDCH compression. |
252 static void EnableSdchSupport(bool enabled); | 260 static void EnableSdchSupport(bool enabled); |
253 | 261 |
254 static bool sdch_enabled() { return g_sdch_enabled_; } | 262 static bool sdch_enabled() { return g_sdch_enabled_; } |
255 | 263 |
256 // Enables or disables SDCH compression over secure connection. | 264 // Enables or disables SDCH compression over secure connection. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 std::string* client_hash, std::string* server_hash); | 337 std::string* client_hash, std::string* server_hash); |
330 | 338 |
331 // For Latency testing only, we need to know if we've succeeded in doing a | 339 // For Latency testing only, we need to know if we've succeeded in doing a |
332 // round trip before starting our comparative tests. If ever we encounter | 340 // round trip before starting our comparative tests. If ever we encounter |
333 // problems with SDCH, we opt-out of the test unless/until we perform a | 341 // problems with SDCH, we opt-out of the test unless/until we perform a |
334 // complete SDCH decoding. | 342 // complete SDCH decoding. |
335 bool AllowLatencyExperiment(const GURL& url) const; | 343 bool AllowLatencyExperiment(const GURL& url) const; |
336 | 344 |
337 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 345 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
338 | 346 |
| 347 base::Value* SdchInfoToValue() const; |
| 348 |
339 private: | 349 private: |
340 typedef std::map<std::string, int> DomainCounter; | 350 typedef std::map<std::string, int> DomainCounter; |
341 typedef std::set<std::string> ExperimentSet; | 351 typedef std::set<std::string> ExperimentSet; |
342 | 352 |
343 // A map of dictionaries info indexed by the hash that the server provides. | 353 // A map of dictionaries info indexed by the hash that the server provides. |
344 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; | 354 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; |
345 | 355 |
| 356 // List of urls and encountered SDCH problems. |
| 357 typedef std::vector<std::pair<std::string, ProblemCodes> > Problems; |
| 358 |
346 // Support SDCH compression, by advertising in headers. | 359 // Support SDCH compression, by advertising in headers. |
347 static bool g_sdch_enabled_; | 360 static bool g_sdch_enabled_; |
348 | 361 |
349 // Support SDCH compression for HTTPS requests and responses. When supported, | 362 // Support SDCH compression for HTTPS requests and responses. When supported, |
350 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. | 363 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. |
351 static bool g_secure_scheme_supported_; | 364 static bool g_secure_scheme_supported_; |
352 | 365 |
353 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. | 366 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. |
354 static void UrlSafeBase64Encode(const std::string& input, | 367 static void UrlSafeBase64Encode(const std::string& input, |
355 std::string* output); | 368 std::string* output); |
356 DictionaryMap dictionaries_; | 369 DictionaryMap dictionaries_; |
357 | 370 |
358 // An instance that can fetch a dictionary given a URL. | 371 // An instance that can fetch a dictionary given a URL. |
359 scoped_ptr<SdchFetcher> fetcher_; | 372 scoped_ptr<SdchFetcher> fetcher_; |
360 | 373 |
361 // List domains where decode failures have required disabling sdch, along with | 374 // List domains where decode failures have required disabling sdch, along with |
362 // count of how many additonal uses should be blacklisted. | 375 // count of how many additonal uses should be blacklisted. |
363 DomainCounter blacklisted_domains_; | 376 DomainCounter blacklisted_domains_; |
364 | 377 |
365 // Support exponential backoff in number of domain accesses before | 378 // Support exponential backoff in number of domain accesses before |
366 // blacklisting expires. | 379 // blacklisting expires. |
367 DomainCounter exponential_blacklist_count_; | 380 DomainCounter exponential_blacklist_count_; |
368 | 381 |
369 // List of hostnames for which a latency experiment is allowed (because a | 382 // List of hostnames for which a latency experiment is allowed (because a |
370 // round trip test has recently passed). | 383 // round trip test has recently passed). |
371 ExperimentSet allow_latency_experiment_; | 384 ExperimentSet allow_latency_experiment_; |
372 | 385 |
| 386 mutable Problems problems_; |
| 387 |
373 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 388 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
374 }; | 389 }; |
375 | 390 |
376 } // namespace net | 391 } // namespace net |
377 | 392 |
378 #endif // NET_BASE_SDCH_MANAGER_H_ | 393 #endif // NET_BASE_SDCH_MANAGER_H_ |
OLD | NEW |