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_BACKOFF_ENTRY_SERIALIZER_H_
6 #define NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "net/base/backoff_entry.h"
12 #include "net/base/net_export.h"
21 // Serialize or deserialize a BackoffEntry, so it can persist beyond the
22 // lifetime of the browser.
23 class NET_EXPORT BackoffEntrySerializer
{
25 // Serializes the release time and failure count into a ListValue that can
26 // later be passed to Deserialize to re-create the given BackoffEntry. The
27 // Policy is not serialized, instead callers must pass an identical Policy*
28 // when deserializing. |time_now| should be base::Time::Now(), except for
29 // tests that want to simulate time changes. The release time TimeTicks will
30 // be converted to an absolute timestamp, thus the time will continue counting
31 // down even whilst the device is powered off, and will be partially
32 // vulnerable to changes in the system clock time.
33 static scoped_ptr
<base::Value
> SerializeToValue(const BackoffEntry
& entry
,
36 // Deserializes a ListValue back to a BackoffEntry. |policy| MUST be the same
37 // Policy as the serialized entry had. |clock| may be NULL. Both |policy| and
38 // |clock| (if not NULL) must enclose lifetime of the returned BackoffEntry.
39 // |time_now| should be base::Time::Now(), except for tests that want to
40 // simulate time changes. The absolute timestamp that was serialized will be
41 // converted back to TimeTicks as best as possible. Returns NULL if
42 // deserialization was unsuccessful.
43 static scoped_ptr
<BackoffEntry
> DeserializeFromValue(
44 const base::Value
& serialized
,
45 const BackoffEntry::Policy
* policy
,
46 base::TickClock
* clock
,
50 DISALLOW_IMPLICIT_CONSTRUCTORS(BackoffEntrySerializer
);
55 #endif // NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_