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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // functionality in this base (when the functionaity can be provided). | 42 // functionality in this base (when the functionaity can be provided). |
43 class SdchFetcher { | 43 class SdchFetcher { |
44 public: | 44 public: |
45 SdchFetcher() {} | 45 SdchFetcher() {} |
46 virtual ~SdchFetcher() {} | 46 virtual ~SdchFetcher() {} |
47 | 47 |
48 // The Schedule() method is called when there is a need to get a dictionary | 48 // The Schedule() method is called when there is a need to get a dictionary |
49 // from a server. The callee is responsible for getting that dictionary_text, | 49 // from a server. The callee is responsible for getting that dictionary_text, |
50 // and then calling back to AddSdchDictionary() to the SdchManager instance. | 50 // and then calling back to AddSdchDictionary() to the SdchManager instance. |
51 virtual void Schedule(const GURL& dictionary_url) = 0; | 51 virtual void Schedule(const GURL& dictionary_url) = 0; |
| 52 |
52 private: | 53 private: |
53 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); | 54 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); |
54 }; | 55 }; |
55 | 56 |
56 //------------------------------------------------------------------------------ | 57 //------------------------------------------------------------------------------ |
57 | 58 |
58 class NET_EXPORT SdchManager : public NON_EXPORTED_BASE(base::NonThreadSafe) { | 59 class NET_EXPORT SdchManager : public NON_EXPORTED_BASE(base::NonThreadSafe) { |
59 public: | 60 public: |
60 // A list of errors that appeared and were either resolved, or used to turn | 61 // A list of errors that appeared and were either resolved, or used to turn |
61 // off sdch encoding. | 62 // off sdch encoding. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24, | 96 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24, |
96 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25, | 97 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25, |
97 DICTIONARY_HAS_NO_TEXT = 26, | 98 DICTIONARY_HAS_NO_TEXT = 26, |
98 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27, | 99 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27, |
99 | 100 |
100 // Dictionary loading problems. | 101 // Dictionary loading problems. |
101 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30, | 102 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30, |
102 DICTIONARY_SELECTED_FOR_SSL = 31, | 103 DICTIONARY_SELECTED_FOR_SSL = 31, |
103 DICTIONARY_ALREADY_LOADED = 32, | 104 DICTIONARY_ALREADY_LOADED = 32, |
104 DICTIONARY_SELECTED_FROM_NON_HTTP = 33, | 105 DICTIONARY_SELECTED_FROM_NON_HTTP = 33, |
105 DICTIONARY_IS_TOO_LARGE= 34, | 106 DICTIONARY_IS_TOO_LARGE = 34, |
106 DICTIONARY_COUNT_EXCEEDED = 35, | 107 DICTIONARY_COUNT_EXCEEDED = 35, |
107 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36, | 108 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36, |
108 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37, | 109 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37, |
109 | 110 |
110 // Failsafe hack. | 111 // Failsafe hack. |
111 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40, | 112 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40, |
112 | 113 |
113 | |
114 // Content-Encoding problems detected, with no action taken. | 114 // Content-Encoding problems detected, with no action taken. |
115 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50, | 115 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50, |
116 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51, | 116 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51, |
117 | 117 |
118 // Dictionary manager issues. | 118 // Dictionary manager issues. |
119 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61, | 119 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61, |
120 | 120 |
121 // Problematic decode recovery methods. | 121 // Problematic decode recovery methods. |
122 META_REFRESH_RECOVERY = 70, // Dictionary not found. | 122 META_REFRESH_RECOVERY = 70, // Dictionary not found. |
123 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED. | 123 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED. |
124 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED. | 124 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED. |
125 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus DISCARD_TENTATIVE_SDCH. | 125 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus DISCARD_TENTATIVE_SDCH. |
126 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error. | 126 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error. |
127 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache. | 127 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache. |
128 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash. | 128 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash. |
129 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded. | 129 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded. |
130 PASS_THROUGH_404_CODE = 78, // URL not found message passing through. | 130 PASS_THROUGH_404_CODE = 78, // URL not found message passing through. |
131 | 131 |
132 // This next report is very common, and not really an error scenario, but | 132 // This next report is very common, and not really an error scenario, but |
133 // it exercises the error recovery logic. | 133 // it exercises the error recovery logic. |
134 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content. | 134 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content. |
135 | 135 |
136 // Common decoded recovery methods. | 136 // Common decoded recovery methods. |
137 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading. | 137 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading. |
138 DISCARD_TENTATIVE_SDCH = 81, // Server decided not to use sdch. | 138 DISCARD_TENTATIVE_SDCH = 81, // Server decided not to use sdch. |
139 | 139 |
140 // Non SDCH problems, only accounted for to make stat counting complete | 140 // Non SDCH problems, only accounted for to make stat counting complete |
141 // (i.e., be able to be sure all dictionary advertisements are accounted | 141 // (i.e., be able to be sure all dictionary advertisements are accounted |
142 // for). | 142 // for). |
143 | 143 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining. |
144 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining. | |
145 // defunct = 91, // MISSING_TIME_STATS (Should never happen.) | 144 // defunct = 91, // MISSING_TIME_STATS (Should never happen.) |
146 CACHE_DECODED = 92, // No timing stats recorded. | 145 CACHE_DECODED = 92, // No timing stats recorded. |
147 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.) | 146 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.) |
148 UNINITIALIZED = 94, // Filter never even got initialized. | 147 UNINITIALIZED = 94, // Filter never even got initialized. |
149 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector. | 148 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector. |
150 DECODE_ERROR = 96, // Something went wrong during decode. | 149 DECODE_ERROR = 96, // Something went wrong during decode. |
151 | 150 |
152 // Problem during the latency test. | 151 // Problem during the latency test. |
153 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before! | 152 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before! |
154 | 153 MAX_PROBLEM_CODE // Used to bound histogram. |
155 MAX_PROBLEM_CODE // Used to bound histogram. | |
156 }; | 154 }; |
157 | 155 |
158 // Use the following static limits to block DOS attacks until we implement | 156 // Use the following static limits to block DOS attacks until we implement |
159 // a cached dictionary evicition strategy. | 157 // a cached dictionary evicition strategy. |
160 static const size_t kMaxDictionarySize; | 158 static const size_t kMaxDictionarySize; |
161 static const size_t kMaxDictionaryCount; | 159 static const size_t kMaxDictionaryCount; |
162 | 160 |
163 // There is one instance of |Dictionary| for each memory-cached SDCH | 161 // There is one instance of |Dictionary| for each memory-cached SDCH |
164 // dictionary. | 162 // dictionary. |
165 class NET_EXPORT_PRIVATE Dictionary : public base::RefCounted<Dictionary> { | 163 class NET_EXPORT_PRIVATE Dictionary : public base::RefCounted<Dictionary> { |
(...skipping 21 matching lines...) Expand all Loading... |
187 | 185 |
188 const GURL& url() const { return url_; } | 186 const GURL& url() const { return url_; } |
189 const std::string& client_hash() const { return client_hash_; } | 187 const std::string& client_hash() const { return client_hash_; } |
190 | 188 |
191 // Security method to check if we can advertise this dictionary for use | 189 // Security method to check if we can advertise this dictionary for use |
192 // if the |target_url| returns SDCH compressed data. | 190 // if the |target_url| returns SDCH compressed data. |
193 bool CanAdvertise(const GURL& target_url); | 191 bool CanAdvertise(const GURL& target_url); |
194 | 192 |
195 // Security methods to check if we can establish a new dictionary with the | 193 // Security methods to check if we can establish a new dictionary with the |
196 // given data, that arrived in response to get of dictionary_url. | 194 // given data, that arrived in response to get of dictionary_url. |
197 static bool CanSet(const std::string& domain, const std::string& path, | 195 static bool CanSet(const std::string& domain, |
198 const std::set<int>& ports, const GURL& dictionary_url); | 196 const std::string& path, |
| 197 const std::set<int>& ports, |
| 198 const GURL& dictionary_url); |
199 | 199 |
200 // Security method to check if we can use a dictionary to decompress a | 200 // Security method to check if we can use a dictionary to decompress a |
201 // target that arrived with a reference to this dictionary. | 201 // target that arrived with a reference to this dictionary. |
202 bool CanUse(const GURL& referring_url); | 202 bool CanUse(const GURL& referring_url); |
203 | 203 |
204 // Compare paths to see if they "match" for dictionary use. | 204 // Compare paths to see if they "match" for dictionary use. |
205 static bool PathMatch(const std::string& path, | 205 static bool PathMatch(const std::string& path, |
206 const std::string& restriction); | 206 const std::string& restriction); |
207 | 207 |
208 // Compare domains to see if the "match" for dictionary use. | 208 // Compare domains to see if the "match" for dictionary use. |
209 static bool DomainMatch(const GURL& url, const std::string& restriction); | 209 static bool DomainMatch(const GURL& url, const std::string& restriction); |
210 | 210 |
211 | |
212 // The actual text of the dictionary. | 211 // The actual text of the dictionary. |
213 std::string text_; | 212 std::string text_; |
214 | 213 |
215 // Part of the hash of text_ that the client uses to advertise the fact that | 214 // Part of the hash of text_ that the client uses to advertise the fact that |
216 // it has a specific dictionary pre-cached. | 215 // it has a specific dictionary pre-cached. |
217 std::string client_hash_; | 216 std::string client_hash_; |
218 | 217 |
219 // The GURL that arrived with the text_ in a URL request to specify where | 218 // The GURL that arrived with the text_ in a URL request to specify where |
220 // this dictionary may be used. | 219 // this dictionary may be used. |
221 const GURL url_; | 220 const GURL url_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 318 |
320 // Get list of available (pre-cached) dictionaries that we have already loaded | 319 // Get list of available (pre-cached) dictionaries that we have already loaded |
321 // into memory. The list is a comma separated list of (client) hashes per | 320 // into memory. The list is a comma separated list of (client) hashes per |
322 // the SDCH spec. | 321 // the SDCH spec. |
323 void GetAvailDictionaryList(const GURL& target_url, std::string* list); | 322 void GetAvailDictionaryList(const GURL& target_url, std::string* list); |
324 | 323 |
325 // Construct the pair of hashes for client and server to identify an SDCH | 324 // Construct the pair of hashes for client and server to identify an SDCH |
326 // dictionary. This is only made public to facilitate unit testing, but is | 325 // dictionary. This is only made public to facilitate unit testing, but is |
327 // otherwise private | 326 // otherwise private |
328 static void GenerateHash(const std::string& dictionary_text, | 327 static void GenerateHash(const std::string& dictionary_text, |
329 std::string* client_hash, std::string* server_hash); | 328 std::string* client_hash, |
| 329 std::string* server_hash); |
330 | 330 |
331 // For Latency testing only, we need to know if we've succeeded in doing a | 331 // 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 | 332 // 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 | 333 // problems with SDCH, we opt-out of the test unless/until we perform a |
334 // complete SDCH decoding. | 334 // complete SDCH decoding. |
335 bool AllowLatencyExperiment(const GURL& url) const; | 335 bool AllowLatencyExperiment(const GURL& url) const; |
336 | 336 |
337 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 337 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
338 | 338 |
339 private: | 339 private: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // List of hostnames for which a latency experiment is allowed (because a | 372 // List of hostnames for which a latency experiment is allowed (because a |
373 // round trip test has recently passed). | 373 // round trip test has recently passed). |
374 ExperimentSet allow_latency_experiment_; | 374 ExperimentSet allow_latency_experiment_; |
375 | 375 |
376 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 376 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
377 }; | 377 }; |
378 | 378 |
379 } // namespace net | 379 } // namespace net |
380 | 380 |
381 #endif // NET_BASE_SDCH_MANAGER_H_ | 381 #endif // NET_BASE_SDCH_MANAGER_H_ |
OLD | NEW |