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

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

Issue 2692373003: Refactor PageLoadExtraInfo::committed_url to url and did_commit fields. (Closed)
Patch Set: address comments Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/page_load_tracker.h" 5 #include "chrome/browser/page_load_metrics/page_load_tracker.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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 bool in_foreground, 287 bool in_foreground,
288 PageLoadMetricsEmbedderInterface* embedder_interface, 288 PageLoadMetricsEmbedderInterface* embedder_interface,
289 const GURL& currently_committed_url, 289 const GURL& currently_committed_url,
290 content::NavigationHandle* navigation_handle, 290 content::NavigationHandle* navigation_handle,
291 UserInitiatedInfo user_initiated_info, 291 UserInitiatedInfo user_initiated_info,
292 int aborted_chain_size, 292 int aborted_chain_size,
293 int aborted_chain_size_same_url) 293 int aborted_chain_size_same_url)
294 : did_stop_tracking_(false), 294 : did_stop_tracking_(false),
295 app_entered_background_(false), 295 app_entered_background_(false),
296 navigation_start_(navigation_handle->NavigationStart()), 296 navigation_start_(navigation_handle->NavigationStart()),
297 url_(navigation_handle->GetURL()),
297 start_url_(navigation_handle->GetURL()), 298 start_url_(navigation_handle->GetURL()),
299 did_commit_(false),
298 abort_type_(ABORT_NONE), 300 abort_type_(ABORT_NONE),
299 abort_user_initiated_info_(UserInitiatedInfo::NotUserInitiated()), 301 abort_user_initiated_info_(UserInitiatedInfo::NotUserInitiated()),
300 started_in_foreground_(in_foreground), 302 started_in_foreground_(in_foreground),
301 page_transition_(navigation_handle->GetPageTransition()), 303 page_transition_(navigation_handle->GetPageTransition()),
302 user_initiated_info_(user_initiated_info), 304 user_initiated_info_(user_initiated_info),
303 aborted_chain_size_(aborted_chain_size), 305 aborted_chain_size_(aborted_chain_size),
304 aborted_chain_size_same_url_(aborted_chain_size_same_url), 306 aborted_chain_size_same_url_(aborted_chain_size_same_url),
305 embedder_interface_(embedder_interface) { 307 embedder_interface_(embedder_interface) {
306 DCHECK(!navigation_handle->HasCommitted()); 308 DCHECK(!navigation_handle->HasCommitted());
307 embedder_interface_->RegisterObservers(this); 309 embedder_interface_->RegisterObservers(this);
308 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnStart, navigation_handle, 310 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnStart, navigation_handle,
309 currently_committed_url, started_in_foreground_); 311 currently_committed_url, started_in_foreground_);
310 } 312 }
311 313
312 PageLoadTracker::~PageLoadTracker() { 314 PageLoadTracker::~PageLoadTracker() {
313 if (app_entered_background_) { 315 if (app_entered_background_) {
314 RecordAppBackgroundPageLoadCompleted(true); 316 RecordAppBackgroundPageLoadCompleted(true);
315 } 317 }
316 318
317 if (did_stop_tracking_) 319 if (did_stop_tracking_)
318 return; 320 return;
319 321
320 if (committed_url_.is_empty()) { 322 if (!did_commit_) {
321 if (!failed_provisional_load_info_) 323 if (!failed_provisional_load_info_)
322 RecordInternalError(ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD); 324 RecordInternalError(ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD);
323 325
324 // Don't include any aborts that resulted in a new navigation, as the chain 326 // Don't include any aborts that resulted in a new navigation, as the chain
325 // length will be included in the aborter PageLoadTracker. 327 // length will be included in the aborter PageLoadTracker.
326 if (abort_type_ != ABORT_RELOAD && abort_type_ != ABORT_FORWARD_BACK && 328 if (abort_type_ != ABORT_RELOAD && abort_type_ != ABORT_FORWARD_BACK &&
327 abort_type_ != ABORT_NEW_NAVIGATION) { 329 abort_type_ != ABORT_NEW_NAVIGATION) {
328 LogAbortChainHistograms(nullptr); 330 LogAbortChainHistograms(nullptr);
329 } 331 }
330 } else if (timing_.IsEmpty()) { 332 } else if (timing_.IsEmpty()) {
331 RecordInternalError(ERR_NO_IPCS_RECEIVED); 333 RecordInternalError(ERR_NO_IPCS_RECEIVED);
332 } 334 }
333 335
334 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); 336 const PageLoadExtraInfo info = ComputePageLoadExtraInfo();
335 for (const auto& observer : observers_) { 337 for (const auto& observer : observers_) {
336 if (failed_provisional_load_info_) { 338 if (failed_provisional_load_info_) {
337 observer->OnFailedProvisionalLoad(*failed_provisional_load_info_, info); 339 observer->OnFailedProvisionalLoad(*failed_provisional_load_info_, info);
338 } else if (!info.committed_url.is_empty()) { 340 } else if (did_commit_) {
339 observer->OnComplete(timing_, info); 341 observer->OnComplete(timing_, info);
340 } 342 }
341 } 343 }
342 } 344 }
343 345
344 void PageLoadTracker::LogAbortChainHistograms( 346 void PageLoadTracker::LogAbortChainHistograms(
345 content::NavigationHandle* final_navigation) { 347 content::NavigationHandle* final_navigation) {
346 if (aborted_chain_size_ == 0) 348 if (aborted_chain_size_ == 0)
347 return; 349 return;
348 // Note that this could be broken out by this navigation's abort type, if more 350 // Note that this could be broken out by this navigation's abort type, if more
349 // granularity is needed. Add one to the chain size to count the current 351 // granularity is needed. Add one to the chain size to count the current
350 // navigation. In the other cases, the current navigation is the final 352 // navigation. In the other cases, the current navigation is the final
351 // navigation (which commits). 353 // navigation (which commits).
352 if (!final_navigation) { 354 if (!final_navigation) {
353 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeNoCommit, 355 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeNoCommit,
354 aborted_chain_size_ + 1); 356 aborted_chain_size_ + 1);
355 LogAbortChainSameURLHistogram(aborted_chain_size_same_url_ + 1); 357 LogAbortChainSameURLHistogram(aborted_chain_size_same_url_ + 1);
356 return; 358 return;
357 } 359 }
358 360
359 // The following is only executed for committing trackers. 361 // The following is only executed for committing trackers.
360 DCHECK(!committed_url_.is_empty()); 362 DCHECK(did_commit_);
361 363
362 // Note that histograms could be separated out by this commit's transition 364 // Note that histograms could be separated out by this commit's transition
363 // type, but for simplicity they will all be bucketed together. 365 // type, but for simplicity they will all be bucketed together.
364 LogAbortChainSameURLHistogram(aborted_chain_size_same_url_); 366 LogAbortChainSameURLHistogram(aborted_chain_size_same_url_);
365 367
366 ui::PageTransition committed_transition = 368 ui::PageTransition committed_transition =
367 final_navigation->GetPageTransition(); 369 final_navigation->GetPageTransition();
368 switch (AbortTypeForPageTransition(committed_transition)) { 370 switch (AbortTypeForPageTransition(committed_transition)) {
369 case ABORT_RELOAD: 371 case ABORT_RELOAD:
370 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeReload, 372 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeReload,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (content::IsBrowserSideNavigationEnabled() && 436 if (content::IsBrowserSideNavigationEnabled() &&
435 navigation_handle->GetGlobalRequestID() == content::GlobalRequestID()) 437 navigation_handle->GetGlobalRequestID() == content::GlobalRequestID())
436 return; 438 return;
437 439
438 DCHECK(!navigation_request_id_.has_value()); 440 DCHECK(!navigation_request_id_.has_value());
439 navigation_request_id_ = navigation_handle->GetGlobalRequestID(); 441 navigation_request_id_ = navigation_handle->GetGlobalRequestID();
440 DCHECK(navigation_request_id_.value() != content::GlobalRequestID()); 442 DCHECK(navigation_request_id_.value() != content::GlobalRequestID());
441 } 443 }
442 444
443 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { 445 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) {
444 committed_url_ = navigation_handle->GetURL(); 446 did_commit_ = true;
447 url_ = navigation_handle->GetURL();
445 // Some transitions (like CLIENT_REDIRECT) are only known at commit time. 448 // Some transitions (like CLIENT_REDIRECT) are only known at commit time.
446 page_transition_ = navigation_handle->GetPageTransition(); 449 page_transition_ = navigation_handle->GetPageTransition();
447 user_initiated_info_.user_gesture = navigation_handle->HasUserGesture(); 450 user_initiated_info_.user_gesture = navigation_handle->HasUserGesture();
448 451
449 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle); 452 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle);
450 LogAbortChainHistograms(navigation_handle); 453 LogAbortChainHistograms(navigation_handle);
451 } 454 }
452 455
453 void PageLoadTracker::FailedProvisionalLoad( 456 void PageLoadTracker::FailedProvisionalLoad(
454 content::NavigationHandle* navigation_handle) { 457 content::NavigationHandle* navigation_handle) {
455 DCHECK(!failed_provisional_load_info_); 458 DCHECK(!failed_provisional_load_info_);
456 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( 459 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo(
457 base::TimeTicks::Now() - navigation_handle->NavigationStart(), 460 base::TimeTicks::Now() - navigation_handle->NavigationStart(),
458 navigation_handle->GetNetErrorCode())); 461 navigation_handle->GetNetErrorCode()));
459 } 462 }
460 463
461 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { 464 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) {
465 url_ = navigation_handle->GetURL();
462 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnRedirect, navigation_handle); 466 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnRedirect, navigation_handle);
463 } 467 }
464 468
465 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) { 469 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) {
466 input_tracker_.OnInputEvent(event); 470 input_tracker_.OnInputEvent(event);
467 for (const auto& observer : observers_) { 471 for (const auto& observer : observers_) {
468 observer->OnUserInput(event); 472 observer->OnUserInput(event);
469 } 473 }
470 } 474 }
471 475
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // different start time from an earlier struct is considered invalid. 508 // different start time from an earlier struct is considered invalid.
505 bool valid_timing_descendent = 509 bool valid_timing_descendent =
506 timing_.navigation_start.is_null() || 510 timing_.navigation_start.is_null() ||
507 timing_.navigation_start == new_timing.navigation_start; 511 timing_.navigation_start == new_timing.navigation_start;
508 // Ensure flags sent previously are still present in the new metadata fields. 512 // Ensure flags sent previously are still present in the new metadata fields.
509 bool valid_behavior_descendent = 513 bool valid_behavior_descendent =
510 (metadata_.behavior_flags & new_metadata.behavior_flags) == 514 (metadata_.behavior_flags & new_metadata.behavior_flags) ==
511 metadata_.behavior_flags; 515 metadata_.behavior_flags;
512 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && 516 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent &&
513 valid_behavior_descendent) { 517 valid_behavior_descendent) {
514 DCHECK(!committed_url_.is_empty()); // OnCommit() must be called first. 518 DCHECK(did_commit_); // OnCommit() must be called first.
515 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo() 519 // There are some subtle ordering constraints here. GetPageLoadMetricsInfo()
516 // must be called before DispatchObserverTimingCallbacks, but its 520 // must be called before DispatchObserverTimingCallbacks, but its
517 // implementation depends on the state of metadata_, so we need to update 521 // implementation depends on the state of metadata_, so we need to update
518 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of 522 // metadata_ before calling GetPageLoadMetricsInfo. Thus, we make a copy of
519 // timing here, update timing_ and metadata_, and then proceed to dispatch 523 // timing here, update timing_ and metadata_, and then proceed to dispatch
520 // the observer timing callbacks. 524 // the observer timing callbacks.
521 const PageLoadTiming last_timing = timing_; 525 const PageLoadTiming last_timing = timing_;
522 timing_ = new_timing; 526 timing_ = new_timing;
523 527
524 const PageLoadMetadata last_metadata = metadata_; 528 const PageLoadMetadata last_metadata = metadata_;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 604 }
601 605
602 // abort_type_ == ABORT_NONE implies abort_user_initiated_info_ is not user 606 // abort_type_ == ABORT_NONE implies abort_user_initiated_info_ is not user
603 // initiated. 607 // initiated.
604 DCHECK(abort_type_ != ABORT_NONE || 608 DCHECK(abort_type_ != ABORT_NONE ||
605 (!abort_user_initiated_info_.browser_initiated && 609 (!abort_user_initiated_info_.browser_initiated &&
606 !abort_user_initiated_info_.user_gesture && 610 !abort_user_initiated_info_.user_gesture &&
607 !abort_user_initiated_info_.user_input_event)); 611 !abort_user_initiated_info_.user_input_event));
608 return PageLoadExtraInfo( 612 return PageLoadExtraInfo(
609 first_background_time, first_foreground_time, started_in_foreground_, 613 first_background_time, first_foreground_time, started_in_foreground_,
610 user_initiated_info_, committed_url_, start_url_, abort_type_, 614 user_initiated_info_, url(), start_url_, did_commit_, abort_type_,
611 abort_user_initiated_info_, time_to_abort, metadata_); 615 abort_user_initiated_info_, time_to_abort, metadata_);
612 } 616 }
613 617
614 bool PageLoadTracker::HasMatchingNavigationRequestID( 618 bool PageLoadTracker::HasMatchingNavigationRequestID(
615 const content::GlobalRequestID& request_id) const { 619 const content::GlobalRequestID& request_id) const {
616 DCHECK(request_id != content::GlobalRequestID()); 620 DCHECK(request_id != content::GlobalRequestID());
617 return navigation_request_id_.has_value() && 621 return navigation_request_id_.has_value() &&
618 navigation_request_id_.value() == request_id; 622 navigation_request_id_.value() == request_id;
619 } 623 }
620 624
(...skipping 30 matching lines...) Expand all
651 base::TimeTicks abort_cause_time) const { 655 base::TimeTicks abort_cause_time) const {
652 // Note that |abort_cause_time - abort_time| can be negative. 656 // Note that |abort_cause_time - abort_time| can be negative.
653 return abort_type_ == ABORT_OTHER && 657 return abort_type_ == ABORT_OTHER &&
654 (abort_cause_time - abort_time_).InMilliseconds() < 100; 658 (abort_cause_time - abort_time_).InMilliseconds() < 100;
655 } 659 }
656 660
657 bool PageLoadTracker::MatchesOriginalNavigation( 661 bool PageLoadTracker::MatchesOriginalNavigation(
658 content::NavigationHandle* navigation_handle) { 662 content::NavigationHandle* navigation_handle) {
659 // Neither navigation should have committed. 663 // Neither navigation should have committed.
660 DCHECK(!navigation_handle->HasCommitted()); 664 DCHECK(!navigation_handle->HasCommitted());
661 DCHECK(committed_url_.is_empty()); 665 DCHECK(!did_commit_);
662 return navigation_handle->GetURL() == start_url_; 666 return navigation_handle->GetURL() == start_url_;
663 } 667 }
664 668
665 void PageLoadTracker::UpdateAbortInternal(UserAbortType abort_type, 669 void PageLoadTracker::UpdateAbortInternal(UserAbortType abort_type,
666 UserInitiatedInfo user_initiated_info, 670 UserInitiatedInfo user_initiated_info,
667 base::TimeTicks timestamp, 671 base::TimeTicks timestamp,
668 bool is_certainly_browser_timestamp) { 672 bool is_certainly_browser_timestamp) {
669 // When a provisional navigation commits, that navigation's start time is 673 // When a provisional navigation commits, that navigation's start time is
670 // interpreted as the abort time for other provisional loads in the tab. 674 // interpreted as the abort time for other provisional loads in the tab.
671 // However, this only makes sense if the committed load started after the 675 // However, this only makes sense if the committed load started after the
(...skipping 21 matching lines...) Expand all
693 // user initiated. 697 // user initiated.
694 if (abort_type != ABORT_CLIENT_REDIRECT) 698 if (abort_type != ABORT_CLIENT_REDIRECT)
695 abort_user_initiated_info_ = user_initiated_info; 699 abort_user_initiated_info_ = user_initiated_info;
696 700
697 if (is_certainly_browser_timestamp) { 701 if (is_certainly_browser_timestamp) {
698 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); 702 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_);
699 } 703 }
700 } 704 }
701 705
702 } // namespace page_load_metrics 706 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « chrome/browser/page_load_metrics/page_load_tracker.h ('k') | chrome/browser/prerender/prerender_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698