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

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: add comment Created 4 years, 4 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 21c3204489a6074d4735cb44d5676af36e648587..07408bdb05313b375caa94d67dea9c7476a89614 100644
--- a/chrome/common/page_load_metrics/page_load_timing.cc
+++ b/chrome/common/page_load_metrics/page_load_timing.cc
@@ -12,6 +12,28 @@ PageLoadTiming::PageLoadTiming(const PageLoadTiming& other) = default;
PageLoadTiming::~PageLoadTiming() {}
+namespace {
+
+// *** IMPORTANT ***: When adding fields to PageLoadTiming, make sure to update
+// operator== and IsEmpty below to reflect your changes.
kinuko 2016/08/02 16:09:00 nit: "update operator==, IsEmpty and kNumTImeDelta
Bryan McQuade 2016/09/07 11:13:17 Good idea, thanks! I updated the code to reflect y
+const int kNumTimeDeltas = 12;
+
+const size_t kSizeOfTime = sizeof(base::Time);
+const size_t kSizeOfOptionalTimeDelta = sizeof(base::Optional<base::TimeDelta>);
+const size_t kSizeOfAllOptionalTimeDeltas =
+ kSizeOfOptionalTimeDelta * kNumTimeDeltas;
+
+// This assumes that the members of PageLoadTiming are stored without any
+// padding. This is true for base::Time and base::Optional<base::TimeDelta>.
+static_assert(
+ sizeof(page_load_metrics::PageLoadTiming) ==
+ kSizeOfTime + kSizeOfAllOptionalTimeDeltas,
kinuko 2016/08/02 16:09:00 Using constexpr function might make these const's
Bryan McQuade 2016/09/07 11:13:17 Yes, constexpr makes this easier to read. I made t
+ "If you added a new TimeDelta to PageLoadTiming, update kNumTimeDeltas "
+ "above. Make sure to also update IsEmpty and operator== to reflect any "
+ "new fields you have added.");
+
+} // 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