OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/page_load_metrics/common/page_load_timing.h" | |
6 #include "third_party/WebKit/public/web/WebPerformance.h" | |
7 | |
8 namespace page_load_metrics { | |
9 | |
10 PageLoadTiming::PageLoadTiming() {} | |
11 PageLoadTiming::PageLoadTiming(blink::WebPerformance& p) { | |
Bryan McQuade
2015/09/02 18:26:46
in this case I think a single-character variable n
Charlie Harrison
2015/09/03 14:00:52
Done.
| |
12 double start = p.navigationStart(); | |
13 navigation_start = base::Time::FromDoubleT(start); | |
14 response_start = ClampDelta(p.responseStart(), start); | |
15 dom_content_loaded_event_start = | |
16 ClampDelta(p.domContentLoadedEventStart(), start); | |
17 load_event_start = ClampDelta(p.loadEventStart(), start); | |
18 first_layout = ClampDelta(p.firstLayout(), start); | |
19 } | |
20 | |
21 base::TimeDelta PageLoadTiming::ClampDelta(double event_ms, | |
Bryan McQuade
2015/09/02 18:26:46
clamp delta doesn't need to be a member function -
| |
22 double start_ms) const { | |
23 double delta = event_ms - start_ms; | |
24 return base::TimeDelta::FromMillisecondsD(delta < 0 ? 0 : delta); | |
25 } | |
26 | |
27 PageLoadTiming::~PageLoadTiming() {} | |
28 | |
29 bool PageLoadTiming::operator==(const PageLoadTiming& other) const { | |
30 return navigation_start == other.navigation_start && | |
31 response_start == other.response_start && | |
32 dom_content_loaded_event_start == | |
33 other.dom_content_loaded_event_start && | |
34 load_event_start == other.load_event_start && | |
35 first_layout == other.first_layout; | |
36 } | |
37 | |
38 bool PageLoadTiming::IsChild(const PageLoadTiming& parent) const { | |
Bryan McQuade
2015/09/02 18:26:46
I do think these policy methods are slightly imple
| |
39 return (parent.navigation_start.is_null() || | |
40 navigation_start == parent.navigation_start); | |
41 } | |
42 | |
43 bool PageLoadTiming::IsComplete() const { | |
44 return !navigation_start.is_null() && !response_start.is_zero() && | |
45 !dom_content_loaded_event_start.is_zero() && | |
46 !load_event_start.is_zero() && !first_layout.is_zero(); | |
47 } | |
48 | |
49 bool PageLoadTiming::IsEmpty() const { | |
50 return navigation_start.is_null() && response_start.is_zero() && | |
51 dom_content_loaded_event_start.is_zero() && | |
52 load_event_start.is_zero() && first_layout.is_zero(); | |
53 } | |
54 | |
55 // Order: navigation_start => response_start => | |
56 // dom_content_loaded_event_start => load_event_start | |
57 bool PageLoadTiming::IsOrdered() const { | |
58 return !response_start.is_zero() && | |
59 response_start < dom_content_loaded_event_start && | |
60 dom_content_loaded_event_start < load_event_start; | |
61 } | |
62 | |
63 } // namespace page_load_metrics | |
OLD | NEW |