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

Side by Side Diff: chrome/renderer/loadtimes_extension_bindings.cc

Issue 2084583002: Update chrome.loadTimes() to use timings from WebPerformance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/loadtimes_extension_bindings.h" 5 #include "chrome/renderer/loadtimes_extension_bindings.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/public/renderer/document_state.h" 10 #include "content/public/renderer/document_state.h"
11 #include "net/http/http_response_info.h" 11 #include "net/http/http_response_info.h"
12 #include "third_party/WebKit/public/web/WebLocalFrame.h" 12 #include "third_party/WebKit/public/web/WebLocalFrame.h"
13 #include "third_party/WebKit/public/web/WebPerformance.h"
13 #include "v8/include/v8.h" 14 #include "v8/include/v8.h"
14 15
15 using blink::WebDataSource; 16 using blink::WebDataSource;
16 using blink::WebLocalFrame; 17 using blink::WebLocalFrame;
17 using blink::WebNavigationType; 18 using blink::WebNavigationType;
19 using blink::WebPerformance;
18 using content::DocumentState; 20 using content::DocumentState;
19 21
20 // Values for CSI "tran" property 22 // Values for CSI "tran" property
21 const int kTransitionLink = 0; 23 const int kTransitionLink = 0;
22 const int kTransitionForwardBack = 6; 24 const int kTransitionForwardBack = 6;
23 const int kTransitionOther = 15; 25 const int kTransitionOther = 15;
24 const int kTransitionReload = 16; 26 const int kTransitionReload = 16;
25 27
26 namespace extensions_v8 { 28 namespace extensions_v8 {
27 29
28 static const char* const kLoadTimesExtensionName = "v8/LoadTimes"; 30 static const char* const kLoadTimesExtensionName = "v8/LoadTimes";
29 31
30 class LoadTimesExtensionWrapper : public v8::Extension { 32 class LoadTimesExtensionWrapper : public v8::Extension {
31 public: 33 public:
32 // Creates an extension which adds a new function, chromium.GetLoadTimes() 34 // Creates an extension which adds a new function, chrome.loadTimes()
33 // This function returns an object containing the following members: 35 // This function returns an object containing the following members:
34 // requestTime: The time the request to load the page was received 36 // requestTime: The time the request to load the page was received
35 // loadTime: The time the renderer started the load process 37 // loadTime: The time the renderer started the load process
36 // finishDocumentLoadTime: The time the document itself was loaded 38 // finishDocumentLoadTime: The time the document itself was loaded
37 // (this is before the onload() method is fired) 39 // (this is before the onload() method is fired)
38 // finishLoadTime: The time all loading is done, after the onload() 40 // finishLoadTime: The time all loading is done, after the onload()
39 // method and all resources 41 // method and all resources
40 // navigationType: A string describing what user action initiated the load 42 // navigationType: A string describing what user action initiated the load
43 //
44 // Note that chrome.loadTimes() is deprecated in favor of performance.timing.
45 // Many of the timings reported via chrome.loadTimes() match timings available
46 // in performance.timing. Timing data will be removed from chrome.loadTimes()
47 // in a future release. No new timings or other information should be exposed
48 // via these APIs.
41 LoadTimesExtensionWrapper() : 49 LoadTimesExtensionWrapper() :
42 v8::Extension(kLoadTimesExtensionName, 50 v8::Extension(kLoadTimesExtensionName,
43 "var chrome;" 51 "var chrome;"
44 "if (!chrome)" 52 "if (!chrome)"
45 " chrome = {};" 53 " chrome = {};"
46 "chrome.loadTimes = function() {" 54 "chrome.loadTimes = function() {"
47 " native function GetLoadTimes();" 55 " native function GetLoadTimes();"
48 " return GetLoadTimes();" 56 " return GetLoadTimes();"
49 "};" 57 "};"
50 "chrome.csi = function() {" 58 "chrome.csi = function() {"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return; 112 return;
105 } 113 }
106 WebDataSource* data_source = frame->dataSource(); 114 WebDataSource* data_source = frame->dataSource();
107 if (!data_source) { 115 if (!data_source) {
108 return; 116 return;
109 } 117 }
110 DocumentState* document_state = DocumentState::FromDataSource(data_source); 118 DocumentState* document_state = DocumentState::FromDataSource(data_source);
111 if (!document_state) { 119 if (!document_state) {
112 return; 120 return;
113 } 121 }
114 double request_time = document_state->request_time().ToDoubleT(); 122 WebPerformance web_performance = frame->performance();
115 double start_load_time = document_state->start_load_time().ToDoubleT(); 123 // Though request time now tends to be used to describe the time that the
116 double commit_load_time = document_state->commit_load_time().ToDoubleT(); 124 // request for the main resource was issued, when chrome.loadTimes() was
125 // added, it was used to describe 'The time the request to load the page was
126 // received', which is the time now known as navigation start. For backward
127 // compatibility, we continue to provide request_time, setting its value to
128 // navigation start.
129 double request_time = web_performance.navigationStart();
130 // Developers often use start_load_time as the time the navigation was
131 // started, so we return navigationStart for this value as well. See
132 // https://gist.github.com/search?utf8=%E2%9C%93&q=startLoadTime.
133 // Note that, historically, start_load_time reported the time that a
134 // provisional load was first processed in the render process. For
135 // browser-initiated navigations, this is some time after navigation start,
136 // which means that developers who used this value as a way to track the
137 // start of a navigation were misusing this timestamp and getting the wrong
138 // value - they should be using navigationStart intead. Additionally,
139 // once plznavigate ships, provisional loads will not be processed by the
140 // render process for browser-initiated navigations, so reporting the time a
141 // provisional load was processed in the render process will no longer make
142 // sense. Thus, we now report the time for navigationStart, which is a value
143 // more consistent with what developers currently use start_load_time for.
144 double start_load_time = web_performance.navigationStart();
145 // TODO(bmcquade): Remove this. 'commit' time is a concept internal to
146 // chrome that shouldn't be exposed to the web platform.
147 double commit_load_time = web_performance.responseStart();
117 double finish_document_load_time = 148 double finish_document_load_time =
118 document_state->finish_document_load_time().ToDoubleT(); 149 web_performance.domContentLoadedEventEnd();
119 double finish_load_time = document_state->finish_load_time().ToDoubleT(); 150 double finish_load_time = web_performance.loadEventEnd();
120 double first_paint_time = document_state->first_paint_time().ToDoubleT(); 151 double first_paint_time = web_performance.firstPaint();
121 double first_paint_after_load_time = 152 // TODO(bmcquade): remove this. It's misleading to track the first paint
122 document_state->first_paint_after_load_time().ToDoubleT(); 153 // after the load event, since many pages perform their meaningful paints
154 // long before the load event fires. We report a time of zero for the
155 // time being.
156 double first_paint_after_load_time = 0.0;
123 std::string navigation_type = 157 std::string navigation_type =
124 GetNavigationType(data_source->navigationType()); 158 GetNavigationType(data_source->navigationType());
125 bool was_fetched_via_spdy = document_state->was_fetched_via_spdy(); 159 bool was_fetched_via_spdy = document_state->was_fetched_via_spdy();
126 bool was_npn_negotiated = document_state->was_npn_negotiated(); 160 bool was_npn_negotiated = document_state->was_npn_negotiated();
127 std::string npn_negotiated_protocol = 161 std::string npn_negotiated_protocol =
128 document_state->npn_negotiated_protocol(); 162 document_state->npn_negotiated_protocol();
129 bool was_alternate_protocol_available = 163 bool was_alternate_protocol_available =
130 document_state->was_alternate_protocol_available(); 164 document_state->was_alternate_protocol_available();
131 std::string connection_info = net::HttpResponseInfo::ConnectionInfoToString( 165 std::string connection_info = net::HttpResponseInfo::ConnectionInfoToString(
132 document_state->connection_info()); 166 document_state->connection_info());
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 346 }
313 args.GetReturnValue().Set(csi); 347 args.GetReturnValue().Set(csi);
314 } 348 }
315 }; 349 };
316 350
317 v8::Extension* LoadTimesExtension::Get() { 351 v8::Extension* LoadTimesExtension::Get() {
318 return new LoadTimesExtensionWrapper(); 352 return new LoadTimesExtensionWrapper();
319 } 353 }
320 354
321 } // namespace extensions_v8 355 } // namespace extensions_v8
OLDNEW
« 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