1 // Copyright 2012 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_CREATION_TIME_MANAGER_H_
6 #define IOS_NET_COOKIES_COOKIE_CREATION_TIME_MANAGER_H_
10 #include "base/containers/hash_tables.h"
11 #include "base/threading/thread_checker.h"
12 #include "base/time/time.h"
18 // The CookieCreationTimeManager allows to get and set the creation time of a
20 // Creation time data is stored either in the cookie properties (when the cookie
21 // is created by the system) or in |creation_times_| (when the cookie is created
22 // by CookieStoreIOS). When both are available, |creation_times_| is used,
23 // because the cookie property only has a one second precision.
24 class CookieCreationTimeManager
{
26 CookieCreationTimeManager();
27 ~CookieCreationTimeManager();
28 // Sets the creation time for |cookie|.
29 // |creation_time| must be unique (not used by another cookie).
30 void SetCreationTime(NSHTTPCookie
* cookie
, const base::Time
& creation_time
);
31 // Creates a unique creation time (to be used in SetCreationTime()) that is
32 // as close as possible to |creation_time|.
33 base::Time
MakeUniqueCreationTime(const base::Time
& creation_time
);
34 // Gets the creation time for |cookie|.
35 base::Time
GetCreationTime(NSHTTPCookie
* cookie
);
36 // Deletes the creation time for |cookie|.
37 void DeleteCreationTime(NSHTTPCookie
* cookie
);
38 // Clears all the creation times.
42 base::hash_map
<std::string
, base::Time
> creation_times_
;
43 std::set
<base::Time
> unique_times_
;
44 base::ThreadChecker thread_checker_
;
49 #endif // IOS_NET_COOKIES_COOKIE_CREATION_TIME_MANAGER_H_