Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Side by Side Diff: net/base/sdch_manager.h

Issue 642403002: git cl format the first third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // The Cancel() method is called to cancel all pending dictionary fetches. 64 // The Cancel() method is called to cancel all pending dictionary fetches.
65 // This is used for implementation of ClearData() below. 65 // This is used for implementation of ClearData() below.
66 virtual void Cancel() = 0; 66 virtual void Cancel() = 0;
67 67
68 private: 68 private:
69 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); 69 DISALLOW_COPY_AND_ASSIGN(SdchFetcher);
70 }; 70 };
71 71
72 //------------------------------------------------------------------------------ 72 //------------------------------------------------------------------------------
73 73
74 class NET_EXPORT SdchManager 74 class NET_EXPORT SdchManager : public SdchFetcher::Delegate,
75 : public SdchFetcher::Delegate, 75 public NON_EXPORTED_BASE(base::NonThreadSafe) {
76 public NON_EXPORTED_BASE(base::NonThreadSafe) {
77 public: 76 public:
78 // A list of errors that appeared and were either resolved, or used to turn 77 // A list of errors that appeared and were either resolved, or used to turn
79 // off sdch encoding. 78 // off sdch encoding.
80 enum ProblemCodes { 79 enum ProblemCodes {
81 MIN_PROBLEM_CODE, 80 MIN_PROBLEM_CODE,
82 81
83 // Content-encoding correction problems. 82 // Content-encoding correction problems.
84 ADDED_CONTENT_ENCODING = 1, 83 ADDED_CONTENT_ENCODING = 1,
85 FIXED_CONTENT_ENCODING = 2, 84 FIXED_CONTENT_ENCODING = 2,
86 FIXED_CONTENT_ENCODINGS = 3, 85 FIXED_CONTENT_ENCODINGS = 3,
(...skipping 26 matching lines...) Expand all
113 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24, 112 DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24,
114 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25, 113 DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25,
115 DICTIONARY_HAS_NO_TEXT = 26, 114 DICTIONARY_HAS_NO_TEXT = 26,
116 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27, 115 DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27,
117 116
118 // Dictionary loading problems. 117 // Dictionary loading problems.
119 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30, 118 DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30,
120 DICTIONARY_SELECTED_FOR_SSL = 31, 119 DICTIONARY_SELECTED_FOR_SSL = 31,
121 DICTIONARY_ALREADY_LOADED = 32, 120 DICTIONARY_ALREADY_LOADED = 32,
122 DICTIONARY_SELECTED_FROM_NON_HTTP = 33, 121 DICTIONARY_SELECTED_FROM_NON_HTTP = 33,
123 DICTIONARY_IS_TOO_LARGE= 34, 122 DICTIONARY_IS_TOO_LARGE = 34,
124 DICTIONARY_COUNT_EXCEEDED = 35, 123 DICTIONARY_COUNT_EXCEEDED = 35,
125 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36, 124 DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36,
126 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37, 125 DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37,
127 DICTIONARY_FETCH_READ_FAILED = 38, 126 DICTIONARY_FETCH_READ_FAILED = 38,
128 127
129 // Failsafe hack. 128 // Failsafe hack.
130 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40, 129 ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40,
131 130
132
133 // Content-Encoding problems detected, with no action taken. 131 // Content-Encoding problems detected, with no action taken.
134 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50, 132 MULTIENCODING_FOR_NON_SDCH_REQUEST = 50,
135 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51, 133 SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51,
136 134
137 // Dictionary manager issues. 135 // Dictionary manager issues.
138 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61, 136 DOMAIN_BLACKLIST_INCLUDES_TARGET = 61,
139 137
140 // Problematic decode recovery methods. 138 // Problematic decode recovery methods.
141 META_REFRESH_RECOVERY = 70, // Dictionary not found. 139 META_REFRESH_RECOVERY = 70, // Dictionary not found.
142 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED. 140 // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED.
143 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED. 141 // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED.
144 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus 142 // defunct = 73, // PASSING_THROUGH_NON_SDCH plus
145 // RESPONSE_TENTATIVE_SDCH in ../filter/sdch_filter.cc. 143 // RESPONSE_TENTATIVE_SDCH in ../filter/sdch_filter.cc.
Ryan Sleevi 2014/10/11 02:04:47 BUG in clang-format
jkarlin 2014/10/16 00:19:32 You think? It seems like it's asking a bit much t
jkarlin 2014/11/11 19:01:44 Fixed by adding whitespace.
146 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error. 144 META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error.
147 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache. 145 CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache.
148 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash. 146 PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash.
149 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded. 147 INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded.
150 PASS_THROUGH_404_CODE = 78, // URL not found message passing through. 148 PASS_THROUGH_404_CODE = 78, // URL not found message passing through.
151 149
152 // This next report is very common, and not really an error scenario, but 150 // This next report is very common, and not really an error scenario, but
153 // it exercises the error recovery logic. 151 // it exercises the error recovery logic.
154 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content. 152 PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content.
155 153
156 // Common decoded recovery methods. 154 // Common decoded recovery methods.
157 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading. 155 META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading.
158 // defunct = 81, // Now tracked by ResponseCorruptionDetectionCause histo. 156 // defunct = 81, // Now tracked by ResponseCorruptionDetectionCause histo.
159 157
160 // Non SDCH problems, only accounted for to make stat counting complete 158 // Non SDCH problems, only accounted for to make stat counting complete
161 // (i.e., be able to be sure all dictionary advertisements are accounted 159 // (i.e., be able to be sure all dictionary advertisements are accounted
162 // for). 160 // for).
163 161
164 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining. 162 UNFLUSHED_CONTENT = 90, // Possible error in filter chaining.
165 // defunct = 91, // MISSING_TIME_STATS (Should never happen.) 163 // defunct = 91, // MISSING_TIME_STATS (Should never happen.)
166 CACHE_DECODED = 92, // No timing stats recorded. 164 CACHE_DECODED = 92, // No timing stats recorded.
Ryan Sleevi 2014/10/11 02:04:47 bug in clang-format
jkarlin 2014/10/16 00:19:32 ditto
jkarlin 2014/11/11 19:01:44 It would be nice if it lined up better but it seem
167 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.) 165 // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.)
168 UNINITIALIZED = 94, // Filter never even got initialized. 166 UNINITIALIZED = 94, // Filter never even got initialized.
169 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector. 167 PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector.
170 DECODE_ERROR = 96, // Something went wrong during decode. 168 DECODE_ERROR = 96, // Something went wrong during decode.
171 169
172 // Problem during the latency test. 170 // Problem during the latency test.
173 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before! 171 LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before!
174 172
175 MAX_PROBLEM_CODE // Used to bound histogram. 173 MAX_PROBLEM_CODE // Used to bound histogram.
176 }; 174 };
(...skipping 30 matching lines...) Expand all
207 205
208 const GURL& url() const { return url_; } 206 const GURL& url() const { return url_; }
209 const std::string& client_hash() const { return client_hash_; } 207 const std::string& client_hash() const { return client_hash_; }
210 208
211 // Security method to check if we can advertise this dictionary for use 209 // Security method to check if we can advertise this dictionary for use
212 // if the |target_url| returns SDCH compressed data. 210 // if the |target_url| returns SDCH compressed data.
213 bool CanAdvertise(const GURL& target_url); 211 bool CanAdvertise(const GURL& target_url);
214 212
215 // Security methods to check if we can establish a new dictionary with the 213 // Security methods to check if we can establish a new dictionary with the
216 // given data, that arrived in response to get of dictionary_url. 214 // given data, that arrived in response to get of dictionary_url.
217 static bool CanSet(const std::string& domain, const std::string& path, 215 static bool CanSet(const std::string& domain,
218 const std::set<int>& ports, const GURL& dictionary_url); 216 const std::string& path,
217 const std::set<int>& ports,
218 const GURL& dictionary_url);
219 219
220 // 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
221 // target that arrived with a reference to this dictionary. 221 // target that arrived with a reference to this dictionary.
222 bool CanUse(const GURL& referring_url); 222 bool CanUse(const GURL& referring_url);
223 223
224 // Compare paths to see if they "match" for dictionary use. 224 // Compare paths to see if they "match" for dictionary use.
225 static bool PathMatch(const std::string& path, 225 static bool PathMatch(const std::string& path,
226 const std::string& restriction); 226 const std::string& restriction);
227 227
228 // Compare domains to see if the "match" for dictionary use. 228 // Compare domains to see if the "match" for dictionary use.
229 static bool DomainMatch(const GURL& url, const std::string& restriction); 229 static bool DomainMatch(const GURL& url, const std::string& restriction);
230 230
231
232 // The actual text of the dictionary. 231 // The actual text of the dictionary.
233 std::string text_; 232 std::string text_;
234 233
235 // Part of the hash of text_ that the client uses to advertise the fact that 234 // Part of the hash of text_ that the client uses to advertise the fact that
236 // it has a specific dictionary pre-cached. 235 // it has a specific dictionary pre-cached.
237 std::string client_hash_; 236 std::string client_hash_;
238 237
239 // The GURL that arrived with the text_ in a URL request to specify where 238 // The GURL that arrived with the text_ in a URL request to specify where
240 // this dictionary may be used. 239 // this dictionary may be used.
241 const GURL url_; 240 const GURL url_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 327
329 // Get list of available (pre-cached) dictionaries that we have already loaded 328 // Get list of available (pre-cached) dictionaries that we have already loaded
330 // into memory. The list is a comma separated list of (client) hashes per 329 // into memory. The list is a comma separated list of (client) hashes per
331 // the SDCH spec. 330 // the SDCH spec.
332 void GetAvailDictionaryList(const GURL& target_url, std::string* list); 331 void GetAvailDictionaryList(const GURL& target_url, std::string* list);
333 332
334 // Construct the pair of hashes for client and server to identify an SDCH 333 // Construct the pair of hashes for client and server to identify an SDCH
335 // dictionary. This is only made public to facilitate unit testing, but is 334 // dictionary. This is only made public to facilitate unit testing, but is
336 // otherwise private 335 // otherwise private
337 static void GenerateHash(const std::string& dictionary_text, 336 static void GenerateHash(const std::string& dictionary_text,
338 std::string* client_hash, std::string* server_hash); 337 std::string* client_hash,
338 std::string* server_hash);
339 339
340 // 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
341 // round trip before starting our comparative tests. If ever we encounter 341 // round trip before starting our comparative tests. If ever we encounter
342 // 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
343 // complete SDCH decoding. 343 // complete SDCH decoding.
344 bool AllowLatencyExperiment(const GURL& url) const; 344 bool AllowLatencyExperiment(const GURL& url) const;
345 345
346 void SetAllowLatencyExperiment(const GURL& url, bool enable); 346 void SetAllowLatencyExperiment(const GURL& url, bool enable);
347 347
348 int GetFetchesCountForTesting() const { 348 int GetFetchesCountForTesting() const { return fetches_count_for_testing_; }
349 return fetches_count_for_testing_;
350 }
351 349
352 // Implementation of SdchFetcher::Delegate. 350 // Implementation of SdchFetcher::Delegate.
353 351
354 // Add an SDCH dictionary to our list of availible 352 // Add an SDCH dictionary to our list of availible
355 // dictionaries. This addition will fail if addition is illegal 353 // dictionaries. This addition will fail if addition is illegal
356 // (data in the dictionary is not acceptable from the 354 // (data in the dictionary is not acceptable from the
357 // dictionary_url; dictionary already added, etc.). 355 // dictionary_url; dictionary already added, etc.).
358 virtual void AddSdchDictionary(const std::string& dictionary_text, 356 virtual void AddSdchDictionary(const std::string& dictionary_text,
359 const GURL& dictionary_url) override; 357 const GURL& dictionary_url) override;
360 358
361 private: 359 private:
362 struct BlacklistInfo { 360 struct BlacklistInfo {
363 BlacklistInfo() 361 BlacklistInfo()
364 : count(0), 362 : count(0), exponential_count(0), reason(MIN_PROBLEM_CODE) {}
365 exponential_count(0),
366 reason(MIN_PROBLEM_CODE) {}
367 363
368 int count; // # of times to refuse SDCH advertisement. 364 int count; // # of times to refuse SDCH advertisement.
369 int exponential_count; // Current exponential backoff ratchet. 365 int exponential_count; // Current exponential backoff ratchet.
370 ProblemCodes reason; // Why domain was blacklisted. 366 ProblemCodes reason; // Why domain was blacklisted.
371
372 }; 367 };
373 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo; 368 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo;
374 typedef std::set<std::string> ExperimentSet; 369 typedef std::set<std::string> ExperimentSet;
375 370
376 // A map of dictionaries info indexed by the hash that the server provides. 371 // A map of dictionaries info indexed by the hash that the server provides.
377 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; 372 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap;
378 373
379 // Support SDCH compression, by advertising in headers. 374 // Support SDCH compression, by advertising in headers.
380 static bool g_sdch_enabled_; 375 static bool g_sdch_enabled_;
381 376
(...skipping 17 matching lines...) Expand all
399 ExperimentSet allow_latency_experiment_; 394 ExperimentSet allow_latency_experiment_;
400 395
401 int fetches_count_for_testing_; 396 int fetches_count_for_testing_;
402 397
403 DISALLOW_COPY_AND_ASSIGN(SdchManager); 398 DISALLOW_COPY_AND_ASSIGN(SdchManager);
404 }; 399 };
405 400
406 } // namespace net 401 } // namespace net
407 402
408 #endif // NET_BASE_SDCH_MANAGER_H_ 403 #endif // NET_BASE_SDCH_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698