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_subresource_bytes_(0), | |
| 263 network_subresource_bytes_(0), | |
| 264 cache_requests_(0), | |
| 265 network_requests_(0), | |
| 262 aborted_chain_size_(aborted_chain_size), | 266 aborted_chain_size_(aborted_chain_size), |
| 263 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 267 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
| 264 embedder_interface_(embedder_interface) { | 268 embedder_interface_(embedder_interface) { |
| 265 DCHECK(!navigation_handle->HasCommitted()); | 269 DCHECK(!navigation_handle->HasCommitted()); |
| 266 embedder_interface_->RegisterObservers(this); | 270 embedder_interface_->RegisterObservers(this); |
| 267 for (const auto& observer : observers_) { | 271 for (const auto& observer : observers_) { |
| 268 observer->OnStart(navigation_handle, currently_committed_url, | 272 observer->OnStart(navigation_handle, currently_committed_url, |
| 269 started_in_foreground_); | 273 started_in_foreground_); |
| 270 } | 274 } |
| 271 } | 275 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); | 475 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); |
| 472 for (const auto& observer : observers_) { | 476 for (const auto& observer : observers_) { |
| 473 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, | 477 DispatchObserverTimingCallbacks(observer.get(), last_timing, new_timing, |
| 474 last_metadata, info); | 478 last_metadata, info); |
| 475 } | 479 } |
| 476 return true; | 480 return true; |
| 477 } | 481 } |
| 478 return false; | 482 return false; |
| 479 } | 483 } |
| 480 | 484 |
| 485 void PageLoadTracker::OnLoadedSubresource(int64_t bytes, bool was_cached) { | |
| 486 if (was_cached) { | |
| 487 ++cache_requests_; | |
| 488 cache_subresource_bytes_ += bytes; | |
| 489 } else { | |
| 490 ++network_requests_; | |
| 491 network_subresource_bytes_ += bytes; | |
| 492 } | |
| 493 } | |
| 494 | |
| 481 void PageLoadTracker::StopTracking() { | 495 void PageLoadTracker::StopTracking() { |
| 482 did_stop_tracking_ = true; | 496 did_stop_tracking_ = true; |
| 483 } | 497 } |
| 484 | 498 |
| 485 void PageLoadTracker::AddObserver( | 499 void PageLoadTracker::AddObserver( |
| 486 std::unique_ptr<PageLoadMetricsObserver> observer) { | 500 std::unique_ptr<PageLoadMetricsObserver> observer) { |
| 487 observers_.push_back(std::move(observer)); | 501 observers_.push_back(std::move(observer)); |
| 488 } | 502 } |
| 489 | 503 |
| 490 void PageLoadTracker::ClampBrowserTimestampIfInterProcessTimeTickSkew( | 504 void PageLoadTracker::ClampBrowserTimestampIfInterProcessTimeTickSkew( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 } | 552 } |
| 539 | 553 |
| 540 if (!commit_time_.is_null()) { | 554 if (!commit_time_.is_null()) { |
| 541 DCHECK_GE(commit_time_, navigation_start_); | 555 DCHECK_GE(commit_time_, navigation_start_); |
| 542 time_to_commit = commit_time_ - navigation_start_; | 556 time_to_commit = commit_time_ - navigation_start_; |
| 543 } | 557 } |
| 544 | 558 |
| 545 return PageLoadExtraInfo( | 559 return PageLoadExtraInfo( |
| 546 first_background_time, first_foreground_time, started_in_foreground_, | 560 first_background_time, first_foreground_time, started_in_foreground_, |
| 547 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_, | 561 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_, |
| 548 time_to_abort, metadata_); | 562 time_to_abort, cache_subresource_bytes_, network_subresource_bytes_, |
| 563 cache_requests_, network_requests_, metadata_); | |
| 549 } | 564 } |
| 550 | 565 |
| 551 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, | 566 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, |
| 552 base::TimeTicks timestamp, | 567 base::TimeTicks timestamp, |
| 553 bool is_certainly_browser_timestamp) { | 568 bool is_certainly_browser_timestamp) { |
| 554 DCHECK_NE(abort_type, ABORT_NONE); | 569 DCHECK_NE(abort_type, ABORT_NONE); |
| 555 // Use UpdateAbort to update an already notified PageLoadTracker. | 570 // Use UpdateAbort to update an already notified PageLoadTracker. |
| 556 if (abort_type_ != ABORT_NONE) | 571 if (abort_type_ != ABORT_NONE) |
| 557 return; | 572 return; |
| 558 | 573 |
| (...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 | 740 // the MetricsWebContentsObserver owns them both list and they are torn down |
| 726 // after the PageLoadTracker. The PageLoadTracker does not hold on to | 741 // after the PageLoadTracker. The PageLoadTracker does not hold on to |
| 727 // committed_load_ or navigation_handle beyond the scope of the constructor. | 742 // committed_load_ or navigation_handle beyond the scope of the constructor. |
| 728 provisional_loads_.insert(std::make_pair( | 743 provisional_loads_.insert(std::make_pair( |
| 729 navigation_handle, | 744 navigation_handle, |
| 730 base::WrapUnique(new PageLoadTracker( | 745 base::WrapUnique(new PageLoadTracker( |
| 731 in_foreground_, embedder_interface_.get(), currently_committed_url, | 746 in_foreground_, embedder_interface_.get(), currently_committed_url, |
| 732 navigation_handle, chain_size, chain_size_same_url)))); | 747 navigation_handle, chain_size, chain_size_same_url)))); |
| 733 } | 748 } |
| 734 | 749 |
| 750 void MetricsWebContentsObserver::OnRequestComplete( | |
| 751 content::ResourceType resource_type, | |
| 752 bool was_cached, | |
| 753 int net_error, | |
| 754 int64_t total_received_bytes, | |
| 755 int64_t raw_body_bytes) { | |
| 756 // For simplicity, only count subresources. | |
| 757 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME && | |
| 758 net_error != net::OK) { | |
| 759 return; | |
| 760 } | |
| 761 if (!committed_load_) | |
| 762 return; | |
| 763 int64_t bytes = was_cached ? raw_body_bytes : total_received_bytes; | |
|
Bryan McQuade
2016/08/08 18:53:28
is raw_body_bytes uncompressed but total_received_
Charlie Harrison
2016/08/08 20:55:02
Great point. I chatted with mmenke@ about this and
| |
| 764 committed_load_->OnLoadedSubresource(bytes, was_cached); | |
|
Bryan McQuade
2016/08/08 18:53:28
are we sure that all resources loaded are for the
Charlie Harrison
2016/08/08 20:55:02
I think this is reasonably accurate. If there are
| |
| 765 } | |
| 766 | |
| 735 const PageLoadExtraInfo | 767 const PageLoadExtraInfo |
| 736 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() { | 768 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() { |
| 737 DCHECK(committed_load_); | 769 DCHECK(committed_load_); |
| 738 return committed_load_->ComputePageLoadExtraInfo(); | 770 return committed_load_->ComputePageLoadExtraInfo(); |
| 739 } | 771 } |
| 740 | 772 |
| 741 void MetricsWebContentsObserver::DidFinishNavigation( | 773 void MetricsWebContentsObserver::DidFinishNavigation( |
| 742 content::NavigationHandle* navigation_handle) { | 774 content::NavigationHandle* navigation_handle) { |
| 743 if (!navigation_handle->IsInMainFrame()) | 775 if (!navigation_handle->IsInMainFrame()) |
| 744 return; | 776 return; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) | 1028 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) |
| 997 return false; | 1029 return false; |
| 998 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 1030 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
| 999 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") | 1031 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") |
| 1000 return false; | 1032 return false; |
| 1001 } | 1033 } |
| 1002 return true; | 1034 return true; |
| 1003 } | 1035 } |
| 1004 | 1036 |
| 1005 } // namespace page_load_metrics | 1037 } // namespace page_load_metrics |
| OLD | NEW |