OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/backoff_entry_serializer.h" | 5 #include "net/base/backoff_entry_serializer.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
8 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "net/base/backoff_entry.h" | 12 #include "net/base/backoff_entry.h" |
11 | 13 |
12 namespace { | 14 namespace { |
13 // Increment this number when changing the serialization format, to avoid old | 15 // Increment this number when changing the serialization format, to avoid old |
14 // serialized values loaded from disk etc being misinterpreted. | 16 // serialized values loaded from disk etc being misinterpreted. |
15 const int kSerializationFormatVersion = 1; | 17 const int kSerializationFormatVersion = 1; |
16 } // namespace | 18 } // namespace |
(...skipping 10 matching lines...) Expand all Loading... |
27 // Can't use entry.GetTimeUntilRelease as it doesn't allow negative deltas. | 29 // Can't use entry.GetTimeUntilRelease as it doesn't allow negative deltas. |
28 base::TimeDelta backoff_duration = | 30 base::TimeDelta backoff_duration = |
29 entry.GetReleaseTime() - entry.tick_clock()->NowTicks(); | 31 entry.GetReleaseTime() - entry.tick_clock()->NowTicks(); |
30 // Redundantly stores both the remaining time delta and the absolute time. | 32 // Redundantly stores both the remaining time delta and the absolute time. |
31 // The delta is used to work around some cases where wall clock time changes. | 33 // The delta is used to work around some cases where wall clock time changes. |
32 serialized->AppendDouble(backoff_duration.InSecondsF()); | 34 serialized->AppendDouble(backoff_duration.InSecondsF()); |
33 base::Time absolute_release_time = backoff_duration + time_now; | 35 base::Time absolute_release_time = backoff_duration + time_now; |
34 serialized->AppendString( | 36 serialized->AppendString( |
35 base::Int64ToString(absolute_release_time.ToInternalValue())); | 37 base::Int64ToString(absolute_release_time.ToInternalValue())); |
36 | 38 |
37 return serialized.Pass(); | 39 return std::move(serialized); |
38 } | 40 } |
39 | 41 |
40 scoped_ptr<BackoffEntry> BackoffEntrySerializer::DeserializeFromValue( | 42 scoped_ptr<BackoffEntry> BackoffEntrySerializer::DeserializeFromValue( |
41 const base::Value& serialized, const BackoffEntry::Policy* policy, | 43 const base::Value& serialized, const BackoffEntry::Policy* policy, |
42 base::TickClock* tick_clock, base::Time time_now) { | 44 base::TickClock* tick_clock, base::Time time_now) { |
43 const base::ListValue* serialized_list = nullptr; | 45 const base::ListValue* serialized_list = nullptr; |
44 if (!serialized.GetAsList(&serialized_list)) | 46 if (!serialized.GetAsList(&serialized_list)) |
45 return nullptr; | 47 return nullptr; |
46 if (serialized_list->GetSize() != 4) | 48 if (serialized_list->GetSize() != 4) |
47 return nullptr; | 49 return nullptr; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // against the clock being wound forward). | 85 // against the clock being wound forward). |
84 if (backoff_duration > original_backoff_duration) | 86 if (backoff_duration > original_backoff_duration) |
85 backoff_duration = original_backoff_duration; | 87 backoff_duration = original_backoff_duration; |
86 entry->SetCustomReleaseTime( | 88 entry->SetCustomReleaseTime( |
87 entry->BackoffDurationToReleaseTime(backoff_duration)); | 89 entry->BackoffDurationToReleaseTime(backoff_duration)); |
88 | 90 |
89 return entry; | 91 return entry; |
90 } | 92 } |
91 | 93 |
92 } // namespace net | 94 } // namespace net |
OLD | NEW |