Joe Mason | 8686e70 | 2024-10-09 21:26:36 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_PERFORMANCE_MANAGER_SCENARIOS_LOADING_SCENARIO_DATA_H_ |
| 6 | #define COMPONENTS_PERFORMANCE_MANAGER_SCENARIOS_LOADING_SCENARIO_DATA_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "components/performance_manager/graph/node_inline_data.h" |
| 12 | |
| 13 | namespace performance_manager { |
| 14 | |
| 15 | class ProcessNode; |
| 16 | |
| 17 | // Counts of pages in each loading state. Per-process loading counts are stored |
| 18 | // inline in ProcessNode; global counts are stored in LoadingScenarioObserver. |
| 19 | class LoadingScenarioCounts : public NodeInlineData<LoadingScenarioCounts> { |
| 20 | public: |
| 21 | LoadingScenarioCounts() = default; |
| 22 | ~LoadingScenarioCounts() = default; |
| 23 | |
| 24 | // Move-only. |
| 25 | LoadingScenarioCounts(const LoadingScenarioCounts&) = delete; |
| 26 | LoadingScenarioCounts& operator=(const LoadingScenarioCounts&) = delete; |
| 27 | LoadingScenarioCounts(LoadingScenarioCounts&&) = default; |
| 28 | LoadingScenarioCounts& operator=(LoadingScenarioCounts&&) = default; |
| 29 | |
| 30 | // Focused pages that are loading. |
| 31 | size_t focused_loading_pages() const { return focused_loading_pages_; } |
| 32 | |
| 33 | // Visible pages (including focused) that are loading. |
| 34 | size_t visible_loading_pages() const { return visible_loading_pages_; } |
| 35 | |
| 36 | // All pages (including focused and visible) that are loading. |
| 37 | size_t loading_pages() const { return loading_pages_; } |
| 38 | |
| 39 | void IncrementLoadingPageCounts(bool visible, bool focused); |
| 40 | void DecrementLoadingPageCounts(bool visible, bool focused); |
| 41 | |
| 42 | private: |
| 43 | size_t focused_loading_pages_ = 0; |
| 44 | size_t visible_loading_pages_ = 0; |
| 45 | size_t loading_pages_ = 0; |
| 46 | }; |
| 47 | |
| 48 | // A cache of the number of frames hosted in each process in a page. Used to |
| 49 | // detect when the last frame in a given process is removed from the page. |
| 50 | // Stored inline in PageNode. |
| 51 | class LoadingScenarioPageFrameCounts |
| 52 | : public NodeInlineData<LoadingScenarioPageFrameCounts> { |
| 53 | public: |
| 54 | LoadingScenarioPageFrameCounts(); |
| 55 | ~LoadingScenarioPageFrameCounts(); |
| 56 | |
| 57 | // Move-only. |
| 58 | LoadingScenarioPageFrameCounts(const LoadingScenarioPageFrameCounts&) = |
| 59 | delete; |
| 60 | LoadingScenarioPageFrameCounts& operator=( |
| 61 | const LoadingScenarioPageFrameCounts&) = delete; |
| 62 | LoadingScenarioPageFrameCounts(LoadingScenarioPageFrameCounts&&); |
| 63 | LoadingScenarioPageFrameCounts& operator=(LoadingScenarioPageFrameCounts&&); |
| 64 | |
| 65 | // Increments the number of frames in this page hosted in `process_node`, and |
| 66 | // returns the new value. |
| 67 | size_t IncrementFrameCountForProcess(const ProcessNode* process_node); |
| 68 | |
| 69 | // Decrements the number of frames in this page hosted in `process_node`, and |
| 70 | // returns the new value. |
| 71 | size_t DecrementFrameCountForProcess(const ProcessNode* process_node); |
| 72 | |
| 73 | // Returns `true` iff any frame in this page is hosted in `process_node`. |
| 74 | bool ProcessHasFramesInPage(const ProcessNode* process_node) const; |
| 75 | |
| 76 | // Returns all processes hosting at least one frame in this page. |
| 77 | std::vector<const ProcessNode*> GetProcessesWithFramesInPage() const; |
| 78 | |
| 79 | private: |
| 80 | std::map<const ProcessNode*, size_t> process_frame_counts_; |
| 81 | }; |
| 82 | |
| 83 | } // namespace performance_manager |
| 84 | |
| 85 | #endif // COMPONENTS_PERFORMANCE_MANAGER_SCENARIOS_LOADING_SCENARIO_DATA_H_ |