OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_ | |
6 #define NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_ | |
7 | |
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" | |
13 | |
14 namespace base { | |
15 class ListValue; | |
16 class TickClock; | |
17 } | |
18 | |
19 namespace net { | |
20 | |
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::ListValue> SerializeToValue(const BackoffEntry& entry, | |
34 base::Time time_now); | |
35 | |
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. | |
mmenke
2015/05/06 17:34:48
nit: NULL is generally capitalized in net/ when i
johnme
2015/05/06 20:38:08
Done (I'd stopped doing this with C++11, as it's u
| |
43 static scoped_ptr<BackoffEntry> DeserializeFromValue( | |
44 const base::ListValue& serialized, | |
mmenke
2015/05/06 17:34:48
Suggest base::Value here and above. Consumer prob
johnme
2015/05/06 20:38:08
Done.
| |
45 const BackoffEntry::Policy* policy, | |
46 base::TickClock* clock, | |
47 base::Time time_now); | |
48 | |
49 private: | |
50 DISALLOW_IMPLICIT_CONSTRUCTORS(BackoffEntrySerializer); | |
51 }; | |
52 | |
53 } // namespace net | |
54 | |
55 #endif // NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_ | |
OLD | NEW |