Commit 0ea75570 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Check if the browser is closing in TabMetricsLogger

TabMetricsLogger generally shouldn't be invoked to log a UKM for a
background tab if the tab is closing, but there are lots of potential
edge cases where this could happen. If the browser window is being
closed, early exit instead of logging.

Bug: 784639
Change-Id: Ic7f39f1f0cbfbba1dd867195c91365afb630dc61
Reviewed-on: https://chromium-review.googlesource.com/905794Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535973}
parent 23c07181
......@@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/stl_util.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
......@@ -17,6 +18,7 @@
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/custom_handlers/protocol_handler.h"
#include "content/public/browser/render_frame_host.h"
......@@ -175,15 +177,23 @@ void TabMetricsLoggerImpl::LogBackgroundTab(ukm::SourceId ukm_source_id,
return;
content::WebContents* web_contents = tab_metrics.web_contents;
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser)
return;
// UKM recording is disabled in OTR.
if (web_contents->GetBrowserContext()->IsOffTheRecord())
return;
// Verify that the browser is not closing.
const Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser ||
base::ContainsKey(
BrowserList::GetInstance()->currently_closing_browsers(), browser)) {
return;
}
const TabStripModel* tab_strip_model = browser->tab_strip_model();
if (tab_strip_model->closing_all())
return;
int index = tab_strip_model->GetIndexOfWebContents(web_contents);
DCHECK_NE(index, TabStripModel::kNoTab);
......
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