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.
5 #ifndef NET_BASE_SDCH_DICTIONARY_H_
6 #define NET_BASE_SDCH_DICTIONARY_H_
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"
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
{
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
,
35 const std::string
& client_hash
,
36 const std::string
& server_hash
,
38 const std::string
& domain
,
39 const std::string
& path
,
40 const base::Time
& expiration
,
41 const std::set
<int>& ports
);
45 // Sdch filters can get our text to use in decoding compressed data.
46 const std::string
& text() const { return text_
; }
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_
; }
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
);
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;
67 // Compare paths to see if they "match" for dictionary use.
68 static bool PathMatch(const std::string
& path
,
69 const std::string
& restriction
);
71 // Is this dictionary expired?
75 friend class base::RefCountedData
<SdchDictionary
>;
77 // Private copy-constructor to support RefCountedData<>, which requires
78 // that an object stored in it be either DefaultConstructible or
80 SdchDictionary(const SdchDictionary
& rhs
);
82 // The actual text of the dictionary.
85 // Part of the hash of text_ that the client uses to advertise the fact that
86 // it has a specific dictionary pre-cached.
87 std::string client_hash_
;
89 // Part of the hash of text_ that the server uses to identify the
90 // dictionary it wants used for decoding.
91 std::string server_hash_
;
93 // The GURL that arrived with the text_ in a URL request to specify where
94 // this dictionary may be used.
97 // Metadate "headers" in before dictionary text contained the following:
98 // Each dictionary payload consists of several headers, followed by the text
99 // of the dictionary. The following are the known headers.
100 const std::string domain_
;
101 const std::string path_
;
102 const base::Time expiration_
; // Implied by max-age.
103 const std::set
<int> ports_
;
105 void operator=(const SdchDictionary
&) = delete;
110 #endif // NET_BASE_SDCH_DICTIONARY_H_