Chromium Code Reviews| 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 "chrome/common/page_load_metrics/page_load_timing.h" | 5 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 6 | 6 |
| 7 namespace page_load_metrics { | 7 namespace page_load_metrics { |
| 8 | 8 |
| 9 PageLoadTiming::PageLoadTiming() {} | 9 PageLoadTiming::PageLoadTiming() {} |
| 10 | 10 |
| 11 PageLoadTiming::PageLoadTiming(const PageLoadTiming& other) = default; | 11 PageLoadTiming::PageLoadTiming(const PageLoadTiming& other) = default; |
| 12 | 12 |
| 13 PageLoadTiming::~PageLoadTiming() {} | 13 PageLoadTiming::~PageLoadTiming() {} |
| 14 | 14 |
| 15 namespace { | |
| 16 | |
| 17 // *** IMPORTANT ***: When adding fields to PageLoadTiming, make sure to update | |
| 18 // 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
| |
| 19 const int kNumTimeDeltas = 12; | |
| 20 | |
| 21 const size_t kSizeOfTime = sizeof(base::Time); | |
| 22 const size_t kSizeOfOptionalTimeDelta = sizeof(base::Optional<base::TimeDelta>); | |
| 23 const size_t kSizeOfAllOptionalTimeDeltas = | |
| 24 kSizeOfOptionalTimeDelta * kNumTimeDeltas; | |
| 25 | |
| 26 // This assumes that the members of PageLoadTiming are stored without any | |
| 27 // padding. This is true for base::Time and base::Optional<base::TimeDelta>. | |
| 28 static_assert( | |
| 29 sizeof(page_load_metrics::PageLoadTiming) == | |
| 30 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
| |
| 31 "If you added a new TimeDelta to PageLoadTiming, update kNumTimeDeltas " | |
| 32 "above. Make sure to also update IsEmpty and operator== to reflect any " | |
| 33 "new fields you have added."); | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 15 bool PageLoadTiming::operator==(const PageLoadTiming& other) const { | 37 bool PageLoadTiming::operator==(const PageLoadTiming& other) const { |
| 16 return navigation_start == other.navigation_start && | 38 return navigation_start == other.navigation_start && |
| 17 response_start == other.response_start && | 39 response_start == other.response_start && |
| 18 dom_content_loaded_event_start == | 40 dom_content_loaded_event_start == |
| 19 other.dom_content_loaded_event_start && | 41 other.dom_content_loaded_event_start && |
| 20 load_event_start == other.load_event_start && | 42 load_event_start == other.load_event_start && |
| 21 first_layout == other.first_layout && | 43 first_layout == other.first_layout && |
| 22 first_paint == other.first_paint && | 44 first_paint == other.first_paint && |
| 23 first_text_paint == other.first_text_paint && | 45 first_text_paint == other.first_text_paint && |
| 24 first_image_paint == other.first_image_paint && | 46 first_image_paint == other.first_image_paint && |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 39 !parse_blocked_on_script_load_from_document_write_duration; | 61 !parse_blocked_on_script_load_from_document_write_duration; |
| 40 } | 62 } |
| 41 | 63 |
| 42 PageLoadMetadata::PageLoadMetadata() {} | 64 PageLoadMetadata::PageLoadMetadata() {} |
| 43 | 65 |
| 44 bool PageLoadMetadata::operator==(const PageLoadMetadata& other) const { | 66 bool PageLoadMetadata::operator==(const PageLoadMetadata& other) const { |
| 45 return behavior_flags == other.behavior_flags; | 67 return behavior_flags == other.behavior_flags; |
| 46 } | 68 } |
| 47 | 69 |
| 48 } // namespace page_load_metrics | 70 } // namespace page_load_metrics |
| OLD | NEW |