system_node_impl.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2018 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. #ifndef COMPONENTS_PERFORMANCE_MANAGER_GRAPH_SYSTEM_NODE_IMPL_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_GRAPH_SYSTEM_NODE_IMPL_H_
  6. #include <cstdint>
  7. #include <memory>
  8. #include "base/memory/memory_pressure_listener.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/process/process_handle.h"
  11. #include "components/performance_manager/graph/node_base.h"
  12. #include "components/performance_manager/graph/properties.h"
  13. #include "components/performance_manager/public/graph/system_node.h"
  14. namespace performance_manager {
  15. class SystemNodeImpl
  16. : public PublicNodeImpl<SystemNodeImpl, SystemNode>,
  17. public TypedNodeBase<SystemNodeImpl, SystemNode, SystemNodeObserver> {
  18. public:
  19. static constexpr NodeTypeEnum Type() { return NodeTypeEnum::kSystem; }
  20. SystemNodeImpl();
  21. SystemNodeImpl(const SystemNodeImpl&) = delete;
  22. SystemNodeImpl& operator=(const SystemNodeImpl&) = delete;
  23. ~SystemNodeImpl() override;
  24. // Implements NodeBase:
  25. void RemoveNodeAttachedData() override;
  26. // This should be called after refreshing the memory usage data of the process
  27. // nodes.
  28. void OnProcessMemoryMetricsAvailable();
  29. void OnMemoryPressureForTesting(MemoryPressureLevel new_level) {
  30. OnMemoryPressure(new_level);
  31. }
  32. base::WeakPtr<SystemNodeImpl> GetWeakPtr() {
  33. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  34. return weak_factory_.GetWeakPtr();
  35. }
  36. private:
  37. void OnMemoryPressure(MemoryPressureLevel new_level);
  38. // The memory pressure listener.
  39. std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
  40. base::WeakPtrFactory<SystemNodeImpl> weak_factory_
  41. GUARDED_BY_CONTEXT(sequence_checker_){this};
  42. };
  43. } // namespace performance_manager
  44. #endif // COMPONENTS_PERFORMANCE_MANAGER_GRAPH_SYSTEM_NODE_IMPL_H_