OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_BASE_SDCH_DICTIONARY_H_ |
| 6 #define NET_BASE_SDCH_DICTIONARY_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time/time.h" |
| 14 #include "net/base/net_export.h" |
| 15 #include "net/base/sdch_problem_codes.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace base { |
| 19 class Clock; |
| 20 class Value; |
| 21 } |
| 22 |
| 23 namespace net { |
| 24 |
| 25 // Contains all information for an SDCH dictionary. This class is intended |
| 26 // to be used with a RefCountedData<> wrappers. These dictionaries |
| 27 // are vended by SdchManager; see sdch_manager.h for details. |
| 28 class NET_EXPORT_PRIVATE SdchDictionary { |
| 29 public: |
| 30 // Construct a vc-diff usable dictionary from the dictionary_text starting |
| 31 // at the given offset. The supplied client_hash should be used to |
| 32 // advertise the dictionary's availability relative to the suppplied URL. |
| 33 SdchDictionary(const std::string& dictionary_text, |
| 34 size_t offset, |
| 35 const std::string& client_hash, |
| 36 const std::string& server_hash, |
| 37 const GURL& url, |
| 38 const std::string& domain, |
| 39 const std::string& path, |
| 40 const base::Time& expiration, |
| 41 const std::set<int>& ports); |
| 42 |
| 43 ~SdchDictionary(); |
| 44 |
| 45 // Sdch filters can get our text to use in decoding compressed data. |
| 46 const std::string& text() const { return text_; } |
| 47 |
| 48 const GURL& url() const { return url_; } |
| 49 const std::string& client_hash() const { return client_hash_; } |
| 50 const std::string& server_hash() const { return server_hash_; } |
| 51 const std::string& domain() const { return domain_; } |
| 52 const std::string& path() const { return path_; } |
| 53 const base::Time& expiration() const { return expiration_; } |
| 54 const std::set<int>& ports() const { return ports_; } |
| 55 |
| 56 // Security methods to check if we can establish a new dictionary with the |
| 57 // given data, that arrived in response to get of dictionary_url. |
| 58 static SdchProblemCode CanSet(const std::string& domain, |
| 59 const std::string& path, |
| 60 const std::set<int>& ports, |
| 61 const GURL& dictionary_url); |
| 62 |
| 63 // Security method to check if we can use a dictionary to decompress a |
| 64 // target that arrived with a reference to this dictionary. |
| 65 SdchProblemCode CanUse(const GURL& referring_url) const; |
| 66 |
| 67 // Compare paths to see if they "match" for dictionary use. |
| 68 static bool PathMatch(const std::string& path, |
| 69 const std::string& restriction); |
| 70 |
| 71 // Is this dictionary expired? |
| 72 bool Expired() const; |
| 73 |
| 74 void SetClockForTesting(scoped_ptr<base::Clock> clock); |
| 75 |
| 76 private: |
| 77 friend class base::RefCountedData<SdchDictionary>; |
| 78 |
| 79 // Private copy-constructor to support RefCountedData<>, which requires |
| 80 // that an object stored in it be either DefaultConstructible or |
| 81 // CopyConstructible |
| 82 SdchDictionary(const SdchDictionary& rhs); |
| 83 |
| 84 // The actual text of the dictionary. |
| 85 std::string text_; |
| 86 |
| 87 // Part of the hash of text_ that the client uses to advertise the fact that |
| 88 // it has a specific dictionary pre-cached. |
| 89 std::string client_hash_; |
| 90 |
| 91 // Part of the hash of text_ that the server uses to identify the |
| 92 // dictionary it wants used for decoding. |
| 93 std::string server_hash_; |
| 94 |
| 95 // The GURL that arrived with the text_ in a URL request to specify where |
| 96 // this dictionary may be used. |
| 97 const GURL url_; |
| 98 |
| 99 // Metadate "headers" in before dictionary text contained the following: |
| 100 // Each dictionary payload consists of several headers, followed by the text |
| 101 // of the dictionary. The following are the known headers. |
| 102 const std::string domain_; |
| 103 const std::string path_; |
| 104 const base::Time expiration_; // Implied by max-age. |
| 105 const std::set<int> ports_; |
| 106 |
| 107 scoped_ptr<base::Clock> clock_; |
| 108 |
| 109 void operator=(const SdchDictionary&) = delete; |
| 110 }; |
| 111 |
| 112 } // namespace net |
| 113 |
| 114 #endif // NET_BASE_SDCH_DICTIONARY_H_ |
OLD | NEW |