Commit 36ced796 authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Set the WebLock/Indexed DB lock usage property in TabLifecycleUnit

The CL that uses this in freezing will follow.

Bug: 999594
Change-Id: I8dd17798ce4f707e99d57d0e9aec6d9da91d5f88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846091
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703504}
parent ae71a50d
...@@ -423,6 +423,16 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy( ...@@ -423,6 +423,16 @@ void TabLifecycleUnitSource::TabLifecycleUnit::UpdateOriginTrialFreezePolicy(
origin_trial_freeze_policy_ = policy; origin_trial_freeze_policy_ = policy;
} }
void TabLifecycleUnitSource::TabLifecycleUnit::SetIsHoldingWebLock(
bool is_holding_weblock) {
is_holding_weblock_ = is_holding_weblock;
}
void TabLifecycleUnitSource::TabLifecycleUnit::SetIsHoldingIndexedDBLock(
bool is_holding_indexeddb_lock) {
is_holding_indexeddb_lock_ = is_holding_indexeddb_lock;
}
void TabLifecycleUnitSource::TabLifecycleUnit::RequestFreezeForDiscard( void TabLifecycleUnitSource::TabLifecycleUnit::RequestFreezeForDiscard(
LifecycleUnitDiscardReason reason) { LifecycleUnitDiscardReason reason) {
DCHECK_EQ(reason, LifecycleUnitDiscardReason::PROACTIVE); DCHECK_EQ(reason, LifecycleUnitDiscardReason::PROACTIVE);
......
...@@ -93,6 +93,10 @@ class TabLifecycleUnitSource::TabLifecycleUnit ...@@ -93,6 +93,10 @@ class TabLifecycleUnitSource::TabLifecycleUnit
// Updates the tab's origin trial freeze policy. // Updates the tab's origin trial freeze policy.
void UpdateOriginTrialFreezePolicy(mojom::InterventionPolicy policy); void UpdateOriginTrialFreezePolicy(mojom::InterventionPolicy policy);
// Setters for the WebLock and IndexedDB lock usage properties.
void SetIsHoldingWebLock(bool is_holding_weblock);
void SetIsHoldingIndexedDBLock(bool is_holding_indexeddb_lock);
// LifecycleUnit: // LifecycleUnit:
TabLifecycleUnitExternal* AsTabLifecycleUnitExternal() override; TabLifecycleUnitExternal* AsTabLifecycleUnitExternal() override;
base::string16 GetTitle() const override; base::string16 GetTitle() const override;
...@@ -225,6 +229,14 @@ class TabLifecycleUnitSource::TabLifecycleUnit ...@@ -225,6 +229,14 @@ class TabLifecycleUnitSource::TabLifecycleUnit
// tab was "recently audible" otherwise. // tab was "recently audible" otherwise.
base::TimeTicks recently_audible_time_; base::TimeTicks recently_audible_time_;
// Indicates if at least one of the frames of this tab is currently holding
// at least one WebLock.
bool is_holding_weblock_ = false;
// Indicates if at least one of the frames of this tab is currently holding
// at least one IndexedDB Lock.
bool is_holding_indexeddb_lock_ = false;
std::unique_ptr<TabLifecycleUnitExternalImpl> external_impl_; std::unique_ptr<TabLifecycleUnitExternalImpl> external_impl_;
DISALLOW_COPY_AND_ASSIGN(TabLifecycleUnit); DISALLOW_COPY_AND_ASSIGN(TabLifecycleUnit);
......
...@@ -97,6 +97,30 @@ class TabLifecycleStateObserver ...@@ -97,6 +97,30 @@ class TabLifecycleStateObserver
} }
} }
static void OnPageIsHoldingWebLockChangedImpl(
const WebContentsProxy& contents_proxy,
bool is_holding_weblock) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// If the web contents is still alive then dispatch to the actual
// implementation in TabLifecycleUnitSource.
if (auto* contents = contents_proxy.Get()) {
TabLifecycleUnitSource::OnIsHoldingWebLockChanged(contents,
is_holding_weblock);
}
}
static void OnPageIsHoldingIndexedDBLockChangedImpl(
const WebContentsProxy& contents_proxy,
bool is_holding_indexeddb_lock) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// If the web contents is still alive then dispatch to the actual
// implementation in TabLifecycleUnitSource.
if (auto* contents = contents_proxy.Get()) {
TabLifecycleUnitSource::OnIsHoldingIndexedDBLockChanged(
contents, is_holding_indexeddb_lock);
}
}
// performance_manager::PageNode::ObserverDefaultImpl:: // performance_manager::PageNode::ObserverDefaultImpl::
void OnPageLifecycleStateChanged(const PageNode* page_node) override { void OnPageLifecycleStateChanged(const PageNode* page_node) override {
// Forward the notification over to the UI thread. // Forward the notification over to the UI thread.
...@@ -118,6 +142,25 @@ class TabLifecycleStateObserver ...@@ -118,6 +142,25 @@ class TabLifecycleStateObserver
page_node->GetOriginTrialFreezePolicy())); page_node->GetOriginTrialFreezePolicy()));
} }
void OnPageIsHoldingWebLockChanged(const PageNode* page_node) override {
// Forward the notification over to the UI thread.
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(
&TabLifecycleStateObserver::OnPageIsHoldingWebLockChangedImpl,
page_node->GetContentsProxy(), page_node->IsHoldingWebLock()));
}
void OnPageIsHoldingIndexedDBLockChanged(const PageNode* page_node) override {
// Forward the notification over to the UI thread.
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(
&TabLifecycleStateObserver::OnPageIsHoldingIndexedDBLockChangedImpl,
page_node->GetContentsProxy(),
page_node->IsHoldingIndexedDBLock()));
}
void OnPassedToGraph(Graph* graph) override { void OnPassedToGraph(Graph* graph) override {
graph->AddPageNodeObserver(this); graph->AddPageNodeObserver(this);
} }
...@@ -384,6 +427,30 @@ void TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged( ...@@ -384,6 +427,30 @@ void TabLifecycleUnitSource::OnOriginTrialFreezePolicyChanged(
lifecycle_unit->UpdateOriginTrialFreezePolicy(policy); lifecycle_unit->UpdateOriginTrialFreezePolicy(policy);
} }
// static
void TabLifecycleUnitSource::OnIsHoldingWebLockChanged(
content::WebContents* web_contents,
bool is_holding_weblock) {
TabLifecycleUnit* lifecycle_unit = GetTabLifecycleUnit(web_contents);
// Some WebContents aren't attached to a tab, so there is no corresponding
// TabLifecycleUnit.
if (lifecycle_unit)
lifecycle_unit->SetIsHoldingWebLock(is_holding_weblock);
}
// static
void TabLifecycleUnitSource::OnIsHoldingIndexedDBLockChanged(
content::WebContents* web_contents,
bool is_holding_indexeddb_lock) {
TabLifecycleUnit* lifecycle_unit = GetTabLifecycleUnit(web_contents);
// Some WebContents aren't attached to a tab, so there is no corresponding
// TabLifecycleUnit.
if (lifecycle_unit)
lifecycle_unit->SetIsHoldingIndexedDBLock(is_holding_indexeddb_lock);
}
void TabLifecycleUnitSource::SetTabLifecyclesEnterprisePolicy(bool enabled) { void TabLifecycleUnitSource::SetTabLifecyclesEnterprisePolicy(bool enabled) {
tab_lifecycles_enterprise_policy_ = enabled; tab_lifecycles_enterprise_policy_ = enabled;
} }
......
...@@ -154,6 +154,11 @@ class TabLifecycleUnitSource : public BrowserListObserver, ...@@ -154,6 +154,11 @@ class TabLifecycleUnitSource : public BrowserListObserver,
static void OnOriginTrialFreezePolicyChanged( static void OnOriginTrialFreezePolicyChanged(
content::WebContents* web_contents, content::WebContents* web_contents,
mojom::InterventionPolicy policy); mojom::InterventionPolicy policy);
static void OnIsHoldingWebLockChanged(content::WebContents* web_contents,
bool is_holding_weblock);
static void OnIsHoldingIndexedDBLockChanged(
content::WebContents* web_contents,
bool is_holding_indexeddb_lock);
// Callback for TabLifecyclesEnterprisePreferenceMonitor. // Callback for TabLifecyclesEnterprisePreferenceMonitor.
void SetTabLifecyclesEnterprisePolicy(bool enabled); void SetTabLifecyclesEnterprisePolicy(bool enabled);
......
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