Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / base / backoff_entry_serializer.h
blob837265727fb4d4d768a61999df4dd6f192615d8f
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"
14 namespace base {
15 class Value;
16 class TickClock;
19 namespace net {
21 // Serialize or deserialize a BackoffEntry, so it can persist beyond the
22 // lifetime of the browser.
23 class NET_EXPORT BackoffEntrySerializer {
24 public:
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,
34 base::Time time_now);
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,
47 base::Time time_now);
49 private:
50 DISALLOW_IMPLICIT_CONSTRUCTORS(BackoffEntrySerializer);
53 } // namespace net
55 #endif // NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_