Commit 4e8dabe3 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

RC: Add sequence checking to all significant node member functions.

Bug: 910288
Change-Id: I10193ba9b6531707ac2891b99565e2c1e2e089b9
Reviewed-on: https://chromium-review.googlesource.com/c/1487291
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635206}
parent cce46f44
...@@ -35,6 +35,7 @@ FrameNodeImpl::~FrameNodeImpl() { ...@@ -35,6 +35,7 @@ FrameNodeImpl::~FrameNodeImpl() {
void FrameNodeImpl::SetProcess( void FrameNodeImpl::SetProcess(
const resource_coordinator::CoordinationUnitID& cu_id) { const resource_coordinator::CoordinationUnitID& cu_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ProcessNodeImpl* process_cu = ProcessNodeImpl::GetNodeByID(graph_, cu_id); ProcessNodeImpl* process_cu = ProcessNodeImpl::GetNodeByID(graph_, cu_id);
if (!process_cu) if (!process_cu)
return; return;
...@@ -45,6 +46,7 @@ void FrameNodeImpl::SetProcess( ...@@ -45,6 +46,7 @@ void FrameNodeImpl::SetProcess(
void FrameNodeImpl::AddChildFrame( void FrameNodeImpl::AddChildFrame(
const resource_coordinator::CoordinationUnitID& cu_id) { const resource_coordinator::CoordinationUnitID& cu_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(cu_id != id()); DCHECK(cu_id != id());
FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id); FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id);
if (!frame_cu) if (!frame_cu)
...@@ -61,6 +63,7 @@ void FrameNodeImpl::AddChildFrame( ...@@ -61,6 +63,7 @@ void FrameNodeImpl::AddChildFrame(
void FrameNodeImpl::RemoveChildFrame( void FrameNodeImpl::RemoveChildFrame(
const resource_coordinator::CoordinationUnitID& cu_id) { const resource_coordinator::CoordinationUnitID& cu_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(cu_id != id()); DCHECK(cu_id != id());
FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id); FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id);
if (!frame_cu) if (!frame_cu)
...@@ -77,6 +80,7 @@ void FrameNodeImpl::SetNetworkAlmostIdle(bool idle) { ...@@ -77,6 +80,7 @@ void FrameNodeImpl::SetNetworkAlmostIdle(bool idle) {
void FrameNodeImpl::SetLifecycleState( void FrameNodeImpl::SetLifecycleState(
resource_coordinator::mojom::LifecycleState state) { resource_coordinator::mojom::LifecycleState state) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (state == lifecycle_state_) if (state == lifecycle_state_)
return; return;
...@@ -91,12 +95,14 @@ void FrameNodeImpl::SetLifecycleState( ...@@ -91,12 +95,14 @@ void FrameNodeImpl::SetLifecycleState(
} }
void FrameNodeImpl::SetHasNonEmptyBeforeUnload(bool has_nonempty_beforeunload) { void FrameNodeImpl::SetHasNonEmptyBeforeUnload(bool has_nonempty_beforeunload) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
has_nonempty_beforeunload_ = has_nonempty_beforeunload; has_nonempty_beforeunload_ = has_nonempty_beforeunload;
} }
void FrameNodeImpl::SetInterventionPolicy( void FrameNodeImpl::SetInterventionPolicy(
resource_coordinator::mojom::PolicyControlledIntervention intervention, resource_coordinator::mojom::PolicyControlledIntervention intervention,
resource_coordinator::mojom::InterventionPolicy policy) { resource_coordinator::mojom::InterventionPolicy policy) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
size_t i = static_cast<size_t>(intervention); size_t i = static_cast<size_t>(intervention);
DCHECK_LT(i, base::size(intervention_policy_)); DCHECK_LT(i, base::size(intervention_policy_));
...@@ -128,22 +134,27 @@ void FrameNodeImpl::OnNonPersistentNotificationCreated() { ...@@ -128,22 +134,27 @@ void FrameNodeImpl::OnNonPersistentNotificationCreated() {
} }
FrameNodeImpl* FrameNodeImpl::GetParentFrameNode() const { FrameNodeImpl* FrameNodeImpl::GetParentFrameNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return parent_frame_coordination_unit_; return parent_frame_coordination_unit_;
} }
PageNodeImpl* FrameNodeImpl::GetPageNode() const { PageNodeImpl* FrameNodeImpl::GetPageNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return page_coordination_unit_; return page_coordination_unit_;
} }
ProcessNodeImpl* FrameNodeImpl::GetProcessNode() const { ProcessNodeImpl* FrameNodeImpl::GetProcessNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return process_coordination_unit_; return process_coordination_unit_;
} }
bool FrameNodeImpl::IsMainFrame() const { bool FrameNodeImpl::IsMainFrame() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !parent_frame_coordination_unit_; return !parent_frame_coordination_unit_;
} }
bool FrameNodeImpl::AreAllInterventionPoliciesSet() const { bool FrameNodeImpl::AreAllInterventionPoliciesSet() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// The convention is that policies are first set en masse, in order. So if // The convention is that policies are first set en masse, in order. So if
// the last policy is set then they are all considered to be set. Check this // the last policy is set then they are all considered to be set. Check this
// in DEBUG builds. // in DEBUG builds.
...@@ -169,6 +180,7 @@ bool FrameNodeImpl::AreAllInterventionPoliciesSet() const { ...@@ -169,6 +180,7 @@ bool FrameNodeImpl::AreAllInterventionPoliciesSet() const {
void FrameNodeImpl::SetAllInterventionPoliciesForTesting( void FrameNodeImpl::SetAllInterventionPoliciesForTesting(
resource_coordinator::mojom::InterventionPolicy policy) { resource_coordinator::mojom::InterventionPolicy policy) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (size_t i = 0; i < base::size(intervention_policy_); ++i) { for (size_t i = 0; i < base::size(intervention_policy_); ++i) {
SetInterventionPolicy( SetInterventionPolicy(
static_cast<resource_coordinator::mojom::PolicyControlledIntervention>( static_cast<resource_coordinator::mojom::PolicyControlledIntervention>(
...@@ -178,6 +190,7 @@ void FrameNodeImpl::SetAllInterventionPoliciesForTesting( ...@@ -178,6 +190,7 @@ void FrameNodeImpl::SetAllInterventionPoliciesForTesting(
} }
void FrameNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) { void FrameNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnFrameEventReceived(this, event); observer.OnFrameEventReceived(this, event);
} }
...@@ -185,11 +198,13 @@ void FrameNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) { ...@@ -185,11 +198,13 @@ void FrameNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) {
void FrameNodeImpl::OnPropertyChanged( void FrameNodeImpl::OnPropertyChanged(
resource_coordinator::mojom::PropertyType property_type, resource_coordinator::mojom::PropertyType property_type,
int64_t value) { int64_t value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnFramePropertyChanged(this, property_type, value); observer.OnFramePropertyChanged(this, property_type, value);
} }
bool FrameNodeImpl::HasFrameNodeInAncestors(FrameNodeImpl* frame_cu) const { bool FrameNodeImpl::HasFrameNodeInAncestors(FrameNodeImpl* frame_cu) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (parent_frame_coordination_unit_ == frame_cu || if (parent_frame_coordination_unit_ == frame_cu ||
(parent_frame_coordination_unit_ && (parent_frame_coordination_unit_ &&
parent_frame_coordination_unit_->HasFrameNodeInAncestors(frame_cu))) { parent_frame_coordination_unit_->HasFrameNodeInAncestors(frame_cu))) {
...@@ -199,6 +214,7 @@ bool FrameNodeImpl::HasFrameNodeInAncestors(FrameNodeImpl* frame_cu) const { ...@@ -199,6 +214,7 @@ bool FrameNodeImpl::HasFrameNodeInAncestors(FrameNodeImpl* frame_cu) const {
} }
bool FrameNodeImpl::HasFrameNodeInDescendants(FrameNodeImpl* frame_cu) const { bool FrameNodeImpl::HasFrameNodeInDescendants(FrameNodeImpl* frame_cu) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (FrameNodeImpl* child : child_frame_coordination_units_) { for (FrameNodeImpl* child : child_frame_coordination_units_) {
if (child == frame_cu || child->HasFrameNodeInDescendants(frame_cu)) { if (child == frame_cu || child->HasFrameNodeInDescendants(frame_cu)) {
return true; return true;
...@@ -208,36 +224,43 @@ bool FrameNodeImpl::HasFrameNodeInDescendants(FrameNodeImpl* frame_cu) const { ...@@ -208,36 +224,43 @@ bool FrameNodeImpl::HasFrameNodeInDescendants(FrameNodeImpl* frame_cu) const {
} }
void FrameNodeImpl::AddParentFrame(FrameNodeImpl* parent_frame_cu) { void FrameNodeImpl::AddParentFrame(FrameNodeImpl* parent_frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
parent_frame_coordination_unit_ = parent_frame_cu; parent_frame_coordination_unit_ = parent_frame_cu;
} }
bool FrameNodeImpl::AddChildFrame(FrameNodeImpl* child_frame_cu) { bool FrameNodeImpl::AddChildFrame(FrameNodeImpl* child_frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return child_frame_coordination_units_.count(child_frame_cu) return child_frame_coordination_units_.count(child_frame_cu)
? false ? false
: child_frame_coordination_units_.insert(child_frame_cu).second; : child_frame_coordination_units_.insert(child_frame_cu).second;
} }
void FrameNodeImpl::RemoveParentFrame(FrameNodeImpl* parent_frame_cu) { void FrameNodeImpl::RemoveParentFrame(FrameNodeImpl* parent_frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(parent_frame_coordination_unit_ == parent_frame_cu); DCHECK(parent_frame_coordination_unit_ == parent_frame_cu);
parent_frame_coordination_unit_ = nullptr; parent_frame_coordination_unit_ = nullptr;
} }
bool FrameNodeImpl::RemoveChildFrame(FrameNodeImpl* child_frame_cu) { bool FrameNodeImpl::RemoveChildFrame(FrameNodeImpl* child_frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return child_frame_coordination_units_.erase(child_frame_cu) > 0; return child_frame_coordination_units_.erase(child_frame_cu) > 0;
} }
void FrameNodeImpl::AddPageNode(PageNodeImpl* page_coordination_unit) { void FrameNodeImpl::AddPageNode(PageNodeImpl* page_coordination_unit) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!page_coordination_unit_); DCHECK(!page_coordination_unit_);
page_coordination_unit_ = page_coordination_unit; page_coordination_unit_ = page_coordination_unit;
} }
void FrameNodeImpl::RemovePageNode(PageNodeImpl* page_coordination_unit) { void FrameNodeImpl::RemovePageNode(PageNodeImpl* page_coordination_unit) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(page_coordination_unit == page_coordination_unit_); DCHECK(page_coordination_unit == page_coordination_unit_);
page_coordination_unit_ = nullptr; page_coordination_unit_ = nullptr;
} }
void FrameNodeImpl::RemoveProcessNode( void FrameNodeImpl::RemoveProcessNode(
ProcessNodeImpl* process_coordination_unit) { ProcessNodeImpl* process_coordination_unit) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(process_coordination_unit == process_coordination_unit_); DCHECK(process_coordination_unit == process_coordination_unit_);
process_coordination_unit_ = nullptr; process_coordination_unit_ = nullptr;
} }
......
...@@ -14,30 +14,41 @@ namespace performance_manager { ...@@ -14,30 +14,41 @@ namespace performance_manager {
NodeBase::NodeBase(const resource_coordinator::CoordinationUnitID& id, NodeBase::NodeBase(const resource_coordinator::CoordinationUnitID& id,
Graph* graph) Graph* graph)
: graph_(graph), id_(id.type, id.id) {} : graph_(graph), id_(id.type, id.id) {
// TODO(siggi): The constructor needs to detach from the sequence once the
// lifetime changes are done.
// DETACH_FROM_SEQUENCE(sequence_checker_);
}
NodeBase::~NodeBase() = default; NodeBase::~NodeBase() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void NodeBase::Destruct() { void NodeBase::Destruct() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
graph_->DestroyNode(this); graph_->DestroyNode(this);
} }
void NodeBase::BeforeDestroyed() { void NodeBase::BeforeDestroyed() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnBeforeNodeDestroyed(this); observer.OnBeforeNodeDestroyed(this);
} }
void NodeBase::AddObserver(GraphObserver* observer) { void NodeBase::AddObserver(GraphObserver* observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
void NodeBase::RemoveObserver(GraphObserver* observer) { void NodeBase::RemoveObserver(GraphObserver* observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
bool NodeBase::GetProperty( bool NodeBase::GetProperty(
const resource_coordinator::mojom::PropertyType property_type, const resource_coordinator::mojom::PropertyType property_type,
int64_t* result) const { int64_t* result) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto value_it = properties_.find(property_type); auto value_it = properties_.find(property_type);
if (value_it != properties_.end()) { if (value_it != properties_.end()) {
*result = value_it->second; *result = value_it->second;
...@@ -49,6 +60,7 @@ bool NodeBase::GetProperty( ...@@ -49,6 +60,7 @@ bool NodeBase::GetProperty(
int64_t NodeBase::GetPropertyOrDefault( int64_t NodeBase::GetPropertyOrDefault(
const resource_coordinator::mojom::PropertyType property_type, const resource_coordinator::mojom::PropertyType property_type,
int64_t default_value) const { int64_t default_value) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
int64_t value = 0; int64_t value = 0;
if (GetProperty(property_type, &value)) if (GetProperty(property_type, &value))
return value; return value;
...@@ -56,6 +68,7 @@ int64_t NodeBase::GetPropertyOrDefault( ...@@ -56,6 +68,7 @@ int64_t NodeBase::GetPropertyOrDefault(
} }
void NodeBase::OnEventReceived(resource_coordinator::mojom::Event event) { void NodeBase::OnEventReceived(resource_coordinator::mojom::Event event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnEventReceived(this, event); observer.OnEventReceived(this, event);
} }
...@@ -63,17 +76,20 @@ void NodeBase::OnEventReceived(resource_coordinator::mojom::Event event) { ...@@ -63,17 +76,20 @@ void NodeBase::OnEventReceived(resource_coordinator::mojom::Event event) {
void NodeBase::OnPropertyChanged( void NodeBase::OnPropertyChanged(
resource_coordinator::mojom::PropertyType property_type, resource_coordinator::mojom::PropertyType property_type,
int64_t value) { int64_t value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnPropertyChanged(this, property_type, value); observer.OnPropertyChanged(this, property_type, value);
} }
void NodeBase::SendEvent(resource_coordinator::mojom::Event event) { void NodeBase::SendEvent(resource_coordinator::mojom::Event event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
OnEventReceived(event); OnEventReceived(event);
} }
void NodeBase::SetProperty( void NodeBase::SetProperty(
resource_coordinator::mojom::PropertyType property_type, resource_coordinator::mojom::PropertyType property_type,
int64_t value) { int64_t value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// The |GraphObserver| API specification dictates that // The |GraphObserver| API specification dictates that
// the property is guaranteed to be set on the |NodeBase| // the property is guaranteed to be set on the |NodeBase|
// and propagated to the appropriate associated |CoordianationUnitBase| // and propagated to the appropriate associated |CoordianationUnitBase|
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "chrome/browser/performance_manager/graph/graph.h" #include "chrome/browser/performance_manager/graph/graph.h"
#include "chrome/browser/performance_manager/observers/coordination_unit_graph_observer.h" #include "chrome/browser/performance_manager/observers/coordination_unit_graph_observer.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
...@@ -75,6 +76,8 @@ class NodeBase { ...@@ -75,6 +76,8 @@ class NodeBase {
Graph* const graph_; Graph* const graph_;
const resource_coordinator::CoordinationUnitID id_; const resource_coordinator::CoordinationUnitID id_;
SEQUENCE_CHECKER(sequence_checker_);
private: private:
base::ObserverList<GraphObserver>::Unchecked observers_; base::ObserverList<GraphObserver>::Unchecked observers_;
std::map<resource_coordinator::mojom::PropertyType, int64_t> properties_; std::map<resource_coordinator::mojom::PropertyType, int64_t> properties_;
......
...@@ -40,6 +40,7 @@ PageNodeImpl::~PageNodeImpl() { ...@@ -40,6 +40,7 @@ PageNodeImpl::~PageNodeImpl() {
void PageNodeImpl::AddFrame( void PageNodeImpl::AddFrame(
const resource_coordinator::CoordinationUnitID& cu_id) { const resource_coordinator::CoordinationUnitID& cu_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(cu_id.type == resource_coordinator::CoordinationUnitType::kFrame); DCHECK(cu_id.type == resource_coordinator::CoordinationUnitType::kFrame);
FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id); FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id);
if (!frame_cu) if (!frame_cu)
...@@ -50,6 +51,7 @@ void PageNodeImpl::AddFrame( ...@@ -50,6 +51,7 @@ void PageNodeImpl::AddFrame(
void PageNodeImpl::RemoveFrame( void PageNodeImpl::RemoveFrame(
const resource_coordinator::CoordinationUnitID& cu_id) { const resource_coordinator::CoordinationUnitID& cu_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(cu_id != id()); DCHECK(cu_id != id());
FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id); FrameNodeImpl* frame_cu = FrameNodeImpl::GetNodeByID(graph_, cu_id);
if (!frame_cu) if (!frame_cu)
...@@ -84,6 +86,7 @@ void PageNodeImpl::OnMainFrameNavigationCommitted( ...@@ -84,6 +86,7 @@ void PageNodeImpl::OnMainFrameNavigationCommitted(
base::TimeTicks navigation_committed_time, base::TimeTicks navigation_committed_time,
int64_t navigation_id, int64_t navigation_id,
const std::string& url) { const std::string& url) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
navigation_committed_time_ = navigation_committed_time; navigation_committed_time_ = navigation_committed_time;
main_frame_url_ = url; main_frame_url_ = url;
navigation_id_ = navigation_id; navigation_id_ = navigation_id;
...@@ -92,6 +95,7 @@ void PageNodeImpl::OnMainFrameNavigationCommitted( ...@@ -92,6 +95,7 @@ void PageNodeImpl::OnMainFrameNavigationCommitted(
std::set<ProcessNodeImpl*> PageNodeImpl::GetAssociatedProcessCoordinationUnits() std::set<ProcessNodeImpl*> PageNodeImpl::GetAssociatedProcessCoordinationUnits()
const { const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::set<ProcessNodeImpl*> process_cus; std::set<ProcessNodeImpl*> process_cus;
for (auto* frame_cu : frame_coordination_units_) { for (auto* frame_cu : frame_coordination_units_) {
...@@ -103,6 +107,7 @@ std::set<ProcessNodeImpl*> PageNodeImpl::GetAssociatedProcessCoordinationUnits() ...@@ -103,6 +107,7 @@ std::set<ProcessNodeImpl*> PageNodeImpl::GetAssociatedProcessCoordinationUnits()
} }
bool PageNodeImpl::IsVisible() const { bool PageNodeImpl::IsVisible() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
int64_t is_visible = 0; int64_t is_visible = 0;
bool has_property = GetProperty( bool has_property = GetProperty(
resource_coordinator::mojom::PropertyType::kVisible, &is_visible); resource_coordinator::mojom::PropertyType::kVisible, &is_visible);
...@@ -111,6 +116,7 @@ bool PageNodeImpl::IsVisible() const { ...@@ -111,6 +116,7 @@ bool PageNodeImpl::IsVisible() const {
} }
double PageNodeImpl::GetCPUUsage() const { double PageNodeImpl::GetCPUUsage() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
double cpu_usage = 0.0; double cpu_usage = 0.0;
for (auto* process_cu : GetAssociatedProcessCoordinationUnits()) { for (auto* process_cu : GetAssociatedProcessCoordinationUnits()) {
...@@ -130,6 +136,7 @@ double PageNodeImpl::GetCPUUsage() const { ...@@ -130,6 +136,7 @@ double PageNodeImpl::GetCPUUsage() const {
} }
bool PageNodeImpl::GetExpectedTaskQueueingDuration(int64_t* output) { bool PageNodeImpl::GetExpectedTaskQueueingDuration(int64_t* output) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Calculate the EQT for the process of the main frame only because // Calculate the EQT for the process of the main frame only because
// the smoothness of the main frame may affect the users the most. // the smoothness of the main frame may affect the users the most.
FrameNodeImpl* main_frame_cu = GetMainFrameNode(); FrameNodeImpl* main_frame_cu = GetMainFrameNode();
...@@ -144,16 +151,19 @@ bool PageNodeImpl::GetExpectedTaskQueueingDuration(int64_t* output) { ...@@ -144,16 +151,19 @@ bool PageNodeImpl::GetExpectedTaskQueueingDuration(int64_t* output) {
} }
base::TimeDelta PageNodeImpl::TimeSinceLastNavigation() const { base::TimeDelta PageNodeImpl::TimeSinceLastNavigation() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (navigation_committed_time_.is_null()) if (navigation_committed_time_.is_null())
return base::TimeDelta(); return base::TimeDelta();
return ResourceCoordinatorClock::NowTicks() - navigation_committed_time_; return ResourceCoordinatorClock::NowTicks() - navigation_committed_time_;
} }
base::TimeDelta PageNodeImpl::TimeSinceLastVisibilityChange() const { base::TimeDelta PageNodeImpl::TimeSinceLastVisibilityChange() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return ResourceCoordinatorClock::NowTicks() - visibility_change_time_; return ResourceCoordinatorClock::NowTicks() - visibility_change_time_;
} }
FrameNodeImpl* PageNodeImpl::GetMainFrameNode() const { FrameNodeImpl* PageNodeImpl::GetMainFrameNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto* frame_cu : frame_coordination_units_) { for (auto* frame_cu : frame_coordination_units_) {
if (frame_cu->IsMainFrame()) if (frame_cu->IsMainFrame())
return frame_cu; return frame_cu;
...@@ -164,6 +174,7 @@ FrameNodeImpl* PageNodeImpl::GetMainFrameNode() const { ...@@ -164,6 +174,7 @@ FrameNodeImpl* PageNodeImpl::GetMainFrameNode() const {
void PageNodeImpl::OnFrameLifecycleStateChanged( void PageNodeImpl::OnFrameLifecycleStateChanged(
FrameNodeImpl* frame_cu, FrameNodeImpl* frame_cu,
resource_coordinator::mojom::LifecycleState old_state) { resource_coordinator::mojom::LifecycleState old_state) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(base::ContainsKey(frame_coordination_units_, frame_cu)); DCHECK(base::ContainsKey(frame_coordination_units_, frame_cu));
DCHECK_NE(old_state, frame_cu->lifecycle_state()); DCHECK_NE(old_state, frame_cu->lifecycle_state());
...@@ -182,6 +193,7 @@ void PageNodeImpl::OnFrameInterventionPolicyChanged( ...@@ -182,6 +193,7 @@ void PageNodeImpl::OnFrameInterventionPolicyChanged(
resource_coordinator::mojom::PolicyControlledIntervention intervention, resource_coordinator::mojom::PolicyControlledIntervention intervention,
resource_coordinator::mojom::InterventionPolicy old_policy, resource_coordinator::mojom::InterventionPolicy old_policy,
resource_coordinator::mojom::InterventionPolicy new_policy) { resource_coordinator::mojom::InterventionPolicy new_policy) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const size_t kIndex = ToIndex(intervention); const size_t kIndex = ToIndex(intervention);
// Invalidate the local policy aggregation for this intervention. It will be // Invalidate the local policy aggregation for this intervention. It will be
...@@ -205,6 +217,7 @@ void PageNodeImpl::OnFrameInterventionPolicyChanged( ...@@ -205,6 +217,7 @@ void PageNodeImpl::OnFrameInterventionPolicyChanged(
resource_coordinator::mojom::InterventionPolicy resource_coordinator::mojom::InterventionPolicy
PageNodeImpl::GetInterventionPolicy( PageNodeImpl::GetInterventionPolicy(
resource_coordinator::mojom::PolicyControlledIntervention intervention) { resource_coordinator::mojom::PolicyControlledIntervention intervention) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// If there are no frames, or they've not all reported, then return kUnknown. // If there are no frames, or they've not all reported, then return kUnknown.
if (frame_coordination_units_.empty() || if (frame_coordination_units_.empty() ||
intervention_policy_frames_reported_ != intervention_policy_frames_reported_ !=
...@@ -226,6 +239,7 @@ PageNodeImpl::GetInterventionPolicy( ...@@ -226,6 +239,7 @@ PageNodeImpl::GetInterventionPolicy(
} }
void PageNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) { void PageNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnPageEventReceived(this, event); observer.OnPageEventReceived(this, event);
} }
...@@ -233,6 +247,7 @@ void PageNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) { ...@@ -233,6 +247,7 @@ void PageNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) {
void PageNodeImpl::OnPropertyChanged( void PageNodeImpl::OnPropertyChanged(
const resource_coordinator::mojom::PropertyType property_type, const resource_coordinator::mojom::PropertyType property_type,
int64_t value) { int64_t value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (property_type == resource_coordinator::mojom::PropertyType::kVisible) if (property_type == resource_coordinator::mojom::PropertyType::kVisible)
visibility_change_time_ = ResourceCoordinatorClock::NowTicks(); visibility_change_time_ = ResourceCoordinatorClock::NowTicks();
for (auto& observer : observers()) for (auto& observer : observers())
...@@ -240,6 +255,7 @@ void PageNodeImpl::OnPropertyChanged( ...@@ -240,6 +255,7 @@ void PageNodeImpl::OnPropertyChanged(
} }
bool PageNodeImpl::AddFrame(FrameNodeImpl* frame_cu) { bool PageNodeImpl::AddFrame(FrameNodeImpl* frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const bool inserted = frame_coordination_units_.insert(frame_cu).second; const bool inserted = frame_coordination_units_.insert(frame_cu).second;
if (inserted) { if (inserted) {
OnNumFrozenFramesStateChange( OnNumFrozenFramesStateChange(
...@@ -253,6 +269,7 @@ bool PageNodeImpl::AddFrame(FrameNodeImpl* frame_cu) { ...@@ -253,6 +269,7 @@ bool PageNodeImpl::AddFrame(FrameNodeImpl* frame_cu) {
} }
bool PageNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) { bool PageNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool removed = frame_coordination_units_.erase(frame_cu) > 0; bool removed = frame_coordination_units_.erase(frame_cu) > 0;
if (removed) { if (removed) {
OnNumFrozenFramesStateChange( OnNumFrozenFramesStateChange(
...@@ -267,6 +284,7 @@ bool PageNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) { ...@@ -267,6 +284,7 @@ bool PageNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) {
} }
void PageNodeImpl::OnNumFrozenFramesStateChange(int num_frozen_frames_delta) { void PageNodeImpl::OnNumFrozenFramesStateChange(int num_frozen_frames_delta) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
num_frozen_frames_ += num_frozen_frames_delta; num_frozen_frames_ += num_frozen_frames_delta;
DCHECK_LE(num_frozen_frames_, frame_coordination_units_.size()); DCHECK_LE(num_frozen_frames_, frame_coordination_units_.size());
...@@ -307,6 +325,7 @@ void PageNodeImpl::OnNumFrozenFramesStateChange(int num_frozen_frames_delta) { ...@@ -307,6 +325,7 @@ void PageNodeImpl::OnNumFrozenFramesStateChange(int num_frozen_frames_delta) {
} }
void PageNodeImpl::InvalidateAllInterventionPolicies() { void PageNodeImpl::InvalidateAllInterventionPolicies() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (size_t i = 0; i <= kMaxInterventionIndex; ++i) for (size_t i = 0; i <= kMaxInterventionIndex; ++i)
intervention_policy_[i] = intervention_policy_[i] =
resource_coordinator::mojom::InterventionPolicy::kUnknown; resource_coordinator::mojom::InterventionPolicy::kUnknown;
...@@ -314,6 +333,7 @@ void PageNodeImpl::InvalidateAllInterventionPolicies() { ...@@ -314,6 +333,7 @@ void PageNodeImpl::InvalidateAllInterventionPolicies() {
void PageNodeImpl::MaybeInvalidateInterventionPolicies(FrameNodeImpl* frame_cu, void PageNodeImpl::MaybeInvalidateInterventionPolicies(FrameNodeImpl* frame_cu,
bool adding_frame) { bool adding_frame) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Ensure that the frame was already added or removed as expected. // Ensure that the frame was already added or removed as expected.
DCHECK(adding_frame == frame_coordination_units_.count(frame_cu)); DCHECK(adding_frame == frame_coordination_units_.count(frame_cu));
...@@ -343,6 +363,7 @@ void PageNodeImpl::MaybeInvalidateInterventionPolicies(FrameNodeImpl* frame_cu, ...@@ -343,6 +363,7 @@ void PageNodeImpl::MaybeInvalidateInterventionPolicies(FrameNodeImpl* frame_cu,
void PageNodeImpl::RecomputeInterventionPolicy( void PageNodeImpl::RecomputeInterventionPolicy(
resource_coordinator::mojom::PolicyControlledIntervention intervention) { resource_coordinator::mojom::PolicyControlledIntervention intervention) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const size_t kIndex = ToIndex(intervention); const size_t kIndex = ToIndex(intervention);
// This should never be called with an empty frame tree. // This should never be called with an empty frame tree.
......
...@@ -27,6 +27,7 @@ ProcessNodeImpl::~ProcessNodeImpl() { ...@@ -27,6 +27,7 @@ ProcessNodeImpl::~ProcessNodeImpl() {
void ProcessNodeImpl::AddFrame(FrameNodeImpl* frame_cu) { void ProcessNodeImpl::AddFrame(FrameNodeImpl* frame_cu) {
const bool inserted = frame_coordination_units_.insert(frame_cu).second; const bool inserted = frame_coordination_units_.insert(frame_cu).second;
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(inserted); DCHECK(inserted);
if (frame_cu->lifecycle_state() == if (frame_cu->lifecycle_state() ==
resource_coordinator::mojom::LifecycleState::kFrozen) resource_coordinator::mojom::LifecycleState::kFrozen)
...@@ -46,6 +47,7 @@ void ProcessNodeImpl::SetExpectedTaskQueueingDuration( ...@@ -46,6 +47,7 @@ void ProcessNodeImpl::SetExpectedTaskQueueingDuration(
} }
void ProcessNodeImpl::SetLaunchTime(base::Time launch_time) { void ProcessNodeImpl::SetLaunchTime(base::Time launch_time) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(launch_time_.is_null()); DCHECK(launch_time_.is_null());
launch_time_ = launch_time; launch_time_ = launch_time;
} }
...@@ -58,6 +60,7 @@ void ProcessNodeImpl::SetMainThreadTaskLoadIsLow( ...@@ -58,6 +60,7 @@ void ProcessNodeImpl::SetMainThreadTaskLoadIsLow(
} }
void ProcessNodeImpl::SetPID(base::ProcessId pid) { void ProcessNodeImpl::SetPID(base::ProcessId pid) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Either this is the initial process associated with this process CU, // Either this is the initial process associated with this process CU,
// or it's a subsequent process. In the latter case, there must have been // or it's a subsequent process. In the latter case, there must have been
// an exit status associated with the previous process. // an exit status associated with the previous process.
...@@ -80,6 +83,7 @@ void ProcessNodeImpl::SetPID(base::ProcessId pid) { ...@@ -80,6 +83,7 @@ void ProcessNodeImpl::SetPID(base::ProcessId pid) {
} }
void ProcessNodeImpl::SetProcessExitStatus(int32_t exit_status) { void ProcessNodeImpl::SetProcessExitStatus(int32_t exit_status) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
exit_status_ = exit_status; exit_status_ = exit_status;
} }
...@@ -88,6 +92,7 @@ void ProcessNodeImpl::OnRendererIsBloated() { ...@@ -88,6 +92,7 @@ void ProcessNodeImpl::OnRendererIsBloated() {
} }
const std::set<FrameNodeImpl*>& ProcessNodeImpl::GetFrameNodes() const { const std::set<FrameNodeImpl*>& ProcessNodeImpl::GetFrameNodes() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_coordination_units_; return frame_coordination_units_;
} }
...@@ -97,6 +102,7 @@ const std::set<FrameNodeImpl*>& ProcessNodeImpl::GetFrameNodes() const { ...@@ -97,6 +102,7 @@ const std::set<FrameNodeImpl*>& ProcessNodeImpl::GetFrameNodes() const {
// frames. // frames.
std::set<PageNodeImpl*> ProcessNodeImpl::GetAssociatedPageCoordinationUnits() std::set<PageNodeImpl*> ProcessNodeImpl::GetAssociatedPageCoordinationUnits()
const { const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::set<PageNodeImpl*> page_cus; std::set<PageNodeImpl*> page_cus;
for (auto* frame_cu : frame_coordination_units_) { for (auto* frame_cu : frame_coordination_units_) {
if (auto* page_cu = frame_cu->GetPageNode()) if (auto* page_cu = frame_cu->GetPageNode())
...@@ -108,6 +114,7 @@ std::set<PageNodeImpl*> ProcessNodeImpl::GetAssociatedPageCoordinationUnits() ...@@ -108,6 +114,7 @@ std::set<PageNodeImpl*> ProcessNodeImpl::GetAssociatedPageCoordinationUnits()
void ProcessNodeImpl::OnFrameLifecycleStateChanged( void ProcessNodeImpl::OnFrameLifecycleStateChanged(
FrameNodeImpl* frame_cu, FrameNodeImpl* frame_cu,
resource_coordinator::mojom::LifecycleState old_state) { resource_coordinator::mojom::LifecycleState old_state) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(base::ContainsKey(frame_coordination_units_, frame_cu)); DCHECK(base::ContainsKey(frame_coordination_units_, frame_cu));
DCHECK_NE(old_state, frame_cu->lifecycle_state()); DCHECK_NE(old_state, frame_cu->lifecycle_state());
...@@ -120,6 +127,7 @@ void ProcessNodeImpl::OnFrameLifecycleStateChanged( ...@@ -120,6 +127,7 @@ void ProcessNodeImpl::OnFrameLifecycleStateChanged(
void ProcessNodeImpl::OnEventReceived( void ProcessNodeImpl::OnEventReceived(
resource_coordinator::mojom::Event event) { resource_coordinator::mojom::Event event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnProcessEventReceived(this, event); observer.OnProcessEventReceived(this, event);
} }
...@@ -127,11 +135,13 @@ void ProcessNodeImpl::OnEventReceived( ...@@ -127,11 +135,13 @@ void ProcessNodeImpl::OnEventReceived(
void ProcessNodeImpl::OnPropertyChanged( void ProcessNodeImpl::OnPropertyChanged(
const resource_coordinator::mojom::PropertyType property_type, const resource_coordinator::mojom::PropertyType property_type,
int64_t value) { int64_t value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnProcessPropertyChanged(this, property_type, value); observer.OnProcessPropertyChanged(this, property_type, value);
} }
void ProcessNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) { void ProcessNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(base::ContainsKey(frame_coordination_units_, frame_cu)); DCHECK(base::ContainsKey(frame_coordination_units_, frame_cu));
frame_coordination_units_.erase(frame_cu); frame_coordination_units_.erase(frame_cu);
...@@ -141,11 +151,13 @@ void ProcessNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) { ...@@ -141,11 +151,13 @@ void ProcessNodeImpl::RemoveFrame(FrameNodeImpl* frame_cu) {
} }
void ProcessNodeImpl::DecrementNumFrozenFrames() { void ProcessNodeImpl::DecrementNumFrozenFrames() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
--num_frozen_frames_; --num_frozen_frames_;
DCHECK_GE(num_frozen_frames_, 0); DCHECK_GE(num_frozen_frames_, 0);
} }
void ProcessNodeImpl::IncrementNumFrozenFrames() { void ProcessNodeImpl::IncrementNumFrozenFrames() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
++num_frozen_frames_; ++num_frozen_frames_;
DCHECK_LE(num_frozen_frames_, DCHECK_LE(num_frozen_frames_,
static_cast<int>(frame_coordination_units_.size())); static_cast<int>(frame_coordination_units_.size()));
......
...@@ -30,6 +30,7 @@ void SystemNodeImpl::OnProcessCPUUsageReady() { ...@@ -30,6 +30,7 @@ void SystemNodeImpl::OnProcessCPUUsageReady() {
void SystemNodeImpl::DistributeMeasurementBatch( void SystemNodeImpl::DistributeMeasurementBatch(
resource_coordinator::mojom::ProcessResourceMeasurementBatchPtr resource_coordinator::mojom::ProcessResourceMeasurementBatchPtr
measurement_batch) { measurement_batch) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::TimeDelta time_since_last_measurement; base::TimeDelta time_since_last_measurement;
if (!last_measurement_end_time_.is_null()) { if (!last_measurement_end_time_.is_null()) {
// Use the end of the measurement batch as a proxy for when every // Use the end of the measurement batch as a proxy for when every
...@@ -156,6 +157,7 @@ void SystemNodeImpl::DistributeMeasurementBatch( ...@@ -156,6 +157,7 @@ void SystemNodeImpl::DistributeMeasurementBatch(
} }
void SystemNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) { void SystemNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnSystemEventReceived(this, event); observer.OnSystemEventReceived(this, event);
} }
...@@ -163,6 +165,7 @@ void SystemNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) { ...@@ -163,6 +165,7 @@ void SystemNodeImpl::OnEventReceived(resource_coordinator::mojom::Event event) {
void SystemNodeImpl::OnPropertyChanged( void SystemNodeImpl::OnPropertyChanged(
resource_coordinator::mojom::PropertyType property_type, resource_coordinator::mojom::PropertyType property_type,
int64_t value) { int64_t value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& observer : observers()) for (auto& observer : observers())
observer.OnSystemPropertyChanged(this, property_type, value); observer.OnSystemPropertyChanged(this, property_type, value);
} }
......
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