| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return ABORT_OTHER; | 196 return ABORT_OTHER; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void LogAbortChainSameURLHistogram(int aborted_chain_size_same_url) { | 199 void LogAbortChainSameURLHistogram(int aborted_chain_size_same_url) { |
| 200 if (aborted_chain_size_same_url > 0) { | 200 if (aborted_chain_size_same_url > 0) { |
| 201 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, | 201 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, |
| 202 aborted_chain_size_same_url); | 202 aborted_chain_size_same_url); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 void DispatchObserverTimingCallbacks(PageLoadMetricsObserver* observer, |
| 207 const PageLoadTiming& last_timing, |
| 208 const PageLoadTiming& new_timing, |
| 209 const PageLoadExtraInfo& extra_info) { |
| 210 observer->OnTimingUpdate(new_timing, extra_info); |
| 211 if (!new_timing.dom_content_loaded_event_start.is_zero() && |
| 212 last_timing.dom_content_loaded_event_start.is_zero()) |
| 213 observer->OnDomContentLoadedEventStart(new_timing, extra_info); |
| 214 if (!new_timing.load_event_start.is_zero() && |
| 215 last_timing.load_event_start.is_zero()) |
| 216 observer->OnLoadEventStart(new_timing, extra_info); |
| 217 if (!new_timing.first_layout.is_zero() && last_timing.first_layout.is_zero()) |
| 218 observer->OnFirstLayout(new_timing, extra_info); |
| 219 if (!new_timing.first_paint.is_zero() && last_timing.first_paint.is_zero()) |
| 220 observer->OnFirstPaint(new_timing, extra_info); |
| 221 if (!new_timing.first_text_paint.is_zero() && |
| 222 last_timing.first_text_paint.is_zero()) |
| 223 observer->OnFirstTextPaint(new_timing, extra_info); |
| 224 if (!new_timing.first_image_paint.is_zero() && |
| 225 last_timing.first_image_paint.is_zero()) |
| 226 observer->OnFirstImagePaint(new_timing, extra_info); |
| 227 if (!new_timing.first_contentful_paint.is_zero() && |
| 228 last_timing.first_contentful_paint.is_zero()) |
| 229 observer->OnFirstContentfulPaint(new_timing, extra_info); |
| 230 if (!new_timing.parse_start.is_zero() && last_timing.parse_start.is_zero()) |
| 231 observer->OnParseStart(new_timing, extra_info); |
| 232 if (!new_timing.parse_stop.is_zero() && last_timing.parse_stop.is_zero()) |
| 233 observer->OnParseStop(new_timing, extra_info); |
| 234 } |
| 235 |
| 206 } // namespace | 236 } // namespace |
| 207 | 237 |
| 208 PageLoadTracker::PageLoadTracker( | 238 PageLoadTracker::PageLoadTracker( |
| 209 bool in_foreground, | 239 bool in_foreground, |
| 210 PageLoadMetricsEmbedderInterface* embedder_interface, | 240 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 211 const GURL& currently_committed_url, | 241 const GURL& currently_committed_url, |
| 212 content::NavigationHandle* navigation_handle, | 242 content::NavigationHandle* navigation_handle, |
| 213 int aborted_chain_size, | 243 int aborted_chain_size, |
| 214 int aborted_chain_size_same_url) | 244 int aborted_chain_size_same_url) |
| 215 : renderer_tracked_(false), | 245 : renderer_tracked_(false), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // different start time from an earlier struct is considered invalid. | 373 // different start time from an earlier struct is considered invalid. |
| 344 bool valid_timing_descendent = | 374 bool valid_timing_descendent = |
| 345 timing_.navigation_start.is_null() || | 375 timing_.navigation_start.is_null() || |
| 346 timing_.navigation_start == new_timing.navigation_start; | 376 timing_.navigation_start == new_timing.navigation_start; |
| 347 // Ensure flags sent previously are still present in the new metadata fields. | 377 // Ensure flags sent previously are still present in the new metadata fields. |
| 348 bool valid_behavior_descendent = | 378 bool valid_behavior_descendent = |
| 349 (metadata_.behavior_flags & new_metadata.behavior_flags) == | 379 (metadata_.behavior_flags & new_metadata.behavior_flags) == |
| 350 metadata_.behavior_flags; | 380 metadata_.behavior_flags; |
| 351 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && | 381 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && |
| 352 valid_behavior_descendent) { | 382 valid_behavior_descendent) { |
| 383 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo() |
| 384 // must be called before DispatchObserverTimingCallbacks, but its |
| 385 // implementation depends on the state of metadata_, so we need to update |
| 386 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of |
| 387 // timing here, update timing_ and metadata_, and then proceed to dispatch |
| 388 // the observer timing callbacks. |
| 389 const PageLoadTiming last_timing = timing_; |
| 353 timing_ = new_timing; | 390 timing_ = new_timing; |
| 354 metadata_ = new_metadata; | 391 metadata_ = new_metadata; |
| 355 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); | 392 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); |
| 356 for (const auto& observer : observers_) { | 393 for (const auto& observer : observers_) { |
| 357 observer->OnTimingUpdate(timing_, info); | 394 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, |
| 395 info); |
| 358 } | 396 } |
| 359 return true; | 397 return true; |
| 360 } | 398 } |
| 361 return false; | 399 return false; |
| 362 } | 400 } |
| 363 | 401 |
| 364 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { | 402 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { |
| 365 renderer_tracked_ = renderer_tracked; | 403 renderer_tracked_ = renderer_tracked; |
| 366 } | 404 } |
| 367 | 405 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 | 781 |
| 744 if (!committed_load_->UpdateTiming(timing, metadata)) { | 782 if (!committed_load_->UpdateTiming(timing, metadata)) { |
| 745 // If the page load tracker cannot update its timing, something is wrong | 783 // If the page load tracker cannot update its timing, something is wrong |
| 746 // with the IPC (it's from another load, or it's invalid in some other way). | 784 // with the IPC (it's from another load, or it's invalid in some other way). |
| 747 // We expect this to be a rare occurrence. | 785 // We expect this to be a rare occurrence. |
| 748 RecordInternalError(ERR_BAD_TIMING_IPC); | 786 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 749 } | 787 } |
| 750 } | 788 } |
| 751 | 789 |
| 752 } // namespace page_load_metrics | 790 } // namespace page_load_metrics |
| OLD | NEW |