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

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

Issue 1916913008: This patch uses the WebContents' opener to extract the previous committed url for the very first na… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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 "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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, 200 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL,
201 aborted_chain_size_same_url); 201 aborted_chain_size_same_url);
202 } 202 }
203 } 203 }
204 204
205 } // namespace 205 } // namespace
206 206
207 PageLoadTracker::PageLoadTracker( 207 PageLoadTracker::PageLoadTracker(
208 bool in_foreground, 208 bool in_foreground,
209 PageLoadMetricsEmbedderInterface* embedder_interface, 209 PageLoadMetricsEmbedderInterface* embedder_interface,
210 PageLoadTracker* const currently_committed_load_or_null, 210 const GURL& currently_committed_url,
211 content::NavigationHandle* navigation_handle, 211 content::NavigationHandle* navigation_handle,
212 int aborted_chain_size, 212 int aborted_chain_size,
213 int aborted_chain_size_same_url) 213 int aborted_chain_size_same_url)
214 : renderer_tracked_(false), 214 : renderer_tracked_(false),
215 navigation_start_(navigation_handle->NavigationStart()), 215 navigation_start_(navigation_handle->NavigationStart()),
216 url_(navigation_handle->GetURL()), 216 url_(navigation_handle->GetURL()),
217 abort_type_(ABORT_NONE), 217 abort_type_(ABORT_NONE),
218 started_in_foreground_(in_foreground), 218 started_in_foreground_(in_foreground),
219 aborted_chain_size_(aborted_chain_size), 219 aborted_chain_size_(aborted_chain_size),
220 aborted_chain_size_same_url_(aborted_chain_size_same_url), 220 aborted_chain_size_same_url_(aborted_chain_size_same_url),
221 embedder_interface_(embedder_interface) { 221 embedder_interface_(embedder_interface) {
222 DCHECK(!navigation_handle->HasCommitted()); 222 DCHECK(!navigation_handle->HasCommitted());
223 embedder_interface_->RegisterObservers(this); 223 embedder_interface_->RegisterObservers(this);
224 const GURL& currently_committed_url =
225 currently_committed_load_or_null
226 ? currently_committed_load_or_null->committed_url()
227 : GURL::EmptyGURL();
228 for (const auto& observer : observers_) { 224 for (const auto& observer : observers_) {
229 observer->OnStart(navigation_handle, currently_committed_url); 225 observer->OnStart(navigation_handle, currently_committed_url);
230 } 226 }
231 } 227 }
232 228
233 PageLoadTracker::~PageLoadTracker() { 229 PageLoadTracker::~PageLoadTracker() {
234 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); 230 const PageLoadExtraInfo info = GetPageLoadMetricsInfo();
235 if (!info.time_to_commit.is_zero() && renderer_tracked() && 231 if (!info.time_to_commit.is_zero() && renderer_tracked() &&
236 timing_.IsEmpty()) { 232 timing_.IsEmpty()) {
237 RecordInternalError(ERR_NO_IPCS_RECEIVED); 233 RecordInternalError(ERR_NO_IPCS_RECEIVED);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 abort_type_ = abort_type; 450 abort_type_ = abort_type;
455 abort_time_ = timestamp; 451 abort_time_ = timestamp;
456 } 452 }
457 453
458 // static 454 // static
459 MetricsWebContentsObserver::MetricsWebContentsObserver( 455 MetricsWebContentsObserver::MetricsWebContentsObserver(
460 content::WebContents* web_contents, 456 content::WebContents* web_contents,
461 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) 457 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface)
462 : content::WebContentsObserver(web_contents), 458 : content::WebContentsObserver(web_contents),
463 in_foreground_(false), 459 in_foreground_(false),
464 embedder_interface_(std::move(embedder_interface)) {} 460 embedder_interface_(std::move(embedder_interface)),
461 has_navigated_(false) {}
465 462
466 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( 463 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents(
467 content::WebContents* web_contents, 464 content::WebContents* web_contents,
468 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { 465 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) {
469 DCHECK(web_contents); 466 DCHECK(web_contents);
470 467
471 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); 468 MetricsWebContentsObserver* metrics = FromWebContents(web_contents);
472 if (!metrics) { 469 if (!metrics) {
473 metrics = new MetricsWebContentsObserver(web_contents, 470 metrics = new MetricsWebContentsObserver(web_contents,
474 std::move(embedder_interface)); 471 std::move(embedder_interface));
(...skipping 18 matching lines...) Expand all
493 IPC_END_MESSAGE_MAP() 490 IPC_END_MESSAGE_MAP()
494 return handled; 491 return handled;
495 } 492 }
496 493
497 void MetricsWebContentsObserver::DidStartNavigation( 494 void MetricsWebContentsObserver::DidStartNavigation(
498 content::NavigationHandle* navigation_handle) { 495 content::NavigationHandle* navigation_handle) {
499 if (!navigation_handle->IsInMainFrame()) 496 if (!navigation_handle->IsInMainFrame())
500 return; 497 return;
501 if (embedder_interface_->IsPrerendering(web_contents())) 498 if (embedder_interface_->IsPrerendering(web_contents()))
502 return; 499 return;
500 if (navigation_handle->GetURL().spec().compare(url::kAboutBlankURL) == 0)
501 return;
503 502
504 scoped_ptr<PageLoadTracker> last_aborted = 503 scoped_ptr<PageLoadTracker> last_aborted =
505 NotifyAbortedProvisionalLoadsNewNavigation(navigation_handle); 504 NotifyAbortedProvisionalLoadsNewNavigation(navigation_handle);
506 505
507 int chain_size_same_url = 0; 506 int chain_size_same_url = 0;
508 int chain_size = 0; 507 int chain_size = 0;
509 if (last_aborted) { 508 if (last_aborted) {
510 if (last_aborted->MatchesOriginalNavigation(navigation_handle)) { 509 if (last_aborted->MatchesOriginalNavigation(navigation_handle)) {
511 chain_size_same_url = last_aborted->aborted_chain_size_same_url() + 1; 510 chain_size_same_url = last_aborted->aborted_chain_size_same_url() + 1;
512 } else if (last_aborted->aborted_chain_size_same_url() > 0) { 511 } else if (last_aborted->aborted_chain_size_same_url() > 0) {
513 LogAbortChainSameURLHistogram( 512 LogAbortChainSameURLHistogram(
514 last_aborted->aborted_chain_size_same_url()); 513 last_aborted->aborted_chain_size_same_url());
515 } 514 }
516 chain_size = last_aborted->aborted_chain_size() + 1; 515 chain_size = last_aborted->aborted_chain_size() + 1;
517 } 516 }
518 517
518 // Pass in the last committed url to the PageLoadTracker. If the MWCO has
519 // never observed a committed load, use the last committed url from this
520 // WebContent's opener. This is more accurate than using referrers due to
521 // referrer sanitizing and origin referrers. Note that this could potentially
522 // be inaccurate if the opener has since navigated.
523 content::WebContents* opener = web_contents()->GetOpener();
524 const GURL& opener_url =
525 !has_navigated_ && opener
526 ? web_contents()->GetOpener()->GetLastCommittedURL()
527 : GURL::EmptyGURL();
528 const GURL& currently_committed_url =
529 committed_load_ ? committed_load_->committed_url() : opener_url;
530 has_navigated_ = true;
531
519 // We can have two provisional loads in some cases. E.g. a same-site 532 // We can have two provisional loads in some cases. E.g. a same-site
520 // navigation can have a concurrent cross-process navigation started 533 // navigation can have a concurrent cross-process navigation started
521 // from the omnibox. 534 // from the omnibox.
522 DCHECK_GT(2ul, provisional_loads_.size()); 535 DCHECK_GT(2ul, provisional_loads_.size());
523 // Passing raw pointers to observers_ and embedder_interface_ is safe because 536 // Passing raw pointers to observers_ and embedder_interface_ is safe because
524 // the MetricsWebContentsObserver owns them both list and they are torn down 537 // the MetricsWebContentsObserver owns them both list and they are torn down
525 // after the PageLoadTracker. The PageLoadTracker does not hold on to 538 // after the PageLoadTracker. The PageLoadTracker does not hold on to
526 // committed_load_ or navigation_handle beyond the scope of the constructor. 539 // committed_load_ or navigation_handle beyond the scope of the constructor.
527 provisional_loads_.insert(std::make_pair( 540 provisional_loads_.insert(std::make_pair(
528 navigation_handle, 541 navigation_handle,
529 make_scoped_ptr(new PageLoadTracker( 542 make_scoped_ptr(new PageLoadTracker(
530 in_foreground_, embedder_interface_.get(), committed_load_.get(), 543 in_foreground_, embedder_interface_.get(), currently_committed_url,
531 navigation_handle, chain_size, chain_size_same_url)))); 544 navigation_handle, chain_size, chain_size_same_url))));
532 } 545 }
533 546
534 void MetricsWebContentsObserver::DidFinishNavigation( 547 void MetricsWebContentsObserver::DidFinishNavigation(
535 content::NavigationHandle* navigation_handle) { 548 content::NavigationHandle* navigation_handle) {
536 if (!navigation_handle->IsInMainFrame()) 549 if (!navigation_handle->IsInMainFrame())
537 return; 550 return;
538 551
539 scoped_ptr<PageLoadTracker> finished_nav( 552 scoped_ptr<PageLoadTracker> finished_nav(
540 std::move(provisional_loads_[navigation_handle])); 553 std::move(provisional_loads_[navigation_handle]));
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 738
726 if (!committed_load_->UpdateTiming(timing, metadata)) { 739 if (!committed_load_->UpdateTiming(timing, metadata)) {
727 // 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
728 // 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).
729 // We expect this to be a rare occurrence. 742 // We expect this to be a rare occurrence.
730 RecordInternalError(ERR_BAD_TIMING_IPC); 743 RecordInternalError(ERR_BAD_TIMING_IPC);
731 } 744 }
732 } 745 }
733 746
734 } // namespace page_load_metrics 747 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698