Commit f4ba53f5 authored by jam's avatar jam Committed by Commit bot

A different approach to fixing FirstWebContentsProfiler with PlzNavigate.

The previous fix depended on ensuring we add hooks to all the code paths that cause the first active WebContents to get added to the tab strip. We're still missing some code paths. So instead restore the old behavior. Even though it did miss navigation starts, fix that by using the time from NavigationHandle for PlzNavigate.

This should restore the metrics for non-PlzNavigate case.
For PlzNavigate, the start timings were already different regardless from non-PlzNavigate because of how navigations are structured very differently. This change shouldn't affects things too much for PlzNavigate though, because the only difference should be the IPC time from the renderer to the browser thread.

BUG=650349

Review-Url: https://codereview.chromium.org/2448553002
Cr-Commit-Position: refs/heads/master@{#427144}
parent 3d279e08
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/events/event_switches.h" #include "ui/events/event_switches.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/metrics/first_web_contents_profiler.h"
#endif // !defined(OS_ANDROID)
#if defined(OS_ANDROID) && defined(__arm__) #if defined(OS_ANDROID) && defined(__arm__)
#include <cpu-features.h> #include <cpu-features.h>
#endif // defined(OS_ANDROID) && defined(__arm__) #endif // defined(OS_ANDROID) && defined(__arm__)
...@@ -368,6 +372,7 @@ void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() { ...@@ -368,6 +372,7 @@ void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
is_screen_observer_ = true; is_screen_observer_ = true;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
FirstWebContentsProfiler::Start();
metrics::TabUsageRecorder::Initialize(); metrics::TabUsageRecorder::Initialize();
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
} }
......
...@@ -13,20 +13,27 @@ ...@@ -13,20 +13,27 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/metrics/profiler/tracking_synchronizer.h" #include "components/metrics/profiler/tracking_synchronizer.h"
#include "components/metrics/proto/profiler_event.pb.h" #include "components/metrics/proto/profiler_event.pb.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/common/browser_side_navigation_policy.h"
void FirstWebContentsProfiler::WebContentsStarted(
content::WebContents* web_contents) { // static
static bool first_web_contents_profiled = false; void FirstWebContentsProfiler::Start() {
if (first_web_contents_profiled) for (auto* browser : *BrowserList::GetInstance()) {
return; content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
first_web_contents_profiled = true; if (web_contents) {
// FirstWebContentsProfiler owns itself and is also bound to
// |web_contents|'s lifetime by observing WebContentsDestroyed().
new FirstWebContentsProfiler(web_contents); new FirstWebContentsProfiler(web_contents);
return;
}
}
} }
FirstWebContentsProfiler::FirstWebContentsProfiler( FirstWebContentsProfiler::FirstWebContentsProfiler(
...@@ -81,6 +88,13 @@ void FirstWebContentsProfiler::DidStartNavigation( ...@@ -81,6 +88,13 @@ void FirstWebContentsProfiler::DidStartNavigation(
return; return;
} }
if (content::IsBrowserSideNavigationEnabled()) {
// With PlzNavigate, DidStartNavigation is called synchronously on
// browser-initiated loads instead of through an IPC. This means that we
// will miss this signal. Instead we record it when the commit completes.
return;
}
// The first navigation has to be the main frame's. // The first navigation has to be the main frame's.
DCHECK(navigation_handle->IsInMainFrame()); DCHECK(navigation_handle->IsInMainFrame());
...@@ -120,6 +134,12 @@ void FirstWebContentsProfiler::DidFinishNavigation( ...@@ -120,6 +134,12 @@ void FirstWebContentsProfiler::DidFinishNavigation(
return; return;
} }
if (content::IsBrowserSideNavigationEnabled()) {
startup_metric_utils::RecordFirstWebContentsMainNavigationStart(
navigation_handle->NavigationStart());
collected_main_navigation_start_metric_ = true;
}
collected_main_navigation_finished_metric_ = true; collected_main_navigation_finished_metric_ = true;
startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( startup_metric_utils::RecordFirstWebContentsMainNavigationFinished(
base::TimeTicks::Now()); base::TimeTicks::Now());
......
...@@ -23,7 +23,7 @@ class FirstWebContentsProfiler : public content::WebContentsObserver { ...@@ -23,7 +23,7 @@ class FirstWebContentsProfiler : public content::WebContentsObserver {
// Creates a profiler for the active web contents. If there are multiple // Creates a profiler for the active web contents. If there are multiple
// browsers, the first one is chosen. The resulting FirstWebContentsProfiler // browsers, the first one is chosen. The resulting FirstWebContentsProfiler
// owns itself. // owns itself.
static void WebContentsStarted(content::WebContents* web_contents); static void Start();
private: private:
// Reasons for which profiling is deemed complete. Logged in UMA (do not re- // Reasons for which profiling is deemed complete. Logged in UMA (do not re-
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/keep_alive_types.h" #include "chrome/browser/lifetime/keep_alive_types.h"
#include "chrome/browser/lifetime/scoped_keep_alive.h" #include "chrome/browser/lifetime/scoped_keep_alive.h"
#include "chrome/browser/metrics/first_web_contents_profiler.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h" #include "chrome/browser/search/search.h"
#include "chrome/browser/sessions/session_restore_delegate.h" #include "chrome/browser/sessions/session_restore_delegate.h"
...@@ -549,7 +548,6 @@ class SessionRestoreImpl : public content::NotificationObserver { ...@@ -549,7 +548,6 @@ class SessionRestoreImpl : public content::NotificationObserver {
if (!is_selected_tab) if (!is_selected_tab)
continue; continue;
FirstWebContentsProfiler::WebContentsStarted(contents);
ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents( ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents(
contents)); contents));
// TODO(sky): remove. For debugging 368236. // TODO(sky): remove. For debugging 368236.
......
...@@ -55,10 +55,6 @@ ...@@ -55,10 +55,6 @@
#include "extensions/common/extension_set.h" #include "extensions/common/extension_set.h"
#endif #endif
#if !defined(OS_ANDROID)
#include "chrome/browser/metrics/first_web_contents_profiler.h"
#endif // !defined(OS_ANDROID)
using content::GlobalRequestID; using content::GlobalRequestID;
using content::NavigationController; using content::NavigationController;
using content::WebContents; using content::WebContents;
...@@ -385,9 +381,6 @@ content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, ...@@ -385,9 +381,6 @@ content::WebContents* CreateTargetContents(const chrome::NavigateParams& params,
SetExtensionAppById(params.extension_app_id); SetExtensionAppById(params.extension_app_id);
#endif #endif
#if !defined(OS_ANDROID)
FirstWebContentsProfiler::WebContentsStarted(target_contents);
#endif // !defined(OS_ANDROID)
return target_contents; return target_contents;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment