| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_COOKIES_CANONICAL_COOKIE_H_ | 5 #ifndef NET_COOKIES_CANONICAL_COOKIE_H_ |
| 6 #define NET_COOKIES_CANONICAL_COOKIE_H_ | 6 #define NET_COOKIES_CANONICAL_COOKIE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 14 #include "net/cookies/cookie_constants.h" | 15 #include "net/cookies/cookie_constants.h" |
| 15 #include "net/cookies/cookie_options.h" | 16 #include "net/cookies/cookie_options.h" |
| 16 | 17 |
| 17 class GURL; | 18 class GURL; |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 class ParsedCookie; | 22 class ParsedCookie; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // domain and path. In particular, two equivalent cookies (see IsEquivalent()) | 140 // domain and path. In particular, two equivalent cookies (see IsEquivalent()) |
| 140 // are identical for PartialCompare(). | 141 // are identical for PartialCompare(). |
| 141 bool PartialCompare(const CanonicalCookie& other) const; | 142 bool PartialCompare(const CanonicalCookie& other) const; |
| 142 | 143 |
| 143 // Returns true if the cookie is less than |other|, considering all fields. | 144 // Returns true if the cookie is less than |other|, considering all fields. |
| 144 // FullCompare() is consistent with PartialCompare(): cookies sorted using | 145 // FullCompare() is consistent with PartialCompare(): cookies sorted using |
| 145 // FullCompare() are also sorted with respect to PartialCompare(). | 146 // FullCompare() are also sorted with respect to PartialCompare(). |
| 146 bool FullCompare(const CanonicalCookie& other) const; | 147 bool FullCompare(const CanonicalCookie& other) const; |
| 147 | 148 |
| 148 private: | 149 private: |
| 150 FRIEND_TEST_ALL_PREFIXES(CanonicalCookiePrefixHistogramTest, TestHistograms); |
| 151 |
| 152 // The special cookie prefixes as defined in |
| 153 // https://tools.ietf.org/html/draft-west-cookie-prefixes |
| 154 // |
| 155 // This enum is being histogrammed; do not reorder or remove values. |
| 156 enum CookiePrefix { |
| 157 COOKIE_PREFIX_NONE = 0, |
| 158 COOKIE_PREFIX_SECURE, |
| 159 COOKIE_PREFIX_HOST, |
| 160 COOKIE_PREFIX_LAST |
| 161 }; |
| 162 |
| 163 // Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that |
| 164 // applies to the given cookie |name|. |
| 165 static CookiePrefix GetCookiePrefix(const std::string& name); |
| 166 // Records histograms to measure how often cookie prefixes appear in |
| 167 // the wild and how often they would be blocked. |
| 168 static void RecordCookiePrefixMetrics(CookiePrefix prefix, |
| 169 bool is_cookie_valid); |
| 170 // Returns true if a prefixed cookie does not violate any of the rules |
| 171 // for that cookie. |
| 172 static bool IsCookiePrefixValid(CookiePrefix prefix, |
| 173 const GURL& url, |
| 174 const ParsedCookie& parsed_cookie); |
| 175 |
| 149 // The source member of a canonical cookie is the origin of the URL that tried | 176 // The source member of a canonical cookie is the origin of the URL that tried |
| 150 // to set this cookie. This field is not persistent though; its only used in | 177 // to set this cookie. This field is not persistent though; its only used in |
| 151 // the in-tab cookies dialog to show the user the source URL. This is used for | 178 // the in-tab cookies dialog to show the user the source URL. This is used for |
| 152 // both allowed and blocked cookies. | 179 // both allowed and blocked cookies. |
| 153 // When a CanonicalCookie is constructed from the backing store (common case) | 180 // When a CanonicalCookie is constructed from the backing store (common case) |
| 154 // this field will be null. CanonicalCookie consumers should not rely on | 181 // this field will be null. CanonicalCookie consumers should not rely on |
| 155 // this field unless they guarantee that the creator of those | 182 // this field unless they guarantee that the creator of those |
| 156 // CanonicalCookies properly initialized the field. | 183 // CanonicalCookies properly initialized the field. |
| 157 GURL source_; | 184 GURL source_; |
| 158 std::string name_; | 185 std::string name_; |
| 159 std::string value_; | 186 std::string value_; |
| 160 std::string domain_; | 187 std::string domain_; |
| 161 std::string path_; | 188 std::string path_; |
| 162 base::Time creation_date_; | 189 base::Time creation_date_; |
| 163 base::Time expiry_date_; | 190 base::Time expiry_date_; |
| 164 base::Time last_access_date_; | 191 base::Time last_access_date_; |
| 165 bool secure_; | 192 bool secure_; |
| 166 bool httponly_; | 193 bool httponly_; |
| 167 bool first_party_only_; | 194 bool first_party_only_; |
| 168 CookiePriority priority_; | 195 CookiePriority priority_; |
| 169 }; | 196 }; |
| 170 | 197 |
| 171 typedef std::vector<CanonicalCookie> CookieList; | 198 typedef std::vector<CanonicalCookie> CookieList; |
| 172 | 199 |
| 173 } // namespace net | 200 } // namespace net |
| 174 | 201 |
| 175 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ | 202 #endif // NET_COOKIES_CANONICAL_COOKIE_H_ |
| OLD | NEW |