Commit 06d779c4 authored by sangwoo.ko's avatar sangwoo.ko Committed by Commit Bot

Use RenderWidgetHostVisibilityTracker correctly

RenderWidgetHostVisibilityTracker should outlive
OnTabStripModelChanged().

Bug: 907237
Change-Id: I784140523076ba2472a04b98b0840f0bd75ba50d
Reviewed-on: https://chromium-review.googlesource.com/c/1345750Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610888}
parent 5eaea8ea
...@@ -48,6 +48,8 @@ using content::WebContents; ...@@ -48,6 +48,8 @@ using content::WebContents;
namespace { namespace {
class RenderWidgetHostVisibilityTracker;
// Returns true if the specified transition is one of the types that cause the // Returns true if the specified transition is one of the types that cause the
// opener relationships for the tab in which the transition occurred to be // opener relationships for the tab in which the transition occurred to be
// forgotten. This is generally any navigation that isn't a link click (i.e. // forgotten. This is generally any navigation that isn't a link click (i.e.
...@@ -65,6 +67,21 @@ bool ShouldForgetOpenersForTransition(ui::PageTransition transition) { ...@@ -65,6 +67,21 @@ bool ShouldForgetOpenersForTransition(ui::PageTransition transition) {
ui::PAGE_TRANSITION_AUTO_TOPLEVEL); ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
} }
// Intalls RenderWidgetVisibilityTracker when the active tab has changed.
std::unique_ptr<RenderWidgetHostVisibilityTracker>
InstallRenderWigetVisibilityTracker(const TabStripSelectionChange& selection) {
if (!selection.active_tab_changed())
return nullptr;
content::RenderWidgetHost* track_host = nullptr;
if (selection.new_contents &&
selection.new_contents->GetRenderWidgetHostView()) {
track_host = selection.new_contents->GetRenderWidgetHostView()
->GetRenderWidgetHost();
}
return std::make_unique<RenderWidgetHostVisibilityTracker>(track_host);
}
// This tracks (and reports via UMA and tracing) how long it takes before a // This tracks (and reports via UMA and tracing) how long it takes before a
// RenderWidgetHost is requested to become visible. // RenderWidgetHost is requested to become visible.
class RenderWidgetHostVisibilityTracker class RenderWidgetHostVisibilityTracker
...@@ -486,17 +503,14 @@ void TabStripModel::SendDetachWebContentsNotifications( ...@@ -486,17 +503,14 @@ void TabStripModel::SendDetachWebContentsNotifications(
}); });
TabStripModelChange change(TabStripModelChange::kRemoved, deltas); TabStripModelChange change(TabStripModelChange::kRemoved, deltas);
for (auto& observer : observers_) {
observer.OnTabStripModelChanged(this, change, selection); auto visibility_tracker =
empty() ? nullptr : InstallRenderWigetVisibilityTracker(selection);
for (auto& observer : observers_)
observer.OnTabStripModelChanged(this, change, selection);
}
for (auto& dwc : notifications->detached_web_contents) { for (auto& dwc : notifications->detached_web_contents) {
if (notifications->initially_active_web_contents &&
dwc->contents.get() == notifications->initially_active_web_contents) {
if (!empty())
InstallRenderWigetVisibilityTracker(selection);
notifications->initially_active_web_contents = nullptr;
}
if (notifications->will_delete) { if (notifications->will_delete) {
// This destroys the WebContents, which will also send // This destroys the WebContents, which will also send
// WebContentsDestroyed notifications. // WebContentsDestroyed notifications.
...@@ -1359,19 +1373,6 @@ WebContents* TabStripModel::GetWebContentsAtImpl(int index) const { ...@@ -1359,19 +1373,6 @@ WebContents* TabStripModel::GetWebContentsAtImpl(int index) const {
return contents_data_[index]->web_contents(); return contents_data_[index]->web_contents();
} }
void TabStripModel::InstallRenderWigetVisibilityTracker(
const TabStripSelectionChange& selection) {
if (!selection.active_tab_changed())
return;
content::RenderWidgetHost* track_host = nullptr;
if (selection.new_contents &&
selection.new_contents->GetRenderWidgetHostView()) {
track_host = selection.new_contents->GetRenderWidgetHostView()
->GetRenderWidgetHost();
}
RenderWidgetHostVisibilityTracker tracker(track_host);
}
TabStripSelectionChange TabStripModel::SetSelection( TabStripSelectionChange TabStripModel::SetSelection(
ui::ListSelectionModel new_model, ui::ListSelectionModel new_model,
...@@ -1389,11 +1390,10 @@ TabStripSelectionChange TabStripModel::SetSelection( ...@@ -1389,11 +1390,10 @@ TabStripSelectionChange TabStripModel::SetSelection(
selection_model_ = new_model; selection_model_ = new_model;
selection.new_contents = GetActiveWebContents(); selection.new_contents = GetActiveWebContents();
InstallRenderWigetVisibilityTracker(selection);
if (!triggered_by_other_operation && if (!triggered_by_other_operation &&
(selection.active_tab_changed() || selection.selection_changed())) { (selection.active_tab_changed() || selection.selection_changed())) {
TabStripModelChange change; TabStripModelChange change;
auto visibility_tracker = InstallRenderWigetVisibilityTracker(selection);
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnTabStripModelChanged(this, change, selection); observer.OnTabStripModelChanged(this, change, selection);
} }
......
...@@ -481,10 +481,6 @@ class TabStripModel { ...@@ -481,10 +481,6 @@ class TabStripModel {
std::vector<content::WebContents*> GetWebContentsesByIndices( std::vector<content::WebContents*> GetWebContentsesByIndices(
const std::vector<int>& indices); const std::vector<int>& indices);
// Intalls RenderWidgetVisibilityTracker when the active tab has changed.
void InstallRenderWigetVisibilityTracker(
const TabStripSelectionChange& selection);
// Sets the selection to |new_model| and notifies any observers. // Sets the selection to |new_model| and notifies any observers.
// Note: This function might end up sending 0 to 3 notifications in the // Note: This function might end up sending 0 to 3 notifications in the
// following order: TabDeactivated, ActiveTabChanged, TabSelectionChanged. // following order: TabDeactivated, ActiveTabChanged, TabSelectionChanged.
......
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