| Index: net/base/sdch_manager.h
|
| diff --git a/net/base/sdch_manager.h b/net/base/sdch_manager.h
|
| index b5f901b036414bb6cb24e1d4f9ceefb5384a5a87..47f6a1e880d18a809323daef01d616f502abb39c 100644
|
| --- a/net/base/sdch_manager.h
|
| +++ b/net/base/sdch_manager.h
|
| @@ -30,8 +30,13 @@
|
| #include "base/threading/non_thread_safe.h"
|
| #include "base/time/time.h"
|
| #include "net/base/net_export.h"
|
| +#include "net/base/sdch_problem_codes.h"
|
| #include "url/gurl.h"
|
|
|
| +namespace base {
|
| +class Value;
|
| +}
|
| +
|
| namespace net {
|
|
|
| //------------------------------------------------------------------------------
|
| @@ -49,8 +54,9 @@ class NET_EXPORT SdchFetcher {
|
| // Called whenever the SdchFetcher has successfully retrieved a
|
| // dictionary. |dictionary_text| contains the body of the dictionary
|
| // retrieved from |dictionary_url|.
|
| - virtual void AddSdchDictionary(const std::string& dictionary_text,
|
| - const GURL& dictionary_url) = 0;
|
| + virtual SdchProblemCode AddSdchDictionary(
|
| + const std::string& dictionary_text,
|
| + const GURL& dictionary_url) = 0;
|
| };
|
|
|
| SdchFetcher() {}
|
| @@ -59,7 +65,7 @@ class NET_EXPORT SdchFetcher {
|
| // The Schedule() method is called when there is a need to get a dictionary
|
| // from a server. The callee is responsible for getting that dictionary_text,
|
| // and then calling back to AddSdchDictionary() in the Delegate instance.
|
| - virtual void Schedule(const GURL& dictionary_url) = 0;
|
| + virtual bool Schedule(const GURL& dictionary_url) = 0;
|
|
|
| // The Cancel() method is called to cancel all pending dictionary fetches.
|
| // This is used for implementation of ClearData() below.
|
| @@ -75,106 +81,6 @@ class NET_EXPORT SdchManager
|
| : public SdchFetcher::Delegate,
|
| public NON_EXPORTED_BASE(base::NonThreadSafe) {
|
| public:
|
| - // A list of errors that appeared and were either resolved, or used to turn
|
| - // off sdch encoding.
|
| - enum ProblemCodes {
|
| - MIN_PROBLEM_CODE,
|
| -
|
| - // Content-encoding correction problems.
|
| - ADDED_CONTENT_ENCODING = 1,
|
| - FIXED_CONTENT_ENCODING = 2,
|
| - FIXED_CONTENT_ENCODINGS = 3,
|
| -
|
| - // Content decoding errors.
|
| - DECODE_HEADER_ERROR = 4,
|
| - DECODE_BODY_ERROR = 5,
|
| -
|
| - // More content-encoding correction problems.
|
| - OPTIONAL_GUNZIP_ENCODING_ADDED = 6,
|
| -
|
| - // Content encoding correction when we're not even tagged as HTML!?!
|
| - BINARY_ADDED_CONTENT_ENCODING = 7,
|
| - BINARY_FIXED_CONTENT_ENCODING = 8,
|
| - BINARY_FIXED_CONTENT_ENCODINGS = 9,
|
| -
|
| - // Dictionary selection for use problems.
|
| - DICTIONARY_FOUND_HAS_WRONG_DOMAIN = 10,
|
| - DICTIONARY_FOUND_HAS_WRONG_PORT_LIST = 11,
|
| - DICTIONARY_FOUND_HAS_WRONG_PATH = 12,
|
| - DICTIONARY_FOUND_HAS_WRONG_SCHEME = 13,
|
| - DICTIONARY_HASH_NOT_FOUND = 14,
|
| - DICTIONARY_HASH_MALFORMED = 15,
|
| -
|
| - // Dictionary saving problems.
|
| - DICTIONARY_HAS_NO_HEADER = 20,
|
| - DICTIONARY_HEADER_LINE_MISSING_COLON = 21,
|
| - DICTIONARY_MISSING_DOMAIN_SPECIFIER = 22,
|
| - DICTIONARY_SPECIFIES_TOP_LEVEL_DOMAIN = 23,
|
| - DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL = 24,
|
| - DICTIONARY_PORT_NOT_MATCHING_SOURCE_URL = 25,
|
| - DICTIONARY_HAS_NO_TEXT = 26,
|
| - DICTIONARY_REFERER_URL_HAS_DOT_IN_PREFIX = 27,
|
| -
|
| - // Dictionary loading problems.
|
| - DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST = 30,
|
| - DICTIONARY_SELECTED_FOR_SSL = 31,
|
| - DICTIONARY_ALREADY_LOADED = 32,
|
| - DICTIONARY_SELECTED_FROM_NON_HTTP = 33,
|
| - DICTIONARY_IS_TOO_LARGE= 34,
|
| - DICTIONARY_COUNT_EXCEEDED = 35,
|
| - DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD = 36,
|
| - DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD = 37,
|
| - DICTIONARY_FETCH_READ_FAILED = 38,
|
| -
|
| - // Failsafe hack.
|
| - ATTEMPT_TO_DECODE_NON_HTTP_DATA = 40,
|
| -
|
| -
|
| - // Content-Encoding problems detected, with no action taken.
|
| - MULTIENCODING_FOR_NON_SDCH_REQUEST = 50,
|
| - SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST = 51,
|
| -
|
| - // Dictionary manager issues.
|
| - DOMAIN_BLACKLIST_INCLUDES_TARGET = 61,
|
| -
|
| - // Problematic decode recovery methods.
|
| - META_REFRESH_RECOVERY = 70, // Dictionary not found.
|
| - // defunct = 71, // Almost the same as META_REFRESH_UNSUPPORTED.
|
| - // defunct = 72, // Almost the same as CACHED_META_REFRESH_UNSUPPORTED.
|
| - // defunct = 73, // PASSING_THROUGH_NON_SDCH plus
|
| - // RESPONSE_TENTATIVE_SDCH in ../filter/sdch_filter.cc.
|
| - META_REFRESH_UNSUPPORTED = 74, // Unrecoverable error.
|
| - CACHED_META_REFRESH_UNSUPPORTED = 75, // As above, but pulled from cache.
|
| - PASSING_THROUGH_NON_SDCH = 76, // Tagged sdch but missing dictionary-hash.
|
| - INCOMPLETE_SDCH_CONTENT = 77, // Last window was not completely decoded.
|
| - PASS_THROUGH_404_CODE = 78, // URL not found message passing through.
|
| -
|
| - // This next report is very common, and not really an error scenario, but
|
| - // it exercises the error recovery logic.
|
| - PASS_THROUGH_OLD_CACHED = 79, // Back button got pre-SDCH cached content.
|
| -
|
| - // Common decoded recovery methods.
|
| - META_REFRESH_CACHED_RECOVERY = 80, // Probably startup tab loading.
|
| - // defunct = 81, // Now tracked by ResponseCorruptionDetectionCause histo.
|
| -
|
| - // Non SDCH problems, only accounted for to make stat counting complete
|
| - // (i.e., be able to be sure all dictionary advertisements are accounted
|
| - // for).
|
| -
|
| - UNFLUSHED_CONTENT = 90, // Possible error in filter chaining.
|
| - // defunct = 91, // MISSING_TIME_STATS (Should never happen.)
|
| - CACHE_DECODED = 92, // No timing stats recorded.
|
| - // defunct = 93, // OVER_10_MINUTES (No timing stats recorded.)
|
| - UNINITIALIZED = 94, // Filter never even got initialized.
|
| - PRIOR_TO_DICTIONARY = 95, // We hadn't even parsed a dictionary selector.
|
| - DECODE_ERROR = 96, // Something went wrong during decode.
|
| -
|
| - // Problem during the latency test.
|
| - LATENCY_TEST_DISALLOWED = 100, // SDCH now failing, but it worked before!
|
| -
|
| - MAX_PROBLEM_CODE // Used to bound histogram.
|
| - };
|
| -
|
| // Use the following static limits to block DOS attacks until we implement
|
| // a cached dictionary evicition strategy.
|
| static const size_t kMaxDictionarySize;
|
| @@ -207,19 +113,25 @@ class NET_EXPORT SdchManager
|
|
|
| const GURL& url() const { return url_; }
|
| const std::string& client_hash() const { return client_hash_; }
|
| + const std::string& domain() const { return domain_; }
|
| + const std::string& path() const { return path_; }
|
| + const base::Time& expiration() const { return expiration_; }
|
| + const std::set<int>& ports() const { return ports_; }
|
|
|
| // Security method to check if we can advertise this dictionary for use
|
| // if the |target_url| returns SDCH compressed data.
|
| - bool CanAdvertise(const GURL& target_url);
|
| + SdchProblemCode CanAdvertise(const GURL& target_url) const;
|
|
|
| // Security methods to check if we can establish a new dictionary with the
|
| // given data, that arrived in response to get of dictionary_url.
|
| - static bool CanSet(const std::string& domain, const std::string& path,
|
| - const std::set<int>& ports, const GURL& dictionary_url);
|
| + static SdchProblemCode CanSet(const std::string& domain,
|
| + const std::string& path,
|
| + const std::set<int>& ports,
|
| + const GURL& dictionary_url);
|
|
|
| // Security method to check if we can use a dictionary to decompress a
|
| // target that arrived with a reference to this dictionary.
|
| - bool CanUse(const GURL& referring_url);
|
| + SdchProblemCode CanUse(const GURL& referring_url) const;
|
|
|
| // Compare paths to see if they "match" for dictionary use.
|
| static bool PathMatch(const std::string& path,
|
| @@ -228,7 +140,6 @@ class NET_EXPORT SdchManager
|
| // Compare domains to see if the "match" for dictionary use.
|
| static bool DomainMatch(const GURL& url, const std::string& restriction);
|
|
|
| -
|
| // The actual text of the dictionary.
|
| std::string text_;
|
|
|
| @@ -258,7 +169,7 @@ class NET_EXPORT SdchManager
|
| void ClearData();
|
|
|
| // Record stats on various errors.
|
| - static void SdchErrorRecovery(ProblemCodes problem);
|
| + static void SdchErrorRecovery(SdchProblemCode problem);
|
|
|
| // Register a fetcher that this class can use to obtain dictionaries.
|
| void set_sdch_fetcher(scoped_ptr<SdchFetcher> fetcher);
|
| @@ -280,11 +191,12 @@ class NET_EXPORT SdchManager
|
| // Used when filter errors are found from a given domain, but it is plausible
|
| // that the cause is temporary (such as application startup, where cached
|
| // entries are used, but a dictionary is not yet loaded).
|
| - void BlacklistDomain(const GURL& url, ProblemCodes blacklist_reason);
|
| + void BlacklistDomain(const GURL& url, SdchProblemCode blacklist_reason);
|
|
|
| // Used when SEVERE filter errors are found from a given domain, to prevent
|
| // further use of SDCH on that domain.
|
| - void BlacklistDomainForever(const GURL& url, ProblemCodes blacklist_reason);
|
| + void BlacklistDomainForever(const GURL& url,
|
| + SdchProblemCode blacklist_reason);
|
|
|
| // Unit test only, this function resets enabling of sdch, and clears the
|
| // blacklist.
|
| @@ -303,18 +215,19 @@ class NET_EXPORT SdchManager
|
| // supported domain (i.e., not blacklisted, and either the specific supported
|
| // domain, or all domains were assumed supported). If it is blacklist, reduce
|
| // by 1 the number of times it will be reported as blacklisted.
|
| - bool IsInSupportedDomain(const GURL& url);
|
| + SdchProblemCode IsInSupportedDomain(const GURL& url);
|
|
|
| // Schedule the URL fetching to load a dictionary. This will always return
|
| // before the dictionary is actually loaded and added.
|
| // After the implied task does completes, the dictionary will have been
|
| // cached in memory.
|
| - void FetchDictionary(const GURL& request_url, const GURL& dictionary_url);
|
| + SdchProblemCode FetchDictionary(const GURL& request_url,
|
| + const GURL& dictionary_url);
|
|
|
| // Security test function used before initiating a FetchDictionary.
|
| - // Return true if fetch is legal.
|
| - bool CanFetchDictionary(const GURL& referring_url,
|
| - const GURL& dictionary_url) const;
|
| + // Return PROBLEM_CODE_OK if fetch is legal.
|
| + SdchProblemCode CanFetchDictionary(const GURL& referring_url,
|
| + const GURL& dictionary_url) const;
|
|
|
| // Find the vcdiff dictionary (the body of the sdch dictionary that appears
|
| // after the meta-data headers like Domain:...) with the given |server_hash|
|
| @@ -322,9 +235,12 @@ class NET_EXPORT SdchManager
|
| // be sure the returned |dictionary| can be used for decoding content supplied
|
| // in response to a request for |referring_url|.
|
| // Return null in |dictionary| if there is no matching legal dictionary.
|
| - void GetVcdiffDictionary(const std::string& server_hash,
|
| - const GURL& referring_url,
|
| - scoped_refptr<Dictionary>* dictionary);
|
| + // Returns SDCH_OK if dictionary is not found, SDCH(-over-https) is disabled,
|
| + // or if matching legal dictionary exists. Otherwise returns the
|
| + // corresponding problem code.
|
| + SdchProblemCode GetVcdiffDictionary(const std::string& server_hash,
|
| + const GURL& referring_url,
|
| + scoped_refptr<Dictionary>* dictionary);
|
|
|
| // Get list of available (pre-cached) dictionaries that we have already loaded
|
| // into memory. The list is a comma separated list of (client) hashes per
|
| @@ -345,6 +261,8 @@ class NET_EXPORT SdchManager
|
|
|
| void SetAllowLatencyExperiment(const GURL& url, bool enable);
|
|
|
| + base::Value* SdchInfoToValue() const;
|
| +
|
| int GetFetchesCountForTesting() const {
|
| return fetches_count_for_testing_;
|
| }
|
| @@ -355,20 +273,18 @@ class NET_EXPORT SdchManager
|
| // dictionaries. This addition will fail if addition is illegal
|
| // (data in the dictionary is not acceptable from the
|
| // dictionary_url; dictionary already added, etc.).
|
| - void AddSdchDictionary(const std::string& dictionary_text,
|
| - const GURL& dictionary_url) override;
|
| + // Returns SDCH_OK if the addition was successfull, and corresponding error
|
| + // code otherwise.
|
| + SdchProblemCode AddSdchDictionary(const std::string& dictionary_text,
|
| + const GURL& dictionary_url) override;
|
|
|
| private:
|
| struct BlacklistInfo {
|
| - BlacklistInfo()
|
| - : count(0),
|
| - exponential_count(0),
|
| - reason(MIN_PROBLEM_CODE) {}
|
| -
|
| - int count; // # of times to refuse SDCH advertisement.
|
| - int exponential_count; // Current exponential backoff ratchet.
|
| - ProblemCodes reason; // Why domain was blacklisted.
|
| + BlacklistInfo() : count(0), exponential_count(0), reason(SDCH_OK) {}
|
|
|
| + int count; // # of times to refuse SDCH advertisement.
|
| + int exponential_count; // Current exponential backoff ratchet.
|
| + SdchProblemCode reason; // Why domain was blacklisted.
|
| };
|
| typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo;
|
| typedef std::set<std::string> ExperimentSet;
|
| @@ -386,6 +302,7 @@ class NET_EXPORT SdchManager
|
| // A simple implementation of a RFC 3548 "URL safe" base64 encoder.
|
| static void UrlSafeBase64Encode(const std::string& input,
|
| std::string* output);
|
| +
|
| DictionaryMap dictionaries_;
|
|
|
| // An instance that can fetch a dictionary given a URL.
|
|
|