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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 observer->OnFailedProvisionalLoad(navigation_handle); | 358 observer->OnFailedProvisionalLoad(navigation_handle); |
359 } | 359 } |
360 } | 360 } |
361 | 361 |
362 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { | 362 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { |
363 for (const auto& observer : observers_) { | 363 for (const auto& observer : observers_) { |
364 observer->OnRedirect(navigation_handle); | 364 observer->OnRedirect(navigation_handle); |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 void PageLoadTracker::UserInteraction(blink::WebInputEvent::Type type) { | |
369 // Only log the first user interaction in a given page load. | |
370 if (user_interaction_time_.is_null()) { | |
Alexei Svitkine (slow)
2016/05/18 14:51:12
Nit: No {}'s
| |
371 user_interaction_time_ = base::TimeTicks::Now(); | |
372 } | |
373 | |
374 for (const auto& observer : observers_) { | |
375 observer->OnUserInteraction(type); | |
376 } | |
377 } | |
378 | |
368 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing, | 379 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing, |
369 const PageLoadMetadata& new_metadata) { | 380 const PageLoadMetadata& new_metadata) { |
370 // Throw away IPCs that are not relevant to the current navigation. | 381 // Throw away IPCs that are not relevant to the current navigation. |
371 // Two timing structures cannot refer to the same navigation if they indicate | 382 // Two timing structures cannot refer to the same navigation if they indicate |
372 // that a navigation started at different times, so a new timing struct with a | 383 // that a navigation started at different times, so a new timing struct with a |
373 // different start time from an earlier struct is considered invalid. | 384 // different start time from an earlier struct is considered invalid. |
374 bool valid_timing_descendent = | 385 bool valid_timing_descendent = |
375 timing_.navigation_start.is_null() || | 386 timing_.navigation_start.is_null() || |
376 timing_.navigation_start == new_timing.navigation_start; | 387 timing_.navigation_start == new_timing.navigation_start; |
377 // Ensure flags sent previously are still present in the new metadata fields. | 388 // Ensure flags sent previously are still present in the new metadata fields. |
(...skipping 26 matching lines...) Expand all Loading... | |
404 } | 415 } |
405 | 416 |
406 void PageLoadTracker::AddObserver( | 417 void PageLoadTracker::AddObserver( |
407 std::unique_ptr<PageLoadMetricsObserver> observer) { | 418 std::unique_ptr<PageLoadMetricsObserver> observer) { |
408 observers_.push_back(std::move(observer)); | 419 observers_.push_back(std::move(observer)); |
409 } | 420 } |
410 | 421 |
411 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { | 422 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { |
412 base::TimeDelta first_background_time; | 423 base::TimeDelta first_background_time; |
413 base::TimeDelta first_foreground_time; | 424 base::TimeDelta first_foreground_time; |
425 base::TimeDelta first_user_interaction_time; | |
414 base::TimeDelta time_to_abort; | 426 base::TimeDelta time_to_abort; |
415 base::TimeDelta time_to_commit; | 427 base::TimeDelta time_to_commit; |
416 if (!background_time_.is_null()) | 428 if (!background_time_.is_null()) |
417 first_background_time = background_time_ - navigation_start_; | 429 first_background_time = background_time_ - navigation_start_; |
418 if (!foreground_time_.is_null()) | 430 if (!foreground_time_.is_null()) |
419 first_foreground_time = foreground_time_ - navigation_start_; | 431 first_foreground_time = foreground_time_ - navigation_start_; |
432 if (!user_interaction_time_.is_null()) | |
433 first_user_interaction_time = user_interaction_time_ - navigation_start_; | |
420 if (abort_type_ != ABORT_NONE) { | 434 if (abort_type_ != ABORT_NONE) { |
421 DCHECK_GT(abort_time_, navigation_start_); | 435 DCHECK_GT(abort_time_, navigation_start_); |
422 time_to_abort = abort_time_ - navigation_start_; | 436 time_to_abort = abort_time_ - navigation_start_; |
423 } else { | 437 } else { |
424 DCHECK(abort_time_.is_null()); | 438 DCHECK(abort_time_.is_null()); |
425 } | 439 } |
426 | 440 |
427 if (!commit_time_.is_null()) { | 441 if (!commit_time_.is_null()) { |
428 DCHECK_GT(commit_time_, navigation_start_); | 442 DCHECK_GT(commit_time_, navigation_start_); |
429 time_to_commit = commit_time_ - navigation_start_; | 443 time_to_commit = commit_time_ - navigation_start_; |
430 } else { | 444 } else { |
431 DCHECK(commit_time_.is_null()); | 445 DCHECK(commit_time_.is_null()); |
432 } | 446 } |
433 return PageLoadExtraInfo( | 447 return PageLoadExtraInfo( |
434 first_background_time, first_foreground_time, started_in_foreground_, | 448 first_background_time, first_foreground_time, first_user_interaction_time, |
435 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_, | 449 started_in_foreground_, commit_time_.is_null() ? GURL() : url_, |
436 time_to_abort, metadata_); | 450 time_to_commit, abort_type_, time_to_abort, metadata_); |
437 } | 451 } |
438 | 452 |
439 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, | 453 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, |
440 base::TimeTicks timestamp) { | 454 base::TimeTicks timestamp) { |
441 DCHECK_NE(abort_type, ABORT_NONE); | 455 DCHECK_NE(abort_type, ABORT_NONE); |
442 // Use UpdateAbort to update an already notified PageLoadTracker. | 456 // Use UpdateAbort to update an already notified PageLoadTracker. |
443 if (abort_type_ != ABORT_NONE) | 457 if (abort_type_ != ABORT_NONE) |
444 return; | 458 return; |
445 | 459 |
446 UpdateAbortInternal(abort_type, timestamp); | 460 UpdateAbortInternal(abort_type, timestamp); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 committed_load_->set_renderer_tracked( | 663 committed_load_->set_renderer_tracked( |
650 IsRelevantNavigation(navigation_handle, browser_url, mime_type)); | 664 IsRelevantNavigation(navigation_handle, browser_url, mime_type)); |
651 | 665 |
652 committed_load_->Commit(navigation_handle); | 666 committed_load_->Commit(navigation_handle); |
653 } | 667 } |
654 | 668 |
655 void MetricsWebContentsObserver::NavigationStopped() { | 669 void MetricsWebContentsObserver::NavigationStopped() { |
656 NotifyAbortAllLoads(ABORT_STOP); | 670 NotifyAbortAllLoads(ABORT_STOP); |
657 } | 671 } |
658 | 672 |
673 void MetricsWebContentsObserver::DidGetUserInteraction( | |
674 const blink::WebInputEvent::Type type) { | |
675 // ignore browser navigation or reload which comes with type Undefined | |
676 if (type != blink::WebInputEvent::Type::Undefined) { | |
Bryan McQuade
2016/05/18 15:21:50
based on the comment, do you want to ignore if typ
| |
677 } else { | |
Alexei Svitkine (slow)
2016/05/18 14:51:12
Nit: Reverse the cond and turn the if else into ju
| |
678 if (!committed_load_) { | |
679 RecordInternalError(ERR_USER_INTERACTION_WITH_NO_RELEVANT_LOAD); | |
680 return; | |
681 } | |
682 committed_load_->UserInteraction(type); | |
683 } | |
684 } | |
685 | |
659 void MetricsWebContentsObserver::DidRedirectNavigation( | 686 void MetricsWebContentsObserver::DidRedirectNavigation( |
660 content::NavigationHandle* navigation_handle) { | 687 content::NavigationHandle* navigation_handle) { |
661 if (!navigation_handle->IsInMainFrame()) | 688 if (!navigation_handle->IsInMainFrame()) |
662 return; | 689 return; |
663 auto it = provisional_loads_.find(navigation_handle); | 690 auto it = provisional_loads_.find(navigation_handle); |
664 if (it == provisional_loads_.end()) | 691 if (it == provisional_loads_.end()) |
665 return; | 692 return; |
666 it->second->Redirect(navigation_handle); | 693 it->second->Redirect(navigation_handle); |
667 } | 694 } |
668 | 695 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 | 808 |
782 if (!committed_load_->UpdateTiming(timing, metadata)) { | 809 if (!committed_load_->UpdateTiming(timing, metadata)) { |
783 // If the page load tracker cannot update its timing, something is wrong | 810 // If the page load tracker cannot update its timing, something is wrong |
784 // with the IPC (it's from another load, or it's invalid in some other way). | 811 // with the IPC (it's from another load, or it's invalid in some other way). |
785 // We expect this to be a rare occurrence. | 812 // We expect this to be a rare occurrence. |
786 RecordInternalError(ERR_BAD_TIMING_IPC); | 813 RecordInternalError(ERR_BAD_TIMING_IPC); |
787 } | 814 } |
788 } | 815 } |
789 | 816 |
790 } // namespace page_load_metrics | 817 } // namespace page_load_metrics |
OLD | NEW |