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 "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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, | 201 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, |
| 202 aborted_chain_size_same_url); | 202 aborted_chain_size_same_url); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace | 206 } // namespace |
| 207 | 207 |
| 208 PageLoadTracker::PageLoadTracker( | 208 PageLoadTracker::PageLoadTracker( |
| 209 bool in_foreground, | 209 bool in_foreground, |
| 210 PageLoadMetricsEmbedderInterface* embedder_interface, | 210 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 211 PageLoadTracker* const currently_committed_load_or_null, | 211 const GURL& currently_committed_url, |
| 212 content::NavigationHandle* navigation_handle, | 212 content::NavigationHandle* navigation_handle, |
| 213 int aborted_chain_size, | 213 int aborted_chain_size, |
| 214 int aborted_chain_size_same_url) | 214 int aborted_chain_size_same_url) |
| 215 : renderer_tracked_(false), | 215 : renderer_tracked_(false), |
| 216 navigation_start_(navigation_handle->NavigationStart()), | 216 navigation_start_(navigation_handle->NavigationStart()), |
| 217 url_(navigation_handle->GetURL()), | 217 url_(navigation_handle->GetURL()), |
| 218 abort_type_(ABORT_NONE), | 218 abort_type_(ABORT_NONE), |
| 219 started_in_foreground_(in_foreground), | 219 started_in_foreground_(in_foreground), |
| 220 aborted_chain_size_(aborted_chain_size), | 220 aborted_chain_size_(aborted_chain_size), |
| 221 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 221 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
| 222 embedder_interface_(embedder_interface) { | 222 embedder_interface_(embedder_interface) { |
| 223 DCHECK(!navigation_handle->HasCommitted()); | 223 DCHECK(!navigation_handle->HasCommitted()); |
| 224 embedder_interface_->RegisterObservers(this); | 224 embedder_interface_->RegisterObservers(this); |
| 225 const GURL& currently_committed_url = | |
| 226 currently_committed_load_or_null | |
| 227 ? currently_committed_load_or_null->committed_url() | |
| 228 : GURL::EmptyGURL(); | |
| 229 for (const auto& observer : observers_) { | 225 for (const auto& observer : observers_) { |
| 230 observer->OnStart(navigation_handle, currently_committed_url); | 226 observer->OnStart(navigation_handle, currently_committed_url); |
| 231 } | 227 } |
| 232 } | 228 } |
| 233 | 229 |
| 234 PageLoadTracker::~PageLoadTracker() { | 230 PageLoadTracker::~PageLoadTracker() { |
| 235 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); | 231 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); |
| 236 if (!info.time_to_commit.is_zero() && renderer_tracked() && | 232 if (!info.time_to_commit.is_zero() && renderer_tracked() && |
| 237 timing_.IsEmpty()) { | 233 timing_.IsEmpty()) { |
| 238 RecordInternalError(ERR_NO_IPCS_RECEIVED); | 234 RecordInternalError(ERR_NO_IPCS_RECEIVED); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 abort_type_ = abort_type; | 451 abort_type_ = abort_type; |
| 456 abort_time_ = timestamp; | 452 abort_time_ = timestamp; |
| 457 } | 453 } |
| 458 | 454 |
| 459 // static | 455 // static |
| 460 MetricsWebContentsObserver::MetricsWebContentsObserver( | 456 MetricsWebContentsObserver::MetricsWebContentsObserver( |
| 461 content::WebContents* web_contents, | 457 content::WebContents* web_contents, |
| 462 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) | 458 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
| 463 : content::WebContentsObserver(web_contents), | 459 : content::WebContentsObserver(web_contents), |
| 464 in_foreground_(false), | 460 in_foreground_(false), |
| 465 embedder_interface_(std::move(embedder_interface)) {} | 461 embedder_interface_(std::move(embedder_interface)), |
| 462 has_commit_(false) {} | |
| 466 | 463 |
| 467 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( | 464 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( |
| 468 content::WebContents* web_contents, | 465 content::WebContents* web_contents, |
| 469 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { | 466 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { |
| 470 DCHECK(web_contents); | 467 DCHECK(web_contents); |
| 471 | 468 |
| 472 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); | 469 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
| 473 if (!metrics) { | 470 if (!metrics) { |
| 474 metrics = new MetricsWebContentsObserver(web_contents, | 471 metrics = new MetricsWebContentsObserver(web_contents, |
| 475 std::move(embedder_interface)); | 472 std::move(embedder_interface)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 if (last_aborted) { | 507 if (last_aborted) { |
| 511 if (last_aborted->MatchesOriginalNavigation(navigation_handle)) { | 508 if (last_aborted->MatchesOriginalNavigation(navigation_handle)) { |
| 512 chain_size_same_url = last_aborted->aborted_chain_size_same_url() + 1; | 509 chain_size_same_url = last_aborted->aborted_chain_size_same_url() + 1; |
| 513 } else if (last_aborted->aborted_chain_size_same_url() > 0) { | 510 } else if (last_aborted->aborted_chain_size_same_url() > 0) { |
| 514 LogAbortChainSameURLHistogram( | 511 LogAbortChainSameURLHistogram( |
| 515 last_aborted->aborted_chain_size_same_url()); | 512 last_aborted->aborted_chain_size_same_url()); |
| 516 } | 513 } |
| 517 chain_size = last_aborted->aborted_chain_size() + 1; | 514 chain_size = last_aborted->aborted_chain_size() + 1; |
| 518 } | 515 } |
| 519 | 516 |
| 517 // Pass in the last committed url to the PageLoadTracker. This is used for | |
| 518 // FromGWS metrics. If the MWCO has never observed a committed load, use the | |
| 519 // last committed url from this WebContent's opener. This is more accurate | |
| 520 // than using referrers due to referrer sanitizing and origin referrers. Note | |
| 521 // that this could potentially be inaccurate if the opener has since | |
| 522 // navigated. | |
| 523 content::WebContents* opener = web_contents()->GetOpener(); | |
| 524 const GURL& opener_url = | |
| 525 !has_commit_ && opener | |
| 526 ? web_contents()->GetOpener()->GetLastCommittedURL() | |
| 527 : GURL::EmptyGURL(); | |
| 528 const GURL currently_committed_url = | |
|
Bryan McQuade
2016/04/26 18:36:39
do you want this to be const GURL or const GURL& ?
Charlie Harrison
2016/04/26 19:02:41
const GURL&. Good catch.
| |
| 529 committed_load_ ? committed_load_->committed_url() : opener_url; | |
| 530 | |
| 520 // We can have two provisional loads in some cases. E.g. a same-site | 531 // We can have two provisional loads in some cases. E.g. a same-site |
| 521 // navigation can have a concurrent cross-process navigation started | 532 // navigation can have a concurrent cross-process navigation started |
| 522 // from the omnibox. | 533 // from the omnibox. |
| 523 DCHECK_GT(2ul, provisional_loads_.size()); | 534 DCHECK_GT(2ul, provisional_loads_.size()); |
| 524 // Passing raw pointers to observers_ and embedder_interface_ is safe because | 535 // Passing raw pointers to observers_ and embedder_interface_ is safe because |
| 525 // the MetricsWebContentsObserver owns them both list and they are torn down | 536 // the MetricsWebContentsObserver owns them both list and they are torn down |
| 526 // after the PageLoadTracker. The PageLoadTracker does not hold on to | 537 // after the PageLoadTracker. The PageLoadTracker does not hold on to |
| 527 // committed_load_ or navigation_handle beyond the scope of the constructor. | 538 // committed_load_ or navigation_handle beyond the scope of the constructor. |
| 528 provisional_loads_.insert(std::make_pair( | 539 provisional_loads_.insert(std::make_pair( |
| 529 navigation_handle, | 540 navigation_handle, |
| 530 base::WrapUnique(new PageLoadTracker( | 541 base::WrapUnique(new PageLoadTracker( |
| 531 in_foreground_, embedder_interface_.get(), committed_load_.get(), | 542 in_foreground_, embedder_interface_.get(), currently_committed_url, |
| 532 navigation_handle, chain_size, chain_size_same_url)))); | 543 navigation_handle, chain_size, chain_size_same_url)))); |
| 533 } | 544 } |
| 534 | 545 |
| 535 void MetricsWebContentsObserver::DidFinishNavigation( | 546 void MetricsWebContentsObserver::DidFinishNavigation( |
| 536 content::NavigationHandle* navigation_handle) { | 547 content::NavigationHandle* navigation_handle) { |
| 537 if (!navigation_handle->IsInMainFrame()) | 548 if (!navigation_handle->IsInMainFrame()) |
| 538 return; | 549 return; |
| 539 | 550 |
| 540 std::unique_ptr<PageLoadTracker> finished_nav( | 551 std::unique_ptr<PageLoadTracker> finished_nav( |
| 541 std::move(provisional_loads_[navigation_handle])); | 552 std::move(provisional_loads_[navigation_handle])); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 // Notify other loads that they may have been aborted by this committed load. | 589 // Notify other loads that they may have been aborted by this committed load. |
| 579 // Note that by using the committed navigation start as the abort cause, we | 590 // Note that by using the committed navigation start as the abort cause, we |
| 580 // lose data on provisional loads that were aborted by other provisional | 591 // lose data on provisional loads that were aborted by other provisional |
| 581 // loads. Those will either be listed as ABORT_OTHER or as being aborted by | 592 // loads. Those will either be listed as ABORT_OTHER or as being aborted by |
| 582 // this load. | 593 // this load. |
| 583 NotifyAbortAllLoadsWithTimestamp( | 594 NotifyAbortAllLoadsWithTimestamp( |
| 584 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), | 595 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), |
| 585 navigation_handle->NavigationStart()); | 596 navigation_handle->NavigationStart()); |
| 586 | 597 |
| 587 committed_load_ = std::move(finished_nav); | 598 committed_load_ = std::move(finished_nav); |
| 599 has_commit_ = true; | |
| 588 aborted_provisional_loads_.clear(); | 600 aborted_provisional_loads_.clear(); |
| 589 | 601 |
| 590 const GURL& browser_url = web_contents()->GetLastCommittedURL(); | 602 const GURL& browser_url = web_contents()->GetLastCommittedURL(); |
| 591 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 603 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
| 592 DCHECK(!browser_url.is_empty()); | 604 DCHECK(!browser_url.is_empty()); |
| 593 DCHECK(!mime_type.empty()); | 605 DCHECK(!mime_type.empty()); |
| 594 committed_load_->set_renderer_tracked( | 606 committed_load_->set_renderer_tracked( |
| 595 IsRelevantNavigation(navigation_handle, browser_url, mime_type)); | 607 IsRelevantNavigation(navigation_handle, browser_url, mime_type)); |
| 596 | 608 |
| 597 committed_load_->Commit(navigation_handle); | 609 committed_load_->Commit(navigation_handle); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 | 738 |
| 727 if (!committed_load_->UpdateTiming(timing, metadata)) { | 739 if (!committed_load_->UpdateTiming(timing, metadata)) { |
| 728 // If the page load tracker cannot update its timing, something is wrong | 740 // If the page load tracker cannot update its timing, something is wrong |
| 729 // with the IPC (it's from another load, or it's invalid in some other way). | 741 // with the IPC (it's from another load, or it's invalid in some other way). |
| 730 // We expect this to be a rare occurrence. | 742 // We expect this to be a rare occurrence. |
| 731 RecordInternalError(ERR_BAD_TIMING_IPC); | 743 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 732 } | 744 } |
| 733 } | 745 } |
| 734 | 746 |
| 735 } // namespace page_load_metrics | 747 } // namespace page_load_metrics |
| OLD | NEW |