 Chromium Code Reviews
 Chromium Code Reviews Issue 1023473003:
  Allow BackoffEntry to be serialized and deserialized.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1023473003:
  Allow BackoffEntry to be serialized and deserialized.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 
mmenke
2015/05/05 15:47:52
nit:  New files shouldn't use the (c) (Same goes g
 
johnme
2015/05/06 12:46:47
Done.
 | |
| 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/memory/scoped_ptr.h" | |
| 9 #include "base/time/time.h" | |
| 10 #include "net/base/backoff_entry.h" | |
| 11 #include "net/base/net_export.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class ListValue; | |
| 15 class TickClock; | |
| 16 } | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 // Serialize or deserialize a BackoffEntry, so it can persist beyond the | |
| 21 // lifetime of the browser. | |
| 22 class NET_EXPORT BackoffEntrySerializer { | |
| 23 public: | |
| 24 // Serializes the release time and failure count into a ListValue that can | |
| 25 // later be passed to Deserialize to re-create the given BackoffEntry. The | |
| 26 // Policy is not serialized, instead you'll need to pass an identical Policy* | |
| 
mmenke
2015/05/05 15:47:52
Don't use "you" in comments.  Can just use passive
 
johnme
2015/05/06 12:46:47
Done.
 | |
| 27 // when deserializing. |time_now| should be base::Time::Now(), except for | |
| 28 // tests that want to simulate time changes. The release time TimeTicks will | |
| 29 // be converted to an absolute timestamp, thus the time will continue counting | |
| 30 // down even whilst the device is powered off, and will be partially | |
| 31 // vulnerable to changes in the system clock time. | |
| 32 static scoped_ptr<base::ListValue> SerializeToValue(const BackoffEntry& entry, | |
| 33 base::Time time_now); | |
| 34 | |
| 35 // Deserializes a ListValue back to a BackoffEntry. |policy| MUST be the same | |
| 36 // Policy as the serialized entry had. |clock| may be null. Both |policy| and | |
| 37 // |clock| (if not null) must enclose lifetime of the returned BackoffEntry. | |
| 38 // |time_now| should be base::Time::Now(), except for tests that want to | |
| 39 // simulate time changes. The absolute timestamp that was serialized will be | |
| 40 // converted back to TimeTicks as best as possible. Returns null if | |
| 41 // deserialization was unsuccessful. | |
| 42 static scoped_ptr<BackoffEntry> DeserializeFromValue( | |
| 43 const base::ListValue& serialized, | |
| 44 const BackoffEntry::Policy* policy, | |
| 45 base::TickClock* clock, | |
| 46 base::Time time_now); | |
| 47 | |
| 48 private: | |
| 49 DISALLOW_IMPLICIT_CONSTRUCTORS(BackoffEntrySerializer); | |
| 
mmenke
2015/05/05 15:47:52
include base/macros.h
 
johnme
2015/05/06 12:46:47
Done.
 | |
| 50 }; | |
| 51 | |
| 52 } // namespace net | |
| 53 | |
| 54 #endif // NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_ | |
| OLD | NEW |