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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 observer->OnFailedProvisionalLoad(navigation_handle); | 326 observer->OnFailedProvisionalLoad(navigation_handle); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { | 330 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { |
331 for (const auto& observer : observers_) { | 331 for (const auto& observer : observers_) { |
332 observer->OnRedirect(navigation_handle); | 332 observer->OnRedirect(navigation_handle); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { | 336 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing, |
| 337 const PageLoadMetadata& new_metadata) { |
337 // Throw away IPCs that are not relevant to the current navigation. | 338 // Throw away IPCs that are not relevant to the current navigation. |
338 // Two timing structures cannot refer to the same navigation if they indicate | 339 // Two timing structures cannot refer to the same navigation if they indicate |
339 // that a navigation started at different times, so a new timing struct with a | 340 // that a navigation started at different times, so a new timing struct with a |
340 // different start time from an earlier struct is considered invalid. | 341 // different start time from an earlier struct is considered invalid. |
341 bool valid_timing_descendent = | 342 bool valid_timing_descendent = |
342 timing_.navigation_start.is_null() || | 343 timing_.navigation_start.is_null() || |
343 timing_.navigation_start == new_timing.navigation_start; | 344 timing_.navigation_start == new_timing.navigation_start; |
344 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { | 345 // Ensure flags sent previously are still present in the new metadata fields. |
| 346 bool valid_behavior_descendent = |
| 347 (metadata_.behavior_flags & new_metadata.behavior_flags) == |
| 348 metadata_.behavior_flags; |
| 349 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && |
| 350 valid_behavior_descendent) { |
345 timing_ = new_timing; | 351 timing_ = new_timing; |
| 352 metadata_ = new_metadata; |
346 return true; | 353 return true; |
347 } | 354 } |
348 return false; | 355 return false; |
349 } | 356 } |
350 | 357 |
351 bool PageLoadTracker::HasBackgrounded() { | 358 bool PageLoadTracker::HasBackgrounded() { |
352 return !started_in_foreground_ || !background_time_.is_null(); | 359 return !started_in_foreground_ || !background_time_.is_null(); |
353 } | 360 } |
354 | 361 |
355 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { | 362 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { |
(...skipping 20 matching lines...) Expand all Loading... |
376 } else { | 383 } else { |
377 DCHECK(abort_time_.is_null()); | 384 DCHECK(abort_time_.is_null()); |
378 } | 385 } |
379 | 386 |
380 if (!commit_time_.is_null()) { | 387 if (!commit_time_.is_null()) { |
381 DCHECK_GT(commit_time_, navigation_start_); | 388 DCHECK_GT(commit_time_, navigation_start_); |
382 time_to_commit = commit_time_ - navigation_start_; | 389 time_to_commit = commit_time_ - navigation_start_; |
383 } else { | 390 } else { |
384 DCHECK(commit_time_.is_null()); | 391 DCHECK(commit_time_.is_null()); |
385 } | 392 } |
386 return PageLoadExtraInfo(first_background_time, first_foreground_time, | 393 return PageLoadExtraInfo( |
387 started_in_foreground_, | 394 first_background_time, first_foreground_time, started_in_foreground_, |
388 commit_time_.is_null() ? GURL() : url_, | 395 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_, |
389 time_to_commit, abort_type_, time_to_abort); | 396 time_to_abort, metadata_); |
390 } | 397 } |
391 | 398 |
392 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, | 399 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, |
393 base::TimeTicks timestamp) { | 400 base::TimeTicks timestamp) { |
394 DCHECK_NE(abort_type, ABORT_NONE); | 401 DCHECK_NE(abort_type, ABORT_NONE); |
395 // Use UpdateAbort to update an already notified PageLoadTracker. | 402 // Use UpdateAbort to update an already notified PageLoadTracker. |
396 if (abort_type_ != ABORT_NONE) | 403 if (abort_type_ != ABORT_NONE) |
397 return; | 404 return; |
398 | 405 |
399 UpdateAbortInternal(abort_type, timestamp); | 406 UpdateAbortInternal(abort_type, timestamp); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 base::TimeTicks timestamp = new_navigation->NavigationStart(); | 688 base::TimeTicks timestamp = new_navigation->NavigationStart(); |
682 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) | 689 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) |
683 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp); | 690 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp); |
684 | 691 |
685 aborted_provisional_loads_.clear(); | 692 aborted_provisional_loads_.clear(); |
686 return last_aborted_load; | 693 return last_aborted_load; |
687 } | 694 } |
688 | 695 |
689 void MetricsWebContentsObserver::OnTimingUpdated( | 696 void MetricsWebContentsObserver::OnTimingUpdated( |
690 content::RenderFrameHost* render_frame_host, | 697 content::RenderFrameHost* render_frame_host, |
691 const PageLoadTiming& timing) { | 698 const PageLoadTiming& timing, |
| 699 const PageLoadMetadata& metadata) { |
692 bool error = false; | 700 bool error = false; |
693 if (!committed_load_ || !committed_load_->renderer_tracked()) { | 701 if (!committed_load_ || !committed_load_->renderer_tracked()) { |
694 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); | 702 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); |
695 error = true; | 703 error = true; |
696 } | 704 } |
697 | 705 |
698 // We may receive notifications from frames that have been navigated away | 706 // We may receive notifications from frames that have been navigated away |
699 // from. We simply ignore them. | 707 // from. We simply ignore them. |
700 if (render_frame_host != web_contents()->GetMainFrame()) { | 708 if (render_frame_host != web_contents()->GetMainFrame()) { |
701 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); | 709 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); |
702 error = true; | 710 error = true; |
703 } | 711 } |
704 | 712 |
705 // For urls like chrome://newtab, the renderer and browser disagree, | 713 // For urls like chrome://newtab, the renderer and browser disagree, |
706 // so we have to double check that the renderer isn't sending data from a | 714 // so we have to double check that the renderer isn't sending data from a |
707 // bad url like https://www.google.com/_/chrome/newtab. | 715 // bad url like https://www.google.com/_/chrome/newtab. |
708 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { | 716 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { |
709 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); | 717 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); |
710 error = true; | 718 error = true; |
711 } | 719 } |
712 | 720 |
713 if (error) | 721 if (error) |
714 return; | 722 return; |
715 | 723 |
716 if (!committed_load_->UpdateTiming(timing)) { | 724 if (!committed_load_->UpdateTiming(timing, metadata)) { |
717 // If the page load tracker cannot update its timing, something is wrong | 725 // If the page load tracker cannot update its timing, something is wrong |
718 // with the IPC (it's from another load, or it's invalid in some other way). | 726 // with the IPC (it's from another load, or it's invalid in some other way). |
719 // We expect this to be a rare occurrence. | 727 // We expect this to be a rare occurrence. |
720 RecordInternalError(ERR_BAD_TIMING_IPC); | 728 RecordInternalError(ERR_BAD_TIMING_IPC); |
721 } | 729 } |
722 } | 730 } |
723 | 731 |
724 } // namespace page_load_metrics | 732 } // namespace page_load_metrics |
OLD | NEW |