xref: /aosp_15_r20/external/cronet/net/cookies/cookie_access_result.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 The Chromium Authors
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_COOKIES_COOKIE_ACCESS_RESULT_H_
6 #define NET_COOKIES_COOKIE_ACCESS_RESULT_H_
7 
8 #include <ostream>
9 
10 #include "net/base/net_export.h"
11 #include "net/cookies/cookie_constants.h"
12 #include "net/cookies/cookie_inclusion_status.h"
13 
14 namespace net {
15 
16 struct NET_EXPORT CookieAccessResult {
17   // Creating a CookieAccessResult with out any parameters will create a
18   // CookieInclusionStatus that has no exclusion reasons, therefore
19   // indicates inclusion.
20   CookieAccessResult();
21   CookieAccessResult(CookieEffectiveSameSite effective_same_site,
22                      CookieInclusionStatus status,
23                      CookieAccessSemantics access_semantics,
24                      bool is_allowed_to_access_secure_cookie);
25 
26   explicit CookieAccessResult(CookieInclusionStatus status);
27 
28   CookieAccessResult(const CookieAccessResult& cookie_access_result);
29 
30   CookieAccessResult& operator=(const CookieAccessResult& cookie_access_result);
31 
32   CookieAccessResult(CookieAccessResult&& cookie_access_result);
33 
34   ~CookieAccessResult();
35 
36   bool operator==(const CookieAccessResult& other) const {
37     return status == other.status &&
38            effective_same_site == other.effective_same_site &&
39            access_semantics == other.access_semantics &&
40            is_allowed_to_access_secure_cookies ==
41                other.is_allowed_to_access_secure_cookies;
42   }
43 
44   bool operator<(const CookieAccessResult& other) const {
45     return std::tie(status, effective_same_site, access_semantics,
46                     is_allowed_to_access_secure_cookies) <
47            std::tie(other.status, other.effective_same_site,
48                     other.access_semantics,
49                     other.is_allowed_to_access_secure_cookies);
50   }
51 
52   CookieInclusionStatus status;
53   CookieEffectiveSameSite effective_same_site =
54       CookieEffectiveSameSite::UNDEFINED;
55   CookieAccessSemantics access_semantics = CookieAccessSemantics::UNKNOWN;
56   // Whether access to Secure cookies should be allowed. This is expected to be
57   // set based on the scheme of the source URL.
58   bool is_allowed_to_access_secure_cookies = false;
59 };
60 
61 // Provided to allow gtest to create more helpful error messages, instead of
62 // printing hex.
PrintTo(const CookieAccessResult & car,std::ostream * os)63 inline void PrintTo(const CookieAccessResult& car, std::ostream* os) {
64   *os << "{ { ";
65   PrintTo(car.status, os);
66   *os << " }, " << static_cast<int>(car.effective_same_site) << ", "
67       << static_cast<int>(car.access_semantics) << ", "
68       << car.is_allowed_to_access_secure_cookies << " }";
69 }
70 
71 }  // namespace net
72 
73 #endif  // NET_COOKIES_COOKIE_ACCESS_RESULT_H_
74