| 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 "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 bool in_foreground, | 282 bool in_foreground, |
| 283 PageLoadMetricsEmbedderInterface* embedder_interface, | 283 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 284 const GURL& currently_committed_url, | 284 const GURL& currently_committed_url, |
| 285 content::NavigationHandle* navigation_handle, | 285 content::NavigationHandle* navigation_handle, |
| 286 int aborted_chain_size, | 286 int aborted_chain_size, |
| 287 int aborted_chain_size_same_url) | 287 int aborted_chain_size_same_url) |
| 288 : did_stop_tracking_(false), | 288 : did_stop_tracking_(false), |
| 289 app_entered_background_(false), | 289 app_entered_background_(false), |
| 290 navigation_start_(navigation_handle->NavigationStart()), | 290 navigation_start_(navigation_handle->NavigationStart()), |
| 291 url_(navigation_handle->GetURL()), | 291 url_(navigation_handle->GetURL()), |
| 292 start_url_(url_), |
| 292 abort_type_(ABORT_NONE), | 293 abort_type_(ABORT_NONE), |
| 293 abort_user_initiated_(false), | 294 abort_user_initiated_(false), |
| 294 started_in_foreground_(in_foreground), | 295 started_in_foreground_(in_foreground), |
| 295 page_transition_(navigation_handle->GetPageTransition()), | 296 page_transition_(navigation_handle->GetPageTransition()), |
| 296 num_cache_requests_(0), | 297 num_cache_requests_(0), |
| 297 num_network_requests_(0), | 298 num_network_requests_(0), |
| 298 user_gesture_(IsNavigationUserInitiated(navigation_handle)), | 299 user_gesture_(IsNavigationUserInitiated(navigation_handle)), |
| 299 aborted_chain_size_(aborted_chain_size), | 300 aborted_chain_size_(aborted_chain_size), |
| 300 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 301 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
| 301 embedder_interface_(embedder_interface) { | 302 embedder_interface_(embedder_interface) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // different start time from an earlier struct is considered invalid. | 489 // different start time from an earlier struct is considered invalid. |
| 489 bool valid_timing_descendent = | 490 bool valid_timing_descendent = |
| 490 timing_.navigation_start.is_null() || | 491 timing_.navigation_start.is_null() || |
| 491 timing_.navigation_start == new_timing.navigation_start; | 492 timing_.navigation_start == new_timing.navigation_start; |
| 492 // Ensure flags sent previously are still present in the new metadata fields. | 493 // Ensure flags sent previously are still present in the new metadata fields. |
| 493 bool valid_behavior_descendent = | 494 bool valid_behavior_descendent = |
| 494 (metadata_.behavior_flags & new_metadata.behavior_flags) == | 495 (metadata_.behavior_flags & new_metadata.behavior_flags) == |
| 495 metadata_.behavior_flags; | 496 metadata_.behavior_flags; |
| 496 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && | 497 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && |
| 497 valid_behavior_descendent) { | 498 valid_behavior_descendent) { |
| 499 DCHECK(!commit_time_.is_null()); // OnCommit() must be called first. |
| 498 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo() | 500 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo() |
| 499 // must be called before DispatchObserverTimingCallbacks, but its | 501 // must be called before DispatchObserverTimingCallbacks, but its |
| 500 // implementation depends on the state of metadata_, so we need to update | 502 // implementation depends on the state of metadata_, so we need to update |
| 501 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of | 503 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of |
| 502 // timing here, update timing_ and metadata_, and then proceed to dispatch | 504 // timing here, update timing_ and metadata_, and then proceed to dispatch |
| 503 // the observer timing callbacks. | 505 // the observer timing callbacks. |
| 504 const PageLoadTiming last_timing = timing_; | 506 const PageLoadTiming last_timing = timing_; |
| 505 timing_ = new_timing; | 507 timing_ = new_timing; |
| 506 | 508 |
| 507 const PageLoadMetadata last_metadata = metadata_; | 509 const PageLoadMetadata last_metadata = metadata_; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 587 |
| 586 if (!commit_time_.is_null()) { | 588 if (!commit_time_.is_null()) { |
| 587 DCHECK_GE(commit_time_, navigation_start_); | 589 DCHECK_GE(commit_time_, navigation_start_); |
| 588 time_to_commit = commit_time_ - navigation_start_; | 590 time_to_commit = commit_time_ - navigation_start_; |
| 589 } | 591 } |
| 590 | 592 |
| 591 // abort_type_ == ABORT_NONE implies !abort_user_initiated_. | 593 // abort_type_ == ABORT_NONE implies !abort_user_initiated_. |
| 592 DCHECK(abort_type_ != ABORT_NONE || !abort_user_initiated_); | 594 DCHECK(abort_type_ != ABORT_NONE || !abort_user_initiated_); |
| 593 return PageLoadExtraInfo( | 595 return PageLoadExtraInfo( |
| 594 first_background_time, first_foreground_time, started_in_foreground_, | 596 first_background_time, first_foreground_time, started_in_foreground_, |
| 595 user_gesture_, commit_time_.is_null() ? GURL() : url_, time_to_commit, | 597 user_gesture_, commit_time_.is_null() ? GURL() : url_, start_url_, |
| 596 abort_type_, abort_user_initiated_, time_to_abort, num_cache_requests_, | 598 time_to_commit, abort_type_, abort_user_initiated_, time_to_abort, |
| 597 num_network_requests_, metadata_); | 599 num_cache_requests_, num_network_requests_, metadata_); |
| 598 } | 600 } |
| 599 | 601 |
| 600 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, | 602 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, |
| 601 bool user_initiated, | 603 bool user_initiated, |
| 602 base::TimeTicks timestamp, | 604 base::TimeTicks timestamp, |
| 603 bool is_certainly_browser_timestamp) { | 605 bool is_certainly_browser_timestamp) { |
| 604 DCHECK_NE(abort_type, ABORT_NONE); | 606 DCHECK_NE(abort_type, ABORT_NONE); |
| 605 // Use UpdateAbort to update an already notified PageLoadTracker. | 607 // Use UpdateAbort to update an already notified PageLoadTracker. |
| 606 if (abort_type_ != ABORT_NONE) | 608 if (abort_type_ != ABORT_NONE) |
| 607 return; | 609 return; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) | 1071 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) |
| 1070 return false; | 1072 return false; |
| 1071 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 1073 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
| 1072 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") | 1074 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") |
| 1073 return false; | 1075 return false; |
| 1074 } | 1076 } |
| 1075 return true; | 1077 return true; |
| 1076 } | 1078 } |
| 1077 | 1079 |
| 1078 } // namespace page_load_metrics | 1080 } // namespace page_load_metrics |
| OLD | NEW |