Chromium Code Reviews| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 content::NavigationHandle* navigation_handle, | 252 content::NavigationHandle* navigation_handle, |
| 253 int aborted_chain_size, | 253 int aborted_chain_size, |
| 254 int aborted_chain_size_same_url) | 254 int aborted_chain_size_same_url) |
| 255 : did_stop_tracking_(false), | 255 : did_stop_tracking_(false), |
| 256 app_entered_background_(false), | 256 app_entered_background_(false), |
| 257 navigation_start_(navigation_handle->NavigationStart()), | 257 navigation_start_(navigation_handle->NavigationStart()), |
| 258 url_(navigation_handle->GetURL()), | 258 url_(navigation_handle->GetURL()), |
| 259 abort_type_(ABORT_NONE), | 259 abort_type_(ABORT_NONE), |
| 260 started_in_foreground_(in_foreground), | 260 started_in_foreground_(in_foreground), |
| 261 page_transition_(navigation_handle->GetPageTransition()), | 261 page_transition_(navigation_handle->GetPageTransition()), |
| 262 cache_requests_(0), | |
| 263 network_requests_(0), | |
| 262 aborted_chain_size_(aborted_chain_size), | 264 aborted_chain_size_(aborted_chain_size), |
| 263 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 265 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
| 264 embedder_interface_(embedder_interface) { | 266 embedder_interface_(embedder_interface) { |
| 265 DCHECK(!navigation_handle->HasCommitted()); | 267 DCHECK(!navigation_handle->HasCommitted()); |
| 266 embedder_interface_->RegisterObservers(this); | 268 embedder_interface_->RegisterObservers(this); |
| 267 for (const auto& observer : observers_) { | 269 for (const auto& observer : observers_) { |
| 268 observer->OnStart(navigation_handle, currently_committed_url, | 270 observer->OnStart(navigation_handle, currently_committed_url, |
| 269 started_in_foreground_); | 271 started_in_foreground_); |
| 270 } | 272 } |
| 271 } | 273 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); | 473 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); |
| 472 for (const auto& observer : observers_) { | 474 for (const auto& observer : observers_) { |
| 473 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, | 475 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, |
| 474 last_metadata, info); | 476 last_metadata, info); |
| 475 } | 477 } |
| 476 return true; | 478 return true; |
| 477 } | 479 } |
| 478 return false; | 480 return false; |
| 479 } | 481 } |
| 480 | 482 |
| 483 void PageLoadTracker::OnLoadedSubresource(bool was_cached) { | |
| 484 if (was_cached) { | |
| 485 ++cache_requests_; | |
| 486 } else { | |
| 487 ++network_requests_; | |
| 488 } | |
| 489 } | |
| 490 | |
| 481 void PageLoadTracker::StopTracking() { | 491 void PageLoadTracker::StopTracking() { |
| 482 did_stop_tracking_ = true; | 492 did_stop_tracking_ = true; |
| 483 } | 493 } |
| 484 | 494 |
| 485 void PageLoadTracker::AddObserver( | 495 void PageLoadTracker::AddObserver( |
| 486 std::unique_ptr<PageLoadMetricsObserver> observer) { | 496 std::unique_ptr<PageLoadMetricsObserver> observer) { |
| 487 observers_.push_back(std::move(observer)); | 497 observers_.push_back(std::move(observer)); |
| 488 } | 498 } |
| 489 | 499 |
| 490 void PageLoadTracker::ClampBrowserTimestampIfInterProcessTimeTickSkew( | 500 void PageLoadTracker::ClampBrowserTimestampIfInterProcessTimeTickSkew( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 } | 548 } |
| 539 | 549 |
| 540 if (!commit_time_.is_null()) { | 550 if (!commit_time_.is_null()) { |
| 541 DCHECK_GE(commit_time_, navigation_start_); | 551 DCHECK_GE(commit_time_, navigation_start_); |
| 542 time_to_commit = commit_time_ - navigation_start_; | 552 time_to_commit = commit_time_ - navigation_start_; |
| 543 } | 553 } |
| 544 | 554 |
| 545 return PageLoadExtraInfo( | 555 return PageLoadExtraInfo( |
| 546 first_background_time, first_foreground_time, started_in_foreground_, | 556 first_background_time, first_foreground_time, started_in_foreground_, |
| 547 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_, | 557 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_, |
| 548 time_to_abort, metadata_); | 558 time_to_abort, cache_requests_, network_requests_, metadata_); |
| 549 } | 559 } |
| 550 | 560 |
| 551 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, | 561 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, |
| 552 base::TimeTicks timestamp, | 562 base::TimeTicks timestamp, |
| 553 bool is_certainly_browser_timestamp) { | 563 bool is_certainly_browser_timestamp) { |
| 554 DCHECK_NE(abort_type, ABORT_NONE); | 564 DCHECK_NE(abort_type, ABORT_NONE); |
| 555 // Use UpdateAbort to update an already notified PageLoadTracker. | 565 // Use UpdateAbort to update an already notified PageLoadTracker. |
| 556 if (abort_type_ != ABORT_NONE) | 566 if (abort_type_ != ABORT_NONE) |
| 557 return; | 567 return; |
| 558 | 568 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 // the MetricsWebContentsObserver owns them both list and they are torn down | 735 // the MetricsWebContentsObserver owns them both list and they are torn down |
| 726 // after the PageLoadTracker. The PageLoadTracker does not hold on to | 736 // after the PageLoadTracker. The PageLoadTracker does not hold on to |
| 727 // committed_load_ or navigation_handle beyond the scope of the constructor. | 737 // committed_load_ or navigation_handle beyond the scope of the constructor. |
| 728 provisional_loads_.insert(std::make_pair( | 738 provisional_loads_.insert(std::make_pair( |
| 729 navigation_handle, | 739 navigation_handle, |
| 730 base::WrapUnique(new PageLoadTracker( | 740 base::WrapUnique(new PageLoadTracker( |
| 731 in_foreground_, embedder_interface_.get(), currently_committed_url, | 741 in_foreground_, embedder_interface_.get(), currently_committed_url, |
| 732 navigation_handle, chain_size, chain_size_same_url)))); | 742 navigation_handle, chain_size, chain_size_same_url)))); |
| 733 } | 743 } |
| 734 | 744 |
| 745 void MetricsWebContentsObserver::OnRequestComplete( | |
| 746 content::ResourceType resource_type, | |
| 747 bool was_cached, | |
| 748 int net_error) { | |
| 749 // For simplicity, only count subresources. | |
|
kinuko
2016/08/09 12:40:37
nit: this comment doesn't really say anything, wou
Charlie Harrison
2016/08/09 13:15:44
I added a comment. Essentially we do care about ma
| |
| 750 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME && | |
| 751 net_error != net::OK) { | |
| 752 return; | |
| 753 } | |
| 754 if (!committed_load_) | |
| 755 return; | |
| 756 committed_load_->OnLoadedSubresource(was_cached); | |
| 757 } | |
| 758 | |
| 735 const PageLoadExtraInfo | 759 const PageLoadExtraInfo |
| 736 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() { | 760 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() { |
| 737 DCHECK(committed_load_); | 761 DCHECK(committed_load_); |
| 738 return committed_load_->ComputePageLoadExtraInfo(); | 762 return committed_load_->ComputePageLoadExtraInfo(); |
| 739 } | 763 } |
| 740 | 764 |
| 741 void MetricsWebContentsObserver::DidFinishNavigation( | 765 void MetricsWebContentsObserver::DidFinishNavigation( |
| 742 content::NavigationHandle* navigation_handle) { | 766 content::NavigationHandle* navigation_handle) { |
| 743 if (!navigation_handle->IsInMainFrame()) | 767 if (!navigation_handle->IsInMainFrame()) |
| 744 return; | 768 return; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) | 1020 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) |
| 997 return false; | 1021 return false; |
| 998 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 1022 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
| 999 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") | 1023 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") |
| 1000 return false; | 1024 return false; |
| 1001 } | 1025 } |
| 1002 return true; | 1026 return true; |
| 1003 } | 1027 } |
| 1004 | 1028 |
| 1005 } // namespace page_load_metrics | 1029 } // namespace page_load_metrics |
| OLD | NEW |