Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: net/base/backoff_entry_serializer.h

Issue 1023473003: Allow BackoffEntry to be serialized and deserialized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/backoff_entry_serializer.h
diff --git a/net/base/backoff_entry_serializer.h b/net/base/backoff_entry_serializer.h
new file mode 100644
index 0000000000000000000000000000000000000000..b5a8469e78c04d10298d61349f8a1ada2283109a
--- /dev/null
+++ b/net/base/backoff_entry_serializer.h
@@ -0,0 +1,54 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_
+#define NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "net/base/backoff_entry.h"
+#include "net/base/net_export.h"
+
+namespace base {
+class ListValue;
+class TickClock;
+}
+
+namespace net {
+
+// Serialize or deserialize a BackoffEntry, so it can persist beyond the
+// lifetime of the browser.
+class NET_EXPORT BackoffEntrySerializer {
+ public:
+ // Serializes the release time and failure count into a ListValue that can
+ // later be passed to Deserialize to re-create the given BackoffEntry. The
+ // 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.
+ // when deserializing. |time_now| should be base::Time::Now(), except for
+ // tests that want to simulate time changes. The release time TimeTicks will
+ // be converted to an absolute timestamp, thus the time will continue counting
+ // down even whilst the device is powered off, and will be partially
+ // vulnerable to changes in the system clock time.
+ static scoped_ptr<base::ListValue> SerializeToValue(const BackoffEntry& entry,
+ base::Time time_now);
+
+ // Deserializes a ListValue back to a BackoffEntry. |policy| MUST be the same
+ // Policy as the serialized entry had. |clock| may be null. Both |policy| and
+ // |clock| (if not null) must enclose lifetime of the returned BackoffEntry.
+ // |time_now| should be base::Time::Now(), except for tests that want to
+ // simulate time changes. The absolute timestamp that was serialized will be
+ // converted back to TimeTicks as best as possible. Returns null if
+ // deserialization was unsuccessful.
+ static scoped_ptr<BackoffEntry> DeserializeFromValue(
+ const base::ListValue& serialized,
+ const BackoffEntry::Policy* policy,
+ base::TickClock* clock,
+ base::Time time_now);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(BackoffEntrySerializer);
mmenke 2015/05/05 15:47:52 include base/macros.h
johnme 2015/05/06 12:46:47 Done.
+};
+
+} // namespace net
+
+#endif // NET_BASE_BACKOFF_ENTRY_SERIALIZER_H_

Powered by Google App Engine
This is Rietveld 408576698