1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "public/web/WebPerformance.h"
33
34 #include "core/timing/Performance.h"
35
36 namespace blink {
37
millisecondsToSeconds(unsigned long long milliseconds)38 static double millisecondsToSeconds(unsigned long long milliseconds)
39 {
40 return static_cast<double>(milliseconds / 1000.0);
41 }
42
reset()43 void WebPerformance::reset()
44 {
45 m_private.reset();
46 }
47
assign(const WebPerformance & other)48 void WebPerformance::assign(const WebPerformance& other)
49 {
50 m_private = other.m_private;
51 }
52
navigationType() const53 WebNavigationType WebPerformance::navigationType() const
54 {
55 switch (m_private->navigation()->type()) {
56 case PerformanceNavigation::TYPE_NAVIGATE:
57 return WebNavigationTypeOther;
58 case PerformanceNavigation::TYPE_RELOAD:
59 return WebNavigationTypeReload;
60 case PerformanceNavigation::TYPE_BACK_FORWARD:
61 return WebNavigationTypeBackForward;
62 case PerformanceNavigation::TYPE_RESERVED:
63 return WebNavigationTypeOther;
64 }
65 ASSERT_NOT_REACHED();
66 return WebNavigationTypeOther;
67 }
68
navigationStart() const69 double WebPerformance::navigationStart() const
70 {
71 return millisecondsToSeconds(m_private->timing()->navigationStart());
72 }
73
unloadEventEnd() const74 double WebPerformance::unloadEventEnd() const
75 {
76 return millisecondsToSeconds(m_private->timing()->unloadEventEnd());
77 }
78
redirectStart() const79 double WebPerformance::redirectStart() const
80 {
81 return millisecondsToSeconds(m_private->timing()->redirectStart());
82 }
83
redirectEnd() const84 double WebPerformance::redirectEnd() const
85 {
86 return millisecondsToSeconds(m_private->timing()->redirectEnd());
87 }
88
redirectCount() const89 unsigned short WebPerformance::redirectCount() const
90 {
91 return m_private->navigation()->redirectCount();
92 }
93
fetchStart() const94 double WebPerformance::fetchStart() const
95 {
96 return millisecondsToSeconds(m_private->timing()->fetchStart());
97 }
98
domainLookupStart() const99 double WebPerformance::domainLookupStart() const
100 {
101 return millisecondsToSeconds(m_private->timing()->domainLookupStart());
102 }
103
domainLookupEnd() const104 double WebPerformance::domainLookupEnd() const
105 {
106 return millisecondsToSeconds(m_private->timing()->domainLookupEnd());
107 }
108
connectStart() const109 double WebPerformance::connectStart() const
110 {
111 return millisecondsToSeconds(m_private->timing()->connectStart());
112 }
113
connectEnd() const114 double WebPerformance::connectEnd() const
115 {
116 return millisecondsToSeconds(m_private->timing()->connectEnd());
117 }
118
requestStart() const119 double WebPerformance::requestStart() const
120 {
121 return millisecondsToSeconds(m_private->timing()->requestStart());
122 }
123
responseStart() const124 double WebPerformance::responseStart() const
125 {
126 return millisecondsToSeconds(m_private->timing()->responseStart());
127 }
128
responseEnd() const129 double WebPerformance::responseEnd() const
130 {
131 return millisecondsToSeconds(m_private->timing()->responseEnd());
132 }
133
domLoading() const134 double WebPerformance::domLoading() const
135 {
136 return millisecondsToSeconds(m_private->timing()->domLoading());
137 }
138
domInteractive() const139 double WebPerformance::domInteractive() const
140 {
141 return millisecondsToSeconds(m_private->timing()->domInteractive());
142 }
143
domContentLoadedEventStart() const144 double WebPerformance::domContentLoadedEventStart() const
145 {
146 return millisecondsToSeconds(m_private->timing()->domContentLoadedEventStart());
147 }
148
domContentLoadedEventEnd() const149 double WebPerformance::domContentLoadedEventEnd() const
150 {
151 return millisecondsToSeconds(m_private->timing()->domContentLoadedEventEnd());
152 }
153
domComplete() const154 double WebPerformance::domComplete() const
155 {
156 return millisecondsToSeconds(m_private->timing()->domComplete());
157 }
158
loadEventStart() const159 double WebPerformance::loadEventStart() const
160 {
161 return millisecondsToSeconds(m_private->timing()->loadEventStart());
162 }
163
loadEventEnd() const164 double WebPerformance::loadEventEnd() const
165 {
166 return millisecondsToSeconds(m_private->timing()->loadEventEnd());
167 }
168
WebPerformance(const PassRefPtrWillBeRawPtr<Performance> & performance)169 WebPerformance::WebPerformance(const PassRefPtrWillBeRawPtr<Performance>& performance)
170 : m_private(performance)
171 {
172 }
173
operator =(const PassRefPtrWillBeRawPtr<Performance> & performance)174 WebPerformance& WebPerformance::operator=(const PassRefPtrWillBeRawPtr<Performance>& performance)
175 {
176 m_private = performance;
177 return *this;
178 }
179
180 } // namespace blink
181