Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser/web_contents.h" | |
| 21 #include "content/public/common/browser_side_navigation_policy.h" | 22 #include "content/public/common/browser_side_navigation_policy.h" |
| 22 #include "ui/base/page_transition_types.h" | 23 #include "ui/base/page_transition_types.h" |
| 23 | 24 |
| 24 // This macro invokes the specified method on each observer, passing the | 25 // This macro invokes the specified method on each observer, passing the |
| 25 // variable length arguments as the method's arguments, and removes the observer | 26 // variable length arguments as the method's arguments, and removes the observer |
| 26 // from the list of observers if the given method returns STOP_OBSERVING. | 27 // from the list of observers if the given method returns STOP_OBSERVING. |
| 27 #define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \ | 28 #define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \ |
| 28 for (auto it = observers.begin(); it != observers.end();) { \ | 29 for (auto it = observers.begin(); it != observers.end();) { \ |
| 29 if ((*it)->Method(__VA_ARGS__) == \ | 30 if ((*it)->Method(__VA_ARGS__) == \ |
| 30 PageLoadMetricsObserver::STOP_OBSERVING) { \ | 31 PageLoadMetricsObserver::STOP_OBSERVING) { \ |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 navigation_request_id_ = navigation_handle->GetGlobalRequestID(); | 440 navigation_request_id_ = navigation_handle->GetGlobalRequestID(); |
| 440 DCHECK(navigation_request_id_.value() != content::GlobalRequestID()); | 441 DCHECK(navigation_request_id_.value() != content::GlobalRequestID()); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { | 444 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { |
| 444 committed_url_ = navigation_handle->GetURL(); | 445 committed_url_ = navigation_handle->GetURL(); |
| 445 // Some transitions (like CLIENT_REDIRECT) are only known at commit time. | 446 // Some transitions (like CLIENT_REDIRECT) are only known at commit time. |
| 446 page_transition_ = navigation_handle->GetPageTransition(); | 447 page_transition_ = navigation_handle->GetPageTransition(); |
| 447 user_initiated_info_.user_gesture = navigation_handle->HasUserGesture(); | 448 user_initiated_info_.user_gesture = navigation_handle->HasUserGesture(); |
| 448 | 449 |
| 450 INVOKE_AND_PRUNE_OBSERVERS( | |
|
Bryan McQuade
2017/02/21 18:50:15
ah, nice, this actually works very well. i like th
| |
| 451 observers_, ShouldObserveMimeType, | |
| 452 navigation_handle->GetWebContents()->GetContentsMimeType()); | |
| 453 | |
| 449 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle); | 454 INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle); |
| 450 LogAbortChainHistograms(navigation_handle); | 455 LogAbortChainHistograms(navigation_handle); |
| 451 } | 456 } |
| 452 | 457 |
| 453 void PageLoadTracker::FailedProvisionalLoad( | 458 void PageLoadTracker::FailedProvisionalLoad( |
| 454 content::NavigationHandle* navigation_handle) { | 459 content::NavigationHandle* navigation_handle) { |
| 455 DCHECK(!failed_provisional_load_info_); | 460 DCHECK(!failed_provisional_load_info_); |
| 456 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( | 461 failed_provisional_load_info_.reset(new FailedProvisionalLoadInfo( |
| 457 base::TimeTicks::Now() - navigation_handle->NavigationStart(), | 462 base::TimeTicks::Now() - navigation_handle->NavigationStart(), |
| 458 navigation_handle->GetNetErrorCode())); | 463 navigation_handle->GetNetErrorCode())); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 // user initiated. | 698 // user initiated. |
| 694 if (abort_type != ABORT_CLIENT_REDIRECT) | 699 if (abort_type != ABORT_CLIENT_REDIRECT) |
| 695 abort_user_initiated_info_ = user_initiated_info; | 700 abort_user_initiated_info_ = user_initiated_info; |
| 696 | 701 |
| 697 if (is_certainly_browser_timestamp) { | 702 if (is_certainly_browser_timestamp) { |
| 698 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); | 703 ClampBrowserTimestampIfInterProcessTimeTickSkew(&abort_time_); |
| 699 } | 704 } |
| 700 } | 705 } |
| 701 | 706 |
| 702 } // namespace page_load_metrics | 707 } // namespace page_load_metrics |
| OLD | NEW |