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

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

Issue 1924543002: [page_load_metrics] use data from WebContents::GetOpener (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@just_gws_aborts
Patch Set: Remove about:blank from all processing and use navigation start for opener policy Created 4 years, 8 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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)
Bryan McQuade 2016/04/26 19:43:31 seems like a good addition, thanks!
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. This is used for
Bryan McQuade 2016/04/26 19:43:31 let's leave out the 'this is used for FromGWS metr
Charlie Harrison 2016/04/26 20:37:29 Done.
520 // FromGWS metrics. If the MWCO has never observed a committed load, use the
521 // last committed url from this WebContent's opener. This is more accurate
522 // than using referrers due to referrer sanitizing and origin referrers. Note
523 // that this could potentially be inaccurate if the opener has since
524 // navigated.
525 content::WebContents* opener = web_contents()->GetOpener();
526 const GURL& opener_url =
527 !has_navigated_ && opener
528 ? web_contents()->GetOpener()->GetLastCommittedURL()
529 : GURL::EmptyGURL();
530 const GURL currently_committed_url =
Bryan McQuade 2016/04/26 19:43:31 oh, looks like this might still need to be updated
Charlie Harrison 2016/04/26 20:37:29 Done. Sorry.
531 committed_load_ ? committed_load_->committed_url() : opener_url;
532 has_navigated_ = true;
533
520 // We can have two provisional loads in some cases. E.g. a same-site 534 // We can have two provisional loads in some cases. E.g. a same-site
521 // navigation can have a concurrent cross-process navigation started 535 // navigation can have a concurrent cross-process navigation started
522 // from the omnibox. 536 // from the omnibox.
523 DCHECK_GT(2ul, provisional_loads_.size()); 537 DCHECK_GT(2ul, provisional_loads_.size());
524 // Passing raw pointers to observers_ and embedder_interface_ is safe because 538 // Passing raw pointers to observers_ and embedder_interface_ is safe because
525 // the MetricsWebContentsObserver owns them both list and they are torn down 539 // the MetricsWebContentsObserver owns them both list and they are torn down
526 // after the PageLoadTracker. The PageLoadTracker does not hold on to 540 // after the PageLoadTracker. The PageLoadTracker does not hold on to
527 // committed_load_ or navigation_handle beyond the scope of the constructor. 541 // committed_load_ or navigation_handle beyond the scope of the constructor.
528 provisional_loads_.insert(std::make_pair( 542 provisional_loads_.insert(std::make_pair(
529 navigation_handle, 543 navigation_handle,
530 base::WrapUnique(new PageLoadTracker( 544 base::WrapUnique(new PageLoadTracker(
531 in_foreground_, embedder_interface_.get(), committed_load_.get(), 545 in_foreground_, embedder_interface_.get(), currently_committed_url,
532 navigation_handle, chain_size, chain_size_same_url)))); 546 navigation_handle, chain_size, chain_size_same_url))));
533 } 547 }
534 548
535 void MetricsWebContentsObserver::DidFinishNavigation( 549 void MetricsWebContentsObserver::DidFinishNavigation(
536 content::NavigationHandle* navigation_handle) { 550 content::NavigationHandle* navigation_handle) {
537 if (!navigation_handle->IsInMainFrame()) 551 if (!navigation_handle->IsInMainFrame())
538 return; 552 return;
539 553
540 std::unique_ptr<PageLoadTracker> finished_nav( 554 std::unique_ptr<PageLoadTracker> finished_nav(
541 std::move(provisional_loads_[navigation_handle])); 555 std::move(provisional_loads_[navigation_handle]));
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 740
727 if (!committed_load_->UpdateTiming(timing, metadata)) { 741 if (!committed_load_->UpdateTiming(timing, metadata)) {
728 // If the page load tracker cannot update its timing, something is wrong 742 // 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). 743 // 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. 744 // We expect this to be a rare occurrence.
731 RecordInternalError(ERR_BAD_TIMING_IPC); 745 RecordInternalError(ERR_BAD_TIMING_IPC);
732 } 746 }
733 } 747 }
734 748
735 } // namespace page_load_metrics 749 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698