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

Fix FirstWebContentsProfiler not getting created when using session restore.

This regressed in r420175 because a different code path is taken that doesn't go through browser_navigator.cc's CreateTargetContents.

BUG=650349

Review-Url: https://codereview.chromium.org/2388803003
Cr-Commit-Position: refs/heads/master@{#422883}
parent ae40e483
......@@ -19,6 +19,16 @@
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "content/public/browser/navigation_handle.h"
void FirstWebContentsProfiler::WebContentsStarted(
content::WebContents* web_contents) {
static bool first_web_contents_profiled = false;
if (first_web_contents_profiled)
return;
first_web_contents_profiled = true;
new FirstWebContentsProfiler(web_contents);
}
FirstWebContentsProfiler::FirstWebContentsProfiler(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
......
......@@ -20,7 +20,10 @@ class WebContents;
// class.
class FirstWebContentsProfiler : public content::WebContentsObserver {
public:
explicit FirstWebContentsProfiler(content::WebContents* web_contents);
// Creates a profiler for the active web contents. If there are multiple
// browsers, the first one is chosen. The resulting FirstWebContentsProfiler
// owns itself.
static void WebContentsStarted(content::WebContents* web_contents);
private:
// Reasons for which profiling is deemed complete. Logged in UMA (do not re-
......@@ -40,7 +43,7 @@ class FirstWebContentsProfiler : public content::WebContentsObserver {
ABANDON_NAVIGATION_ERROR = 5,
ENUM_MAX
};
explicit FirstWebContentsProfiler(content::WebContents* web_contents);
~FirstWebContentsProfiler() override = default;
// content::WebContentsObserver:
......
......@@ -31,6 +31,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/keep_alive_types.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/search/search.h"
#include "chrome/browser/sessions/session_restore_delegate.h"
......@@ -548,6 +549,7 @@ class SessionRestoreImpl : public content::NotificationObserver {
if (!is_selected_tab)
continue;
FirstWebContentsProfiler::WebContentsStarted(contents);
ShowBrowser(browser, browser->tab_strip_model()->GetIndexOfWebContents(
contents));
// TODO(sky): remove. For debugging 368236.
......
......@@ -377,11 +377,7 @@ content::WebContents* CreateTargetContents(const chrome::NavigateParams& params,
#endif
#if !defined(OS_ANDROID)
static bool first_web_contents_profiled = false;
if (!first_web_contents_profiled) {
first_web_contents_profiled = true;
new FirstWebContentsProfiler(target_contents);
}
FirstWebContentsProfiler::WebContentsStarted(target_contents);
#endif // !defined(OS_ANDROID)
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