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

Side by Side Diff: content/public/renderer/navigation_state.h

Issue 8404018: chrome.loadTimes() shouldn't be affected by in-document navigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ 5 #ifndef CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
6 #define CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ 6 #define CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 23 matching lines...) Expand all
34 HISTORY_LOAD, // Back or forward. 34 HISTORY_LOAD, // Back or forward.
35 NORMAL_LOAD, // User entered URL, or omnibox search. 35 NORMAL_LOAD, // User entered URL, or omnibox search.
36 LINK_LOAD, // (deprecated) Included next 4 categories. 36 LINK_LOAD, // (deprecated) Included next 4 categories.
37 LINK_LOAD_NORMAL, // Commonly following of link. 37 LINK_LOAD_NORMAL, // Commonly following of link.
38 LINK_LOAD_RELOAD, // JS/link directed reload. 38 LINK_LOAD_RELOAD, // JS/link directed reload.
39 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change. 39 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change.
40 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post) 40 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post)
41 kLoadTypeMax // Bounding value for this enum. 41 kLoadTypeMax // Bounding value for this enum.
42 }; 42 };
43 43
44 // Contains pieces of NavigationState that are only relevant to the initial
45 // page load. These are unaffected by in-document navigation.
46 class LoadTimes {
47 public:
48 LoadTimes(const base::Time& request_time);
49
50 // The time that this navigation was requested.
51 const base::Time& request_time() const {
52 return request_time_;
53 }
54 void set_request_time(const base::Time& value) {
55 DCHECK(start_load_time_.is_null());
56 request_time_ = value;
57 }
58
59 // The time that the document load started.
60 const base::Time& start_load_time() const {
61 return start_load_time_;
62 }
63 void set_start_load_time(const base::Time& value) {
64 // TODO(jar): This should not be set twice.
65 // DCHECK(!start_load_time_.is_null());
66 DCHECK(finish_document_load_time_.is_null());
67 start_load_time_ = value;
68 }
69
70 // The time that the document load was committed.
71 const base::Time& commit_load_time() const {
72 return commit_load_time_;
73 }
74 void set_commit_load_time(const base::Time& value) {
75 commit_load_time_ = value;
76 }
77
78 // The time that the document finished loading.
79 const base::Time& finish_document_load_time() const {
80 return finish_document_load_time_;
81 }
82 void set_finish_document_load_time(const base::Time& value) {
83 // TODO(jar): Some unittests break the following DCHECK, and don't have
84 // DCHECK(!start_load_time_.is_null());
85 DCHECK(!value.is_null());
86 // TODO(jar): Double setting does happen, but probably shouldn't.
87 // DCHECK(finish_document_load_time_.is_null());
88 // TODO(jar): We should guarantee this order :-(.
89 // DCHECK(finish_load_time_.is_null());
90 finish_document_load_time_ = value;
91 }
92
93 // The time that the document and all subresources finished loading.
94 const base::Time& finish_load_time() const { return finish_load_time_; }
95 void set_finish_load_time(const base::Time& value) {
96 DCHECK(!value.is_null());
97 DCHECK(finish_load_time_.is_null());
98 // The following is not already set in all cases :-(
99 // DCHECK(!finish_document_load_time_.is_null());
100 finish_load_time_ = value;
101 }
102
103 // The time that painting first happened after a new navigation.
104 const base::Time& first_paint_time() const { return first_paint_time_; }
105 void set_first_paint_time(const base::Time& value) {
106 first_paint_time_ = value;
107 }
108
109 // The time that painting first happened after the document loaded.
110 const base::Time& first_paint_after_load_time() const {
111 return first_paint_after_load_time_;
112 }
113 void set_first_paint_after_load_time(const base::Time& value) {
114 first_paint_after_load_time_ = value;
115 }
116
117 // True iff the histograms for the associated frame have been dumped.
118 bool load_histograms_recorded() const { return load_histograms_recorded_; }
119 void set_load_histograms_recorded(bool value) {
120 load_histograms_recorded_ = value;
121 }
122
123 bool web_timing_histograms_recorded() const {
124 return web_timing_histograms_recorded_;
125 }
126 void set_web_timing_histograms_recorded(bool value) {
127 web_timing_histograms_recorded_ = value;
128 }
129
130 int http_status_code() const { return http_status_code_; }
131 void set_http_status_code(int http_status_code) {
132 http_status_code_ = http_status_code;
133 }
134
135 // Indicator if SPDY was used as part of this page load.
136 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; }
137 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; }
138
139 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; }
140 bool was_npn_negotiated() const { return was_npn_negotiated_; }
141
142 void set_was_alternate_protocol_available(bool value) {
143 was_alternate_protocol_available_ = value;
144 }
145 bool was_alternate_protocol_available() const {
146 return was_alternate_protocol_available_;
147 }
148
149 void set_was_fetched_via_proxy(bool value) {
150 was_fetched_via_proxy_ = value;
151 }
152 bool was_fetched_via_proxy() const { return was_fetched_via_proxy_; }
153
154 private:
155 base::Time request_time_;
156 base::Time start_load_time_;
157 base::Time commit_load_time_;
158 base::Time finish_document_load_time_;
159 base::Time finish_load_time_;
160 base::Time first_paint_time_;
161 base::Time first_paint_after_load_time_;
162 bool load_histograms_recorded_;
163 bool web_timing_histograms_recorded_;
164 int http_status_code_;
165 bool was_fetched_via_spdy_;
166 bool was_npn_negotiated_;
167 bool was_alternate_protocol_available_;
168 bool was_fetched_via_proxy_;
169 };
170
44 virtual ~NavigationState(); 171 virtual ~NavigationState();
45 172
46 static NavigationState* CreateBrowserInitiated( 173 static NavigationState* CreateBrowserInitiated(
47 int32 pending_page_id, 174 int32 pending_page_id,
48 int pending_history_list_offset, 175 int pending_history_list_offset,
49 content::PageTransition transition_type, 176 content::PageTransition transition_type,
50 base::Time request_time) { 177 base::Time request_time) {
51 return new NavigationState(transition_type, request_time, false, 178 return new NavigationState(LoadTimes(request_time), transition_type,
52 pending_page_id, 179 false, pending_page_id,
53 pending_history_list_offset); 180 pending_history_list_offset);
54 } 181 }
55 182
56 static NavigationState* CreateContentInitiated() { 183 static NavigationState* CreateContentInitiated(WebKit::WebDataSource* ds) {
184 NavigationState* prior_state = FromDataSource(ds);
57 // We assume navigations initiated by content are link clicks. 185 // We assume navigations initiated by content are link clicks.
58 return new NavigationState( 186 if (prior_state) {
59 content::PAGE_TRANSITION_LINK, base::Time(), true, -1, -1); 187 return new NavigationState(*prior_state->load_times(),
188 content::PAGE_TRANSITION_LINK, true, -1, -1);
189 } else {
190 return new NavigationState(
191 LoadTimes(base::Time()), content::PAGE_TRANSITION_LINK, true, -1, -1);
192 }
60 } 193 }
61 194
62 static NavigationState* FromDataSource(WebKit::WebDataSource* ds) { 195 static NavigationState* FromDataSource(WebKit::WebDataSource* ds) {
63 return static_cast<NavigationState*>(ds->extraData()); 196 return static_cast<NavigationState*>(ds->extraData());
64 } 197 }
65 198
199 const LoadTimes* load_times() const { return &load_times_; }
200 LoadTimes* load_times() { return &load_times_; }
201
66 // Contains the page_id for this navigation or -1 if there is none yet. 202 // Contains the page_id for this navigation or -1 if there is none yet.
67 int32 pending_page_id() const { return pending_page_id_; } 203 int32 pending_page_id() const { return pending_page_id_; }
68 204
69 // If pending_page_id() is not -1, then this contains the corresponding 205 // If pending_page_id() is not -1, then this contains the corresponding
70 // offset of the page in the back/forward history list. 206 // offset of the page in the back/forward history list.
71 int pending_history_list_offset() const { 207 int pending_history_list_offset() const {
72 return pending_history_list_offset_; 208 return pending_history_list_offset_;
73 } 209 }
74 210
75 // Contains the transition type that the browser specified when it 211 // Contains the transition type that the browser specified when it
76 // initiated the load. 212 // initiated the load.
77 content::PageTransition transition_type() const { return transition_type_; } 213 content::PageTransition transition_type() const { return transition_type_; }
78 void set_transition_type(content::PageTransition type) { 214 void set_transition_type(content::PageTransition type) {
79 transition_type_ = type; 215 transition_type_ = type;
80 } 216 }
81 217
82 // Record the nature of this load, for use when histogramming page load times. 218 // Record the nature of this load, for use when histogramming page load times.
83 LoadType load_type() const { return load_type_; } 219 LoadType load_type() const { return load_type_; }
84 void set_load_type(LoadType load_type) { load_type_ = load_type; } 220 void set_load_type(LoadType load_type) { load_type_ = load_type; }
85 221
86 // The time that this navigation was requested.
87 const base::Time& request_time() const {
88 return request_time_;
89 }
90 void set_request_time(const base::Time& value) {
91 DCHECK(start_load_time_.is_null());
92 request_time_ = value;
93 }
94
95 // The time that the document load started.
96 const base::Time& start_load_time() const {
97 return start_load_time_;
98 }
99 void set_start_load_time(const base::Time& value) {
100 // TODO(jar): This should not be set twice.
101 // DCHECK(!start_load_time_.is_null());
102 DCHECK(finish_document_load_time_.is_null());
103 start_load_time_ = value;
104 }
105
106 // The time that the document load was committed.
107 const base::Time& commit_load_time() const {
108 return commit_load_time_;
109 }
110 void set_commit_load_time(const base::Time& value) {
111 commit_load_time_ = value;
112 }
113
114 // The time that the document finished loading.
115 const base::Time& finish_document_load_time() const {
116 return finish_document_load_time_;
117 }
118 void set_finish_document_load_time(const base::Time& value) {
119 // TODO(jar): Some unittests break the following DCHECK, and don't have
120 // DCHECK(!start_load_time_.is_null());
121 DCHECK(!value.is_null());
122 // TODO(jar): Double setting does happen, but probably shouldn't.
123 // DCHECK(finish_document_load_time_.is_null());
124 // TODO(jar): We should guarantee this order :-(.
125 // DCHECK(finish_load_time_.is_null());
126 finish_document_load_time_ = value;
127 }
128
129 // The time that the document and all subresources finished loading.
130 const base::Time& finish_load_time() const { return finish_load_time_; }
131 void set_finish_load_time(const base::Time& value) {
132 DCHECK(!value.is_null());
133 DCHECK(finish_load_time_.is_null());
134 // The following is not already set in all cases :-(
135 // DCHECK(!finish_document_load_time_.is_null());
136 finish_load_time_ = value;
137 }
138
139 // The time that painting first happened after a new navigation.
140 const base::Time& first_paint_time() const { return first_paint_time_; }
141 void set_first_paint_time(const base::Time& value) {
142 first_paint_time_ = value;
143 }
144
145 // The time that painting first happened after the document finished loading.
146 const base::Time& first_paint_after_load_time() const {
147 return first_paint_after_load_time_;
148 }
149 void set_first_paint_after_load_time(const base::Time& value) {
150 first_paint_after_load_time_ = value;
151 }
152
153 // True iff the histograms for the associated frame have been dumped.
154 bool load_histograms_recorded() const { return load_histograms_recorded_; }
155 void set_load_histograms_recorded(bool value) {
156 load_histograms_recorded_ = value;
157 }
158
159 bool web_timing_histograms_recorded() const {
160 return web_timing_histograms_recorded_;
161 }
162 void set_web_timing_histograms_recorded(bool value) {
163 web_timing_histograms_recorded_ = value;
164 }
165
166 // True if we have already processed the "DidCommitLoad" event for this 222 // True if we have already processed the "DidCommitLoad" event for this
167 // request. Used by session history. 223 // request. Used by session history.
168 bool request_committed() const { return request_committed_; } 224 bool request_committed() const { return request_committed_; }
169 void set_request_committed(bool value) { request_committed_ = value; } 225 void set_request_committed(bool value) { request_committed_ = value; }
170 226
171 // True if this navigation was not initiated via WebFrame::LoadRequest. 227 // True if this navigation was not initiated via WebFrame::LoadRequest.
172 bool is_content_initiated() const { return is_content_initiated_; } 228 bool is_content_initiated() const { return is_content_initiated_; }
173 229
174 const GURL& searchable_form_url() const { return searchable_form_url_; } 230 const GURL& searchable_form_url() const { return searchable_form_url_; }
175 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; } 231 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
(...skipping 19 matching lines...) Expand all
195 security_info_ = security_info; 251 security_info_ = security_info;
196 } 252 }
197 253
198 // True if an error page should be used, if the http status code also 254 // True if an error page should be used, if the http status code also
199 // indicates an error. 255 // indicates an error.
200 bool use_error_page() const { return use_error_page_; } 256 bool use_error_page() const { return use_error_page_; }
201 void set_use_error_page(bool use_error_page) { 257 void set_use_error_page(bool use_error_page) {
202 use_error_page_ = use_error_page; 258 use_error_page_ = use_error_page;
203 } 259 }
204 260
205 int http_status_code() const { return http_status_code_; }
206 void set_http_status_code(int http_status_code) {
207 http_status_code_ = http_status_code;
208 }
209
210 // Sets the cache policy. The cache policy is only used if explicitly set and 261 // Sets the cache policy. The cache policy is only used if explicitly set and
211 // by default is not set. You can mark a NavigationState as not having a cache 262 // by default is not set. You can mark a NavigationState as not having a cache
212 // state by way of clear_cache_policy_override. 263 // state by way of clear_cache_policy_override.
213 void set_cache_policy_override( 264 void set_cache_policy_override(
214 WebKit::WebURLRequest::CachePolicy cache_policy) { 265 WebKit::WebURLRequest::CachePolicy cache_policy) {
215 cache_policy_override_ = cache_policy; 266 cache_policy_override_ = cache_policy;
216 cache_policy_override_set_ = true; 267 cache_policy_override_set_ = true;
217 } 268 }
218 WebKit::WebURLRequest::CachePolicy cache_policy_override() const { 269 WebKit::WebURLRequest::CachePolicy cache_policy_override() const {
219 return cache_policy_override_; 270 return cache_policy_override_;
220 } 271 }
221 void clear_cache_policy_override() { 272 void clear_cache_policy_override() {
222 cache_policy_override_set_ = false; 273 cache_policy_override_set_ = false;
223 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy; 274 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy;
224 } 275 }
225 bool is_cache_policy_override_set() const { 276 bool is_cache_policy_override_set() const {
226 return cache_policy_override_set_; 277 return cache_policy_override_set_;
227 } 278 }
228 279
229 // Indicator if SPDY was used as part of this page load.
230 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; }
231 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; }
232
233 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; }
234 bool was_npn_negotiated() const { return was_npn_negotiated_; }
235
236 void set_was_alternate_protocol_available(bool value) {
237 was_alternate_protocol_available_ = value;
238 }
239 bool was_alternate_protocol_available() const {
240 return was_alternate_protocol_available_;
241 }
242
243 void set_was_fetched_via_proxy(bool value) {
244 was_fetched_via_proxy_ = value;
245 }
246 bool was_fetched_via_proxy() const { return was_fetched_via_proxy_; }
247
248 // Whether the frame text contents was translated to a different language.
249 void set_was_translated(bool value) { was_translated_ = value; }
250 bool was_translated() const { return was_translated_; }
251
252 // True iff the frame's navigation was within the same page. 280 // True iff the frame's navigation was within the same page.
253 void set_was_within_same_page(bool value) { was_within_same_page_ = value; } 281 void set_was_within_same_page(bool value) { was_within_same_page_ = value; }
254 bool was_within_same_page() const { return was_within_same_page_; } 282 bool was_within_same_page() const { return was_within_same_page_; }
255 283
256 void set_was_prefetcher(bool value) { was_prefetcher_ = value; } 284 void set_was_prefetcher(bool value) { was_prefetcher_ = value; }
257 bool was_prefetcher() const { return was_prefetcher_; } 285 bool was_prefetcher() const { return was_prefetcher_; }
258 286
259 void set_was_referred_by_prefetcher(bool value) { 287 void set_was_referred_by_prefetcher(bool value) {
260 was_referred_by_prefetcher_ = value; 288 was_referred_by_prefetcher_ = value;
261 } 289 }
262 bool was_referred_by_prefetcher() const { 290 bool was_referred_by_prefetcher() const {
263 return was_referred_by_prefetcher_; 291 return was_referred_by_prefetcher_;
264 } 292 }
265 293
266 private: 294 private:
267 NavigationState(content::PageTransition transition_type, 295 NavigationState(const LoadTimes& load_times,
268 const base::Time& request_time, 296 content::PageTransition transition_type,
269 bool is_content_initiated, 297 bool is_content_initiated,
270 int32 pending_page_id, 298 int32 pending_page_id,
271 int pending_history_list_offset); 299 int pending_history_list_offset);
272 300
301 LoadTimes load_times_;
273 content::PageTransition transition_type_; 302 content::PageTransition transition_type_;
274 LoadType load_type_; 303 LoadType load_type_;
275 base::Time request_time_;
276 base::Time start_load_time_;
277 base::Time commit_load_time_;
278 base::Time finish_document_load_time_;
279 base::Time finish_load_time_;
280 base::Time first_paint_time_;
281 base::Time first_paint_after_load_time_;
282 bool load_histograms_recorded_;
283 bool web_timing_histograms_recorded_;
284 bool request_committed_; 304 bool request_committed_;
285 bool is_content_initiated_; 305 bool is_content_initiated_;
286 int32 pending_page_id_; 306 int32 pending_page_id_;
287 int pending_history_list_offset_; 307 int pending_history_list_offset_;
288 GURL searchable_form_url_; 308 GURL searchable_form_url_;
289 std::string searchable_form_encoding_; 309 std::string searchable_form_encoding_;
290 scoped_ptr<webkit_glue::PasswordForm> password_form_data_; 310 scoped_ptr<webkit_glue::PasswordForm> password_form_data_;
291 scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_; 311 scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_;
292 std::string security_info_; 312 std::string security_info_;
293 313
294 bool use_error_page_; 314 bool use_error_page_;
295 315
296 bool cache_policy_override_set_; 316 bool cache_policy_override_set_;
297 WebKit::WebURLRequest::CachePolicy cache_policy_override_; 317 WebKit::WebURLRequest::CachePolicy cache_policy_override_;
298 318
299 int http_status_code_;
300
301 bool was_fetched_via_spdy_;
302 bool was_npn_negotiated_;
303 bool was_alternate_protocol_available_;
304 bool was_fetched_via_proxy_;
305 bool was_translated_;
306 bool was_within_same_page_; 319 bool was_within_same_page_;
307 320
308 // A prefetcher is a page that contains link rel=prefetch elements. 321 // A prefetcher is a page that contains link rel=prefetch elements.
309 bool was_prefetcher_; 322 bool was_prefetcher_;
310 bool was_referred_by_prefetcher_; 323 bool was_referred_by_prefetcher_;
311 324
312 DISALLOW_COPY_AND_ASSIGN(NavigationState); 325 DISALLOW_COPY_AND_ASSIGN(NavigationState);
313 }; 326 };
314 327
315 #endif // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ 328 #endif // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
316 329
317 } // namespace content 330 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698