| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 void LogAbortChainSameURLHistogram(int aborted_chain_size_same_url) { | 200 void LogAbortChainSameURLHistogram(int aborted_chain_size_same_url) { |
| 201 if (aborted_chain_size_same_url > 0) { | 201 if (aborted_chain_size_same_url > 0) { |
| 202 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, | 202 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, |
| 203 aborted_chain_size_same_url); | 203 aborted_chain_size_same_url); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 void DispatchObserverTimingCallbacks(PageLoadMetricsObserver* observer, | 207 void DispatchObserverTimingCallbacks(PageLoadMetricsObserver* observer, |
| 208 const PageLoadTiming& last_timing, | 208 const PageLoadTiming& last_timing, |
| 209 const PageLoadTiming& new_timing, | 209 const PageLoadTiming& new_timing, |
| 210 const PageLoadMetadata& last_metadata, |
| 210 const PageLoadExtraInfo& extra_info) { | 211 const PageLoadExtraInfo& extra_info) { |
| 211 observer->OnTimingUpdate(new_timing, extra_info); | 212 observer->OnTimingUpdate(new_timing, extra_info); |
| 212 if (!new_timing.dom_content_loaded_event_start.is_zero() && | 213 if (!new_timing.dom_content_loaded_event_start.is_zero() && |
| 213 last_timing.dom_content_loaded_event_start.is_zero()) | 214 last_timing.dom_content_loaded_event_start.is_zero()) |
| 214 observer->OnDomContentLoadedEventStart(new_timing, extra_info); | 215 observer->OnDomContentLoadedEventStart(new_timing, extra_info); |
| 215 if (!new_timing.load_event_start.is_zero() && | 216 if (!new_timing.load_event_start.is_zero() && |
| 216 last_timing.load_event_start.is_zero()) | 217 last_timing.load_event_start.is_zero()) |
| 217 observer->OnLoadEventStart(new_timing, extra_info); | 218 observer->OnLoadEventStart(new_timing, extra_info); |
| 218 if (!new_timing.first_layout.is_zero() && last_timing.first_layout.is_zero()) | 219 if (!new_timing.first_layout.is_zero() && last_timing.first_layout.is_zero()) |
| 219 observer->OnFirstLayout(new_timing, extra_info); | 220 observer->OnFirstLayout(new_timing, extra_info); |
| 220 if (!new_timing.first_paint.is_zero() && last_timing.first_paint.is_zero()) | 221 if (!new_timing.first_paint.is_zero() && last_timing.first_paint.is_zero()) |
| 221 observer->OnFirstPaint(new_timing, extra_info); | 222 observer->OnFirstPaint(new_timing, extra_info); |
| 222 if (!new_timing.first_text_paint.is_zero() && | 223 if (!new_timing.first_text_paint.is_zero() && |
| 223 last_timing.first_text_paint.is_zero()) | 224 last_timing.first_text_paint.is_zero()) |
| 224 observer->OnFirstTextPaint(new_timing, extra_info); | 225 observer->OnFirstTextPaint(new_timing, extra_info); |
| 225 if (!new_timing.first_image_paint.is_zero() && | 226 if (!new_timing.first_image_paint.is_zero() && |
| 226 last_timing.first_image_paint.is_zero()) | 227 last_timing.first_image_paint.is_zero()) |
| 227 observer->OnFirstImagePaint(new_timing, extra_info); | 228 observer->OnFirstImagePaint(new_timing, extra_info); |
| 228 if (!new_timing.first_contentful_paint.is_zero() && | 229 if (!new_timing.first_contentful_paint.is_zero() && |
| 229 last_timing.first_contentful_paint.is_zero()) | 230 last_timing.first_contentful_paint.is_zero()) |
| 230 observer->OnFirstContentfulPaint(new_timing, extra_info); | 231 observer->OnFirstContentfulPaint(new_timing, extra_info); |
| 231 if (!new_timing.parse_start.is_zero() && last_timing.parse_start.is_zero()) | 232 if (!new_timing.parse_start.is_zero() && last_timing.parse_start.is_zero()) |
| 232 observer->OnParseStart(new_timing, extra_info); | 233 observer->OnParseStart(new_timing, extra_info); |
| 233 if (!new_timing.parse_stop.is_zero() && last_timing.parse_stop.is_zero()) | 234 if (!new_timing.parse_stop.is_zero() && last_timing.parse_stop.is_zero()) |
| 234 observer->OnParseStop(new_timing, extra_info); | 235 observer->OnParseStop(new_timing, extra_info); |
| 236 if (extra_info.metadata.behavior_flags != last_metadata.behavior_flags) |
| 237 observer->OnLoadingBehaviorObserved(extra_info); |
| 235 } | 238 } |
| 236 | 239 |
| 237 } // namespace | 240 } // namespace |
| 238 | 241 |
| 239 PageLoadTracker::PageLoadTracker( | 242 PageLoadTracker::PageLoadTracker( |
| 240 bool in_foreground, | 243 bool in_foreground, |
| 241 PageLoadMetricsEmbedderInterface* embedder_interface, | 244 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 242 const GURL& currently_committed_url, | 245 const GURL& currently_committed_url, |
| 243 content::NavigationHandle* navigation_handle, | 246 content::NavigationHandle* navigation_handle, |
| 244 int aborted_chain_size, | 247 int aborted_chain_size, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && | 398 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && |
| 396 valid_behavior_descendent) { | 399 valid_behavior_descendent) { |
| 397 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo() | 400 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo() |
| 398 // must be called before DispatchObserverTimingCallbacks, but its | 401 // must be called before DispatchObserverTimingCallbacks, but its |
| 399 // implementation depends on the state of metadata_, so we need to update | 402 // implementation depends on the state of metadata_, so we need to update |
| 400 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of | 403 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of |
| 401 // timing here, update timing_ and metadata_, and then proceed to dispatch | 404 // timing here, update timing_ and metadata_, and then proceed to dispatch |
| 402 // the observer timing callbacks. | 405 // the observer timing callbacks. |
| 403 const PageLoadTiming last_timing = timing_; | 406 const PageLoadTiming last_timing = timing_; |
| 404 timing_ = new_timing; | 407 timing_ = new_timing; |
| 408 |
| 409 const PageLoadMetadata last_metadata = metadata_; |
| 405 metadata_ = new_metadata; | 410 metadata_ = new_metadata; |
| 406 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); | 411 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); |
| 407 for (const auto& observer : observers_) { | 412 for (const auto& observer : observers_) { |
| 408 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, | 413 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, |
| 409 info); | 414 last_metadata, info); |
| 410 } | 415 } |
| 411 return true; | 416 return true; |
| 412 } | 417 } |
| 413 return false; | 418 return false; |
| 414 } | 419 } |
| 415 | 420 |
| 416 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { | 421 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { |
| 417 renderer_tracked_ = renderer_tracked; | 422 renderer_tracked_ = renderer_tracked; |
| 418 } | 423 } |
| 419 | 424 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 | 835 |
| 831 if (!committed_load_->UpdateTiming(timing, metadata)) { | 836 if (!committed_load_->UpdateTiming(timing, metadata)) { |
| 832 // If the page load tracker cannot update its timing, something is wrong | 837 // If the page load tracker cannot update its timing, something is wrong |
| 833 // with the IPC (it's from another load, or it's invalid in some other way). | 838 // with the IPC (it's from another load, or it's invalid in some other way). |
| 834 // We expect this to be a rare occurrence. | 839 // We expect this to be a rare occurrence. |
| 835 RecordInternalError(ERR_BAD_TIMING_IPC); | 840 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 836 } | 841 } |
| 837 } | 842 } |
| 838 | 843 |
| 839 } // namespace page_load_metrics | 844 } // namespace page_load_metrics |
| OLD | NEW |