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

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

Issue 2624283004: Associate a main resource request with its PageLoadTracker. (Closed)
Patch Set: comment cleanup Created 3 years, 11 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>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/user_metrics.h" 15 #include "base/metrics/user_metrics.h"
16 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h" 16 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h"
17 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" 17 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
18 #include "chrome/common/page_load_metrics/page_load_timing.h" 18 #include "chrome/common/page_load_metrics/page_load_timing.h"
19 #include "content/public/browser/navigation_details.h" 19 #include "content/public/browser/navigation_details.h"
20 #include "content/public/browser/navigation_handle.h" 20 #include "content/public/browser/navigation_handle.h"
21 #include "content/public/common/browser_side_navigation_policy.h"
21 #include "ui/base/page_transition_types.h" 22 #include "ui/base/page_transition_types.h"
22 23
23 // This macro invokes the specified method on each observer, passing the 24 // This macro invokes the specified method on each observer, passing the
24 // variable length arguments as the method's arguments, and removes the observer 25 // variable length arguments as the method's arguments, and removes the observer
25 // from the list of observers if the given method returns STOP_OBSERVING. 26 // from the list of observers if the given method returns STOP_OBSERVING.
26 #define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \ 27 #define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \
27 for (auto it = observers.begin(); it != observers.end();) { \ 28 for (auto it = observers.begin(); it != observers.end();) { \
28 if ((*it)->Method(__VA_ARGS__) == \ 29 if ((*it)->Method(__VA_ARGS__) == \
29 PageLoadMetricsObserver::STOP_OBSERVING) { \ 30 PageLoadMetricsObserver::STOP_OBSERVING) { \
30 it = observers.erase(it); \ 31 it = observers.erase(it); \
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // backgrounded yet, or started in the foreground and have already been 419 // backgrounded yet, or started in the foreground and have already been
419 // backgrounded. 420 // backgrounded.
420 DCHECK_NE(started_in_foreground_, background_time_.is_null()); 421 DCHECK_NE(started_in_foreground_, background_time_.is_null());
421 foreground_time_ = base::TimeTicks::Now(); 422 foreground_time_ = base::TimeTicks::Now();
422 ClampBrowserTimestampIfInterProcessTimeTickSkew(&foreground_time_); 423 ClampBrowserTimestampIfInterProcessTimeTickSkew(&foreground_time_);
423 } 424 }
424 425
425 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnShown); 426 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnShown);
426 } 427 }
427 428
429 void PageLoadTracker::ReadyToCommit(
430 content::NavigationHandle* navigation_handle) {
431 // When browser side navigation is enabled,
Charlie Harrison 2017/01/13 15:56:23 nit: Just replace this line with "PlzNavigate:", w
Bryan McQuade 2017/01/17 15:06:26 done
432 // NavigationHandle::GetGlobalRequestID() sometimes returns an uninitialized
433 // GlobalRequestID. Bail early in this case. See crbug.com/680841 for details.
434 if (content::IsBrowserSideNavigationEnabled() &&
435 navigation_handle->GetGlobalRequestID() == content::GlobalRequestID())
436 return;
437
438 DCHECK(!navigation_request_id_.has_value());
439 navigation_request_id_ = navigation_handle->GetGlobalRequestID();
440 DCHECK(navigation_request_id_.value() != content::GlobalRequestID());
Charlie Harrison 2017/01/13 15:56:23 nit: DCHECK_NE
Bryan McQuade 2017/01/17 15:06:26 i tried this but it doesn't compile, as DCHECK_NE
441 }
442
428 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { 443 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) {
429 committed_url_ = navigation_handle->GetURL(); 444 committed_url_ = navigation_handle->GetURL();
430 // Some transitions (like CLIENT_REDIRECT) are only known at commit time. 445 // Some transitions (like CLIENT_REDIRECT) are only known at commit time.
431 page_transition_ = navigation_handle->GetPageTransition(); 446 page_transition_ = navigation_handle->GetPageTransition();
432 user_initiated_info_.user_gesture = navigation_handle->HasUserGesture(); 447 user_initiated_info_.user_gesture = navigation_handle->HasUserGesture();
433 448
434 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle); 449 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle);
435 LogAbortChainHistograms(navigation_handle); 450 LogAbortChainHistograms(navigation_handle);
436 } 451 }
437 452
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 DCHECK(abort_type_ != ABORT_NONE || 604 DCHECK(abort_type_ != ABORT_NONE ||
590 (!abort_user_initiated_info_.browser_initiated && 605 (!abort_user_initiated_info_.browser_initiated &&
591 !abort_user_initiated_info_.user_gesture && 606 !abort_user_initiated_info_.user_gesture &&
592 !abort_user_initiated_info_.user_input_event)); 607 !abort_user_initiated_info_.user_input_event));
593 return PageLoadExtraInfo( 608 return PageLoadExtraInfo(
594 first_background_time, first_foreground_time, started_in_foreground_, 609 first_background_time, first_foreground_time, started_in_foreground_,
595 user_initiated_info_, committed_url_, start_url_, abort_type_, 610 user_initiated_info_, committed_url_, start_url_, abort_type_,
596 abort_user_initiated_info_, time_to_abort, metadata_); 611 abort_user_initiated_info_, time_to_abort, metadata_);
597 } 612 }
598 613
614 bool PageLoadTracker::HasMatchingNavigationRequestID(
615 const content::GlobalRequestID& request_id) const {
616 DCHECK(request_id != content::GlobalRequestID());
Charlie Harrison 2017/01/13 15:56:23 ditto
Bryan McQuade 2017/01/17 15:06:26 same
617 return navigation_request_id_.has_value() &&
618 navigation_request_id_.value() == request_id;
619 }
620
599 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, 621 void PageLoadTracker::NotifyAbort(UserAbortType abort_type,
600 UserInitiatedInfo user_initiated_info, 622 UserInitiatedInfo user_initiated_info,
601 base::TimeTicks timestamp, 623 base::TimeTicks timestamp,
602 bool is_certainly_browser_timestamp) { 624 bool is_certainly_browser_timestamp) {
603 DCHECK_NE(abort_type, ABORT_NONE); 625 DCHECK_NE(abort_type, ABORT_NONE);
604 // Use UpdateAbort to update an already notified PageLoadTracker. 626 // Use UpdateAbort to update an already notified PageLoadTracker.
605 if (abort_type_ != ABORT_NONE) 627 if (abort_type_ != ABORT_NONE)
606 return; 628 return;
607 629
608 UpdateAbortInternal(abort_type, user_initiated_info, timestamp, 630 UpdateAbortInternal(abort_type, user_initiated_info, timestamp,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 // user initiated. 693 // user initiated.
672 if (abort_type != ABORT_CLIENT_REDIRECT) 694 if (abort_type != ABORT_CLIENT_REDIRECT)
673 abort_user_initiated_info_ = user_initiated_info; 695 abort_user_initiated_info_ = user_initiated_info;
674 696
675 if (is_certainly_browser_timestamp) { 697 if (is_certainly_browser_timestamp) {
676 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); 698 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_);
677 } 699 }
678 } 700 }
679 701
680 } // namespace page_load_metrics 702 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698