4ac6997a227d4e2c5b7c72a353c61e4fcf24e09a
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebPerformance.cpp
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
38 static double millisecondsToSeconds(unsigned long long milliseconds)
39 {
40     return static_cast<double>(milliseconds / 1000.0);
41 }
42
43 void WebPerformance::reset()
44 {
45     m_private.reset();
46 }
47
48 void WebPerformance::assign(const WebPerformance& other)
49 {
50     m_private = other.m_private;
51 }
52
53 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
69 double WebPerformance::navigationStart() const
70 {
71     return millisecondsToSeconds(m_private->timing()->navigationStart());
72 }
73
74 double WebPerformance::unloadEventEnd() const
75 {
76     return millisecondsToSeconds(m_private->timing()->unloadEventEnd());
77 }
78
79 double WebPerformance::redirectStart() const
80 {
81     return millisecondsToSeconds(m_private->timing()->redirectStart());
82 }
83
84 double WebPerformance::redirectEnd() const
85 {
86     return millisecondsToSeconds(m_private->timing()->redirectEnd());
87 }
88
89 unsigned short WebPerformance::redirectCount() const
90 {
91     return m_private->navigation()->redirectCount();
92 }
93
94 double WebPerformance::fetchStart() const
95 {
96     return millisecondsToSeconds(m_private->timing()->fetchStart());
97 }
98
99 double WebPerformance::domainLookupStart() const
100 {
101     return millisecondsToSeconds(m_private->timing()->domainLookupStart());
102 }
103
104 double WebPerformance::domainLookupEnd() const
105 {
106     return millisecondsToSeconds(m_private->timing()->domainLookupEnd());
107 }
108
109 double WebPerformance::connectStart() const
110 {
111     return millisecondsToSeconds(m_private->timing()->connectStart());
112 }
113
114 double WebPerformance::connectEnd() const
115 {
116     return millisecondsToSeconds(m_private->timing()->connectEnd());
117 }
118
119 double WebPerformance::requestStart() const
120 {
121     return millisecondsToSeconds(m_private->timing()->requestStart());
122 }
123
124 double WebPerformance::responseStart() const
125 {
126     return millisecondsToSeconds(m_private->timing()->responseStart());
127 }
128
129 double WebPerformance::responseEnd() const
130 {
131     return millisecondsToSeconds(m_private->timing()->responseEnd());
132 }
133
134 double WebPerformance::domLoading() const
135 {
136     return millisecondsToSeconds(m_private->timing()->domLoading());
137 }
138
139 double WebPerformance::domInteractive() const
140 {
141     return millisecondsToSeconds(m_private->timing()->domInteractive());
142 }
143
144 double WebPerformance::domContentLoadedEventStart() const
145 {
146     return millisecondsToSeconds(m_private->timing()->domContentLoadedEventStart());
147 }
148
149 double WebPerformance::domContentLoadedEventEnd() const
150 {
151     return millisecondsToSeconds(m_private->timing()->domContentLoadedEventEnd());
152 }
153
154 double WebPerformance::domComplete() const
155 {
156     return millisecondsToSeconds(m_private->timing()->domComplete());
157 }
158
159 double WebPerformance::loadEventStart() const
160 {
161     return millisecondsToSeconds(m_private->timing()->loadEventStart());
162 }
163
164 double WebPerformance::loadEventEnd() const
165 {
166     return millisecondsToSeconds(m_private->timing()->loadEventEnd());
167 }
168
169 WebPerformance::WebPerformance(const PassRefPtrWillBeRawPtr<Performance>& performance)
170     : m_private(performance)
171 {
172 }
173
174 WebPerformance& WebPerformance::operator=(const PassRefPtrWillBeRawPtr<Performance>& performance)
175 {
176     m_private = performance;
177     return *this;
178 }
179
180 } // namespace blink