Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc

Issue 2218583002: [page_load_metrics] Log cache warmth ratios at parse stop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig@ review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 num_cache_requests_(0),
263 num_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
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 ++num_cache_requests_;
486 } else {
487 ++num_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
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, num_cache_requests_, num_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
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. Navigations are hard to attribute
750 // here because we won't have a committed load by the time data streams in
751 // from the IO thread.
752 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME &&
753 net_error != net::OK) {
754 return;
755 }
756 if (!committed_load_)
757 return;
758 committed_load_->OnLoadedSubresource(was_cached);
759 }
760
735 const PageLoadExtraInfo 761 const PageLoadExtraInfo
736 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() { 762 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() {
737 DCHECK(committed_load_); 763 DCHECK(committed_load_);
738 return committed_load_->ComputePageLoadExtraInfo(); 764 return committed_load_->ComputePageLoadExtraInfo();
739 } 765 }
740 766
741 void MetricsWebContentsObserver::DidFinishNavigation( 767 void MetricsWebContentsObserver::DidFinishNavigation(
742 content::NavigationHandle* navigation_handle) { 768 content::NavigationHandle* navigation_handle) {
743 if (!navigation_handle->IsInMainFrame()) 769 if (!navigation_handle->IsInMainFrame())
744 return; 770 return;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) 1022 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage())
997 return false; 1023 return false;
998 const std::string& mime_type = web_contents()->GetContentsMimeType(); 1024 const std::string& mime_type = web_contents()->GetContentsMimeType();
999 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") 1025 if (mime_type != "text/html" && mime_type != "application/xhtml+xml")
1000 return false; 1026 return false;
1001 } 1027 }
1002 return true; 1028 return true;
1003 } 1029 }
1004 1030
1005 } // namespace page_load_metrics 1031 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698