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

Unified Diff: chrome/common/page_load_metrics/page_load_timing.cc

Issue 2191163003: Add compile time assert to help catch new fields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fixequal
Patch Set: remove comment Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/page_load_metrics/page_load_timing.cc
diff --git a/chrome/common/page_load_metrics/page_load_timing.cc b/chrome/common/page_load_metrics/page_load_timing.cc
index d96844881c72490c9aa961af1ed3f5712b36fe83..5244d1082348d54203c186a718979730032cb4c9 100644
--- a/chrome/common/page_load_metrics/page_load_timing.cc
+++ b/chrome/common/page_load_metrics/page_load_timing.cc
@@ -12,6 +12,25 @@ PageLoadTiming::PageLoadTiming(const PageLoadTiming& other) = default;
PageLoadTiming::~PageLoadTiming() {}
+namespace {
+
+// The number of TimeDelta fields in PageLoadTiming.
+const int kNumTimeDeltas = 13;
+
+constexpr size_t ComputePageLoadTimingSize() {
+ // This assumes that the members of PageLoadTiming are stored without any
+ // padding. This is true for base::Time and base::Optional<base::TimeDelta>.
+ return sizeof(base::Time) /* sizeof navigation_start */ +
+ sizeof(base::Optional<base::TimeDelta>) * kNumTimeDeltas;
+}
+
+static_assert(
+ sizeof(PageLoadTiming) == ComputePageLoadTimingSize(),
+ "*** IMPORTANT ***: If you add new TimeDeltas to PageLoadTiming, update "
+ "operator==, IsEmpty, and kNumTimeDeltas to reflect your change.");
+
+} // namespace
+
bool PageLoadTiming::operator==(const PageLoadTiming& other) const {
return navigation_start == other.navigation_start &&
response_start == other.response_start &&
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698