cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / net / cookies / cookie_cache.h
blobaa808b51b668e3db28b3b26cf70139fdffe38fca
1 // Copyright 2014 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 IOS_NET_COOKIES_COOKIE_CACHE_H_
6 #define IOS_NET_COOKIES_COOKIE_CACHE_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
13 #include "base/macros.h"
14 #include "net/cookies/canonical_cookie.h"
15 #include "url/gurl.h"
17 namespace net {
19 // CookieCache is a specialized cache for storing the set of cookies with a
20 // specified name that would be sent with requests for a given URL. It only
21 // provides one operation, Update(), which updates the set of cookies for a
22 // (url, name) pair and returns whether the new set for that (url, name) pair is
23 // different from the old set.
24 class CookieCache {
25 public:
26 CookieCache();
27 ~CookieCache();
29 // Update the cookie cache with cookies named |name| that would be sent for a
30 // request to |url|. The new vector of cookies overwrite the existing cookies
31 // stored for the specified (url, name) pair.
33 // Returns true if the new set is different from the old set, i.e.:
34 // * any cookie in |new_cookies| is not present in the cache
35 // * any cookie in the cache is not present in |new_cookies|
36 // * any cookie in both |new_cookies| and the cache has changed value
37 // Returns false otherwise.
39 // |out_removed_cookies|, if not NULL, will be populated with the cookies that
40 // were removed.
41 // |out_changed_cookies|, if not NULL, will be populated with the cookies that
42 // were added.
43 bool Update(const GURL& url,
44 const std::string& name,
45 const std::vector<net::CanonicalCookie>& new_cookies,
46 std::vector<net::CanonicalCookie>* out_removed_cookies,
47 std::vector<net::CanonicalCookie>* out_added_cookies);
49 private:
50 // Compares two cookies, returning true if |lhs| comes before |rhs| in the
51 // partial ordering defined for CookieSet. This effectively does a
52 // lexicographic comparison of (domain, path, name) tuples for two cookies.
53 struct CookieComparator {
54 bool operator()(const net::CanonicalCookie& lhs,
55 const net::CanonicalCookie& rhs) const;
58 // Compares two cookies, returning true if |lhs| comes before |rhs| in the
59 // partial ordering defined for CookieSet. This effectively does a
60 // lexicographic comparison of (domain, path, name, value) tuples for two
61 // cookies.
62 struct CookieAndValueComparator {
63 bool operator()(const net::CanonicalCookie& lhs,
64 const net::CanonicalCookie& rhs) const;
67 typedef std::set<net::CanonicalCookie, CookieComparator> CookieSet;
68 typedef std::pair<GURL, std::string> CookieKey;
69 typedef std::map<CookieKey, CookieSet> CookieKeyPathMap;
71 CookieKeyPathMap cache_;
73 DISALLOW_COPY_AND_ASSIGN(CookieCache);
76 } // namespace net
78 #endif // IOS_NET_COOKIES_COOKIE_CACHE_H_