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

Unified Diff: net/base/sdch_manager.h

Issue 711753003: Pin dictionaries from being deleted while request is outstanding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated comments; fixed try job errors. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/sdch_manager.cc » ('j') | net/base/sdch_manager.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/sdch_manager.h
diff --git a/net/base/sdch_manager.h b/net/base/sdch_manager.h
index ff157e52a32e1cb04e955f467b3c524cba11b6a7..15769b7aa10df18d5211ff30b2e8917c15a5fafd 100644
--- a/net/base/sdch_manager.h
+++ b/net/base/sdch_manager.h
@@ -8,6 +8,7 @@
#include <map>
#include <set>
#include <string>
+#include <vector>
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
@@ -35,10 +36,12 @@ class SdchObserver;
// module) to decompress data.
class NET_EXPORT SdchManager {
public:
+ class DictionarySet;
+
// A list of errors that appeared and were either resolved, or used to turn
// off sdch encoding.
enum ProblemCodes {
- MIN_PROBLEM_CODE,
+ OK,
Ryan Sleevi 2014/11/14 03:21:25 NO_PROBLEM? (to avoid confusion with net::OK)
Randy Smith (Not in Mondays) 2014/11/17 17:04:22 I'm going to say that this issue will be moot by t
// Content-encoding correction problems.
ADDED_CONTENT_ENCODING = 1,
@@ -89,11 +92,14 @@ class NET_EXPORT SdchManager {
// 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,
+ // A dictionary that wasn't advertised is being used for decoding.
+ UNADVERTISED_SDCH_DICTIONARY_USED = 52,
+ UNADVERTISED_SDCH_DICTIONARY_USED_CACHED = 53,
+
// Dictionary manager issues.
DOMAIN_BLACKLIST_INCLUDES_TARGET = 61,
@@ -142,16 +148,8 @@ class NET_EXPORT SdchManager {
// There is one instance of |Dictionary| for each memory-cached SDCH
// dictionary.
Ryan Sleevi 2014/11/14 03:21:25 Is this still true? By making this public, you cre
Randy Smith (Not in Mondays) 2014/11/17 17:04:21 Completely fair; now consumers can create their ow
- class NET_EXPORT_PRIVATE Dictionary : public base::RefCounted<Dictionary> {
+ class NET_EXPORT_PRIVATE Dictionary {
public:
- // Sdch filters can get our text to use in decoding compressed data.
- const std::string& text() const { return text_; }
-
- private:
- friend class base::RefCounted<Dictionary>;
- friend class SdchManager; // Only manager can construct an instance.
- FRIEND_TEST_ALL_PREFIXES(SdchManagerTest, PathMatch);
-
// Construct a vc-diff usable dictionary from the dictionary_text starting
// at the given offset. The supplied client_hash should be used to
// advertise the dictionary's availability relative to the suppplied URL.
@@ -165,21 +163,21 @@ class NET_EXPORT SdchManager {
const std::set<int>& ports);
virtual ~Dictionary();
+ // Sdch filters can get our text to use in decoding compressed data.
+ const std::string& text() const { return text_; }
+
const GURL& url() const { return url_; }
const std::string& client_hash() const { return client_hash_; }
- // 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);
-
// 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);
- // 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);
+ // Security method to check if a dictionary is appropriate to use
+ // with the given URL. Does not check expiration (it's appropriate to
Ryan Sleevi 2014/11/14 03:21:25 single space
Randy Smith (Not in Mondays) 2014/11/17 17:04:22 :-}. Done (through file).
+ // use dictionaries that were expired while a request is outstanding).
+ SdchManager::ProblemCodes CanUse(const GURL& target_url);
// Compare paths to see if they "match" for dictionary use.
static bool PathMatch(const std::string& path,
@@ -188,7 +186,10 @@ class NET_EXPORT SdchManager {
// Compare domains to see if the "match" for dictionary use.
static bool DomainMatch(const GURL& url, const std::string& restriction);
+ // Is this dictionary expired?
+ bool Expired() const;
+ private:
// The actual text of the dictionary.
std::string text_;
@@ -211,6 +212,59 @@ class NET_EXPORT SdchManager {
DISALLOW_COPY_AND_ASSIGN(Dictionary);
};
+ // Implementation type relevant for the private data members of
+ // DictionarySet and SdchManager. This class should not be used
+ // outside of sdch_manager.*.
+ class DictionaryWrapper : public base::RefCounted<DictionaryWrapper> {
Ryan Sleevi 2014/11/14 03:21:25 Why not just RefCountedData? https://code.google.c
Randy Smith (Not in Mondays) 2014/11/17 17:04:21 Cool; thanks for pointing that type out to me. Th
+ public:
+ typedef std::map<std::string, scoped_refptr<DictionaryWrapper> >
+ DictionaryMap;
Ryan Sleevi 2014/11/14 03:21:25 Why is this a typedef on the Wrapper? Seems to be
Randy Smith (Not in Mondays) 2014/11/17 17:04:21 Yeah, that's fair. I was trying to avoid having t
+
+ explicit DictionaryWrapper(scoped_ptr<Dictionary> dictionary);
+ Dictionary* dictionary() { return dictionary_.get(); }
+
+ private:
+ friend class base::RefCounted<DictionaryWrapper>;
+ ~DictionaryWrapper();
+
+ scoped_ptr<SdchManager::Dictionary> dictionary_;
+
+ DISALLOW_COPY_AND_ASSIGN(DictionaryWrapper);
+ };
+
+ // A handle for one or more dictionaries which will keep the dictionaries
+ // alive and accessible for the handle's lifetime.
+ class NET_EXPORT_PRIVATE DictionarySet {
+ public:
+ ~DictionarySet();
+
+ // Append a comma separated list of client hashes onto the end
+ // of |client_hashes|.
+ void GetDictionaryClientHashList(std::string* client_hashes) const;
Ryan Sleevi 2014/11/14 03:21:25 Why do you append, rather than just returning the
Randy Smith (Not in Mondays) 2014/11/17 17:04:21 I think I was instinctively trying to avoid the pe
+
+ // Lookup a given dictionary based on server hash. Returned pointer
+ // is guaranteed to be valid for the lifetime of the DictionarySet.
+ // Returns NULL if hash is not a valid server hash for a dictionary
+ // named by DictionarySet.
+ const SdchManager::Dictionary* Dictionary(const std::string& hash) const;
Ryan Sleevi 2014/11/14 03:21:25 Should you return a const-ref then? That usually h
Randy Smith (Not in Mondays) 2014/11/17 17:04:22 I like that idea, and I agree that interface would
+
+ bool Empty() const;
+
+ private:
+ // A DictionarySet may only be constructed by the SdchManager.
+ friend class SdchManager;
+
+ static const char* kSdchDictionariesHandleDataKey;
Ryan Sleevi 2014/11/14 03:21:25 private static? seems unnecessary?
Randy Smith (Not in Mondays) 2014/11/17 17:04:22 Whoops; serious leftover. Gone.
+
+ DictionarySet();
+ void AddDictionary(const std::string& server_hash,
+ scoped_refptr<DictionaryWrapper> dictionary);
+
+ DictionaryWrapper::DictionaryMap dictionaries_;
+
+ DISALLOW_COPY_AND_ASSIGN(DictionarySet);
+ };
+
SdchManager();
~SdchManager();
@@ -266,20 +320,19 @@ class NET_EXPORT SdchManager {
// header has been seen.
void OnGetDictionary(const GURL& request_url, const GURL& dictionary_url);
- // Find the vcdiff dictionary (the body of the sdch dictionary that appears
- // after the meta-data headers like Domain:...) with the given |server_hash|
- // to use to decompreses data that arrived as SDCH encoded content. Check to
- // 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);
-
- // 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
- // the SDCH spec.
- void GetAvailDictionaryList(const GURL& target_url, std::string* list);
+ // Get a handle to the available dictionaries that might be used
+ // for encoding responses for the given URL. The return set will not
+ // include expired dictionaries. If no dictionaries
+ // are appropriate to use with the target_url, NULL is returned.
+ scoped_ptr<DictionarySet> GetDictionarySet(const GURL& target_url);
+
+ // Get a handle to a specific dictionary, by its server hash, confirming
+ // that that specific dictionary is appropriate to use with |target_url|.
+ // Expired dictionaries will be returned. If no dictionary with that
+ // hash exists that is usable with |target_url|, NULL is returned.
+ scoped_ptr<DictionarySet> GetDictionarySetByHash(
+ const GURL& target_url,
+ const std::string& server_hash);
// Construct the pair of hashes for client and server to identify an SDCH
// dictionary. This is only made public to facilitate unit testing, but is
@@ -306,18 +359,21 @@ class NET_EXPORT SdchManager {
void AddObserver(SdchObserver* observer);
void RemoveObserver(SdchObserver* observer);
+ static scoped_ptr<DictionarySet> CreateNullDictionarySetForTesting();
Ryan Sleevi 2014/11/14 03:21:25 s/Null/Empty/ (as otherwise you'd just return a nu
Randy Smith (Not in Mondays) 2014/11/17 17:04:22 Done.
+
private:
struct BlacklistInfo {
BlacklistInfo()
: count(0),
exponential_count(0),
- reason(MIN_PROBLEM_CODE) {}
+ reason(OK) {}
int count; // # of times to refuse SDCH advertisement.
int exponential_count; // Current exponential backoff ratchet.
ProblemCodes reason; // Why domain was blacklisted.
};
+
typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo;
typedef std::set<std::string> ExperimentSet;
@@ -327,9 +383,6 @@ class NET_EXPORT SdchManager {
bool CanFetchDictionary(const GURL& referring_url,
const GURL& dictionary_url) const;
- // A map of dictionaries info indexed by the hash that the server provides.
- typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap;
-
// Support SDCH compression, by advertising in headers.
static bool g_sdch_enabled_;
@@ -340,7 +393,8 @@ 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_;
+
+ DictionaryWrapper::DictionaryMap dictionaries_;
Ryan Sleevi 2014/11/14 03:21:25 see comment re: DictionaryMap typedef
Randy Smith (Not in Mondays) 2014/11/17 17:04:21 Moot.
// List domains where decode failures have required disabling sdch.
DomainBlacklistInfo blacklisted_domains_;
« no previous file with comments | « no previous file | net/base/sdch_manager.cc » ('j') | net/base/sdch_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698