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_navigated_(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 18 matching lines...) Expand all Loading... |
494 IPC_END_MESSAGE_MAP() | 491 IPC_END_MESSAGE_MAP() |
495 return handled; | 492 return handled; |
496 } | 493 } |
497 | 494 |
498 void MetricsWebContentsObserver::DidStartNavigation( | 495 void MetricsWebContentsObserver::DidStartNavigation( |
499 content::NavigationHandle* navigation_handle) { | 496 content::NavigationHandle* navigation_handle) { |
500 if (!navigation_handle->IsInMainFrame()) | 497 if (!navigation_handle->IsInMainFrame()) |
501 return; | 498 return; |
502 if (embedder_interface_->IsPrerendering(web_contents())) | 499 if (embedder_interface_->IsPrerendering(web_contents())) |
503 return; | 500 return; |
| 501 if (navigation_handle->GetURL().spec().compare(url::kAboutBlankURL) == 0) |
| 502 return; |
504 | 503 |
505 std::unique_ptr<PageLoadTracker> last_aborted = | 504 std::unique_ptr<PageLoadTracker> last_aborted = |
506 NotifyAbortedProvisionalLoadsNewNavigation(navigation_handle); | 505 NotifyAbortedProvisionalLoadsNewNavigation(navigation_handle); |
507 | 506 |
508 int chain_size_same_url = 0; | 507 int chain_size_same_url = 0; |
509 int chain_size = 0; | 508 int chain_size = 0; |
510 if (last_aborted) { | 509 if (last_aborted) { |
511 if (last_aborted->MatchesOriginalNavigation(navigation_handle)) { | 510 if (last_aborted->MatchesOriginalNavigation(navigation_handle)) { |
512 chain_size_same_url = last_aborted->aborted_chain_size_same_url() + 1; | 511 chain_size_same_url = last_aborted->aborted_chain_size_same_url() + 1; |
513 } else if (last_aborted->aborted_chain_size_same_url() > 0) { | 512 } else if (last_aborted->aborted_chain_size_same_url() > 0) { |
514 LogAbortChainSameURLHistogram( | 513 LogAbortChainSameURLHistogram( |
515 last_aborted->aborted_chain_size_same_url()); | 514 last_aborted->aborted_chain_size_same_url()); |
516 } | 515 } |
517 chain_size = last_aborted->aborted_chain_size() + 1; | 516 chain_size = last_aborted->aborted_chain_size() + 1; |
518 } | 517 } |
519 | 518 |
| 519 // Pass in the last committed url to the PageLoadTracker. If the MWCO has |
| 520 // never observed a committed load, use the last committed url from this |
| 521 // WebContent's opener. This is more accurate than using referrers due to |
| 522 // referrer sanitizing and origin referrers. Note that this could potentially |
| 523 // be inaccurate if the opener has since navigated. |
| 524 content::WebContents* opener = web_contents()->GetOpener(); |
| 525 const GURL& opener_url = |
| 526 !has_navigated_ && opener |
| 527 ? web_contents()->GetOpener()->GetLastCommittedURL() |
| 528 : GURL::EmptyGURL(); |
| 529 const GURL& currently_committed_url = |
| 530 committed_load_ ? committed_load_->committed_url() : opener_url; |
| 531 has_navigated_ = true; |
| 532 |
520 // We can have two provisional loads in some cases. E.g. a same-site | 533 // We can have two provisional loads in some cases. E.g. a same-site |
521 // navigation can have a concurrent cross-process navigation started | 534 // navigation can have a concurrent cross-process navigation started |
522 // from the omnibox. | 535 // from the omnibox. |
523 DCHECK_GT(2ul, provisional_loads_.size()); | 536 DCHECK_GT(2ul, provisional_loads_.size()); |
524 // Passing raw pointers to observers_ and embedder_interface_ is safe because | 537 // Passing raw pointers to observers_ and embedder_interface_ is safe because |
525 // the MetricsWebContentsObserver owns them both list and they are torn down | 538 // the MetricsWebContentsObserver owns them both list and they are torn down |
526 // after the PageLoadTracker. The PageLoadTracker does not hold on to | 539 // after the PageLoadTracker. The PageLoadTracker does not hold on to |
527 // committed_load_ or navigation_handle beyond the scope of the constructor. | 540 // committed_load_ or navigation_handle beyond the scope of the constructor. |
528 provisional_loads_.insert(std::make_pair( | 541 provisional_loads_.insert(std::make_pair( |
529 navigation_handle, | 542 navigation_handle, |
530 base::WrapUnique(new PageLoadTracker( | 543 base::WrapUnique(new PageLoadTracker( |
531 in_foreground_, embedder_interface_.get(), committed_load_.get(), | 544 in_foreground_, embedder_interface_.get(), currently_committed_url, |
532 navigation_handle, chain_size, chain_size_same_url)))); | 545 navigation_handle, chain_size, chain_size_same_url)))); |
533 } | 546 } |
534 | 547 |
535 void MetricsWebContentsObserver::DidFinishNavigation( | 548 void MetricsWebContentsObserver::DidFinishNavigation( |
536 content::NavigationHandle* navigation_handle) { | 549 content::NavigationHandle* navigation_handle) { |
537 if (!navigation_handle->IsInMainFrame()) | 550 if (!navigation_handle->IsInMainFrame()) |
538 return; | 551 return; |
539 | 552 |
540 std::unique_ptr<PageLoadTracker> finished_nav( | 553 std::unique_ptr<PageLoadTracker> finished_nav( |
541 std::move(provisional_loads_[navigation_handle])); | 554 std::move(provisional_loads_[navigation_handle])); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 | 739 |
727 if (!committed_load_->UpdateTiming(timing, metadata)) { | 740 if (!committed_load_->UpdateTiming(timing, metadata)) { |
728 // If the page load tracker cannot update its timing, something is wrong | 741 // 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). | 742 // 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. | 743 // We expect this to be a rare occurrence. |
731 RecordInternalError(ERR_BAD_TIMING_IPC); | 744 RecordInternalError(ERR_BAD_TIMING_IPC); |
732 } | 745 } |
733 } | 746 } |
734 | 747 |
735 } // namespace page_load_metrics | 748 } // namespace page_load_metrics |
OLD | NEW |