node_base.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/performance_manager/graph/node_base.h"
  5. #include "components/performance_manager/graph/graph_impl.h"
  6. #include "components/performance_manager/public/graph/node.h"
  7. namespace performance_manager {
  8. // static
  9. const uintptr_t NodeBase::kNodeBaseType =
  10. reinterpret_cast<uintptr_t>(&kNodeBaseType);
  11. NodeBase::NodeBase(NodeTypeEnum node_type) : type_(node_type) {}
  12. NodeBase::~NodeBase() {
  13. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  14. // The node must have been removed from the graph before destruction.
  15. DCHECK(!graph_);
  16. DCHECK_EQ(NodeState::kNotInGraph, GetNodeState());
  17. }
  18. // static
  19. const NodeBase* NodeBase::FromNode(const Node* node) {
  20. CHECK_EQ(kNodeBaseType, node->GetImplType());
  21. return reinterpret_cast<const NodeBase*>(node->GetImpl());
  22. }
  23. // static
  24. NodeBase* NodeBase::FromNode(Node* node) {
  25. CHECK_EQ(kNodeBaseType, node->GetImplType());
  26. return reinterpret_cast<NodeBase*>(const_cast<void*>(node->GetImpl()));
  27. }
  28. bool NodeBase::CanSetProperty() const {
  29. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  30. return GetNodeState() == NodeState::kInitializing;
  31. }
  32. bool NodeBase::CanSetAndNotifyProperty() const {
  33. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  34. return GetNodeState() == NodeState::kActiveInGraph;
  35. }
  36. void NodeBase::JoinGraph(GraphImpl* graph) {
  37. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  38. DCHECK(!graph_);
  39. DCHECK(graph->NodeInGraph(this));
  40. DCHECK_EQ(NodeState::kNotInGraph, GetNodeState());
  41. graph_ = graph;
  42. }
  43. void NodeBase::OnJoiningGraph() {
  44. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  45. DCHECK_EQ(NodeState::kInitializing, GetNodeState());
  46. // This is overridden by node impls.
  47. }
  48. void NodeBase::OnBeforeLeavingGraph() {
  49. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  50. DCHECK_EQ(NodeState::kActiveInGraph, GetNodeState());
  51. // This is overridden by node impls.
  52. }
  53. void NodeBase::LeaveGraph() {
  54. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  55. DCHECK(graph_);
  56. DCHECK(graph_->NodeInGraph(this));
  57. DCHECK_EQ(NodeState::kLeavingGraph, GetNodeState());
  58. graph_ = nullptr;
  59. }
  60. } // namespace performance_manager