| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ |
| 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ | 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ |
| 7 | 7 |
| 8 #include "base/memory/memory_coordinator_client_registry.h" | 8 #include "base/memory/memory_coordinator_client_registry.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // Returns number of children. Only used for testing. | 36 // Returns number of children. Only used for testing. |
| 37 size_t NumChildrenForTesting(); | 37 size_t NumChildrenForTesting(); |
| 38 | 38 |
| 39 // Dispatches a memory state change to the provided process. Returns true if | 39 // Dispatches a memory state change to the provided process. Returns true if |
| 40 // the process is tracked by this coordinator and successfully dispatches, | 40 // the process is tracked by this coordinator and successfully dispatches, |
| 41 // returns false otherwise. | 41 // returns false otherwise. |
| 42 bool SetMemoryState( | 42 bool SetMemoryState( |
| 43 int render_process_id, mojom::MemoryState memory_state); | 43 int render_process_id, mojom::MemoryState memory_state); |
| 44 | 44 |
| 45 // Dispatches a memory state change to registered MemoryCoordinatorClients. |
| 46 void SetClientMemoryState(base::MemoryState memory_state); |
| 47 |
| 45 // Returns the memory state of the specified render process. Returns UNKNOWN | 48 // Returns the memory state of the specified render process. Returns UNKNOWN |
| 46 // if the process is not tracked by this coordinator. | 49 // if the process is not tracked by this coordinator. |
| 47 mojom::MemoryState GetMemoryState(int render_process_id) const; | 50 mojom::MemoryState GetMemoryState(int render_process_id) const; |
| 48 | 51 |
| 52 // Returns the memory state of registered MemoryCoordinatorClients. |
| 53 base::MemoryState GetClientMemoryState() const; |
| 54 |
| 49 protected: | 55 protected: |
| 50 // Constructor. Protected as this is a singleton, but accessible for | 56 // Constructor. Protected as this is a singleton, but accessible for |
| 51 // unittests. | 57 // unittests. |
| 52 MemoryCoordinator(); | 58 MemoryCoordinator(); |
| 53 | 59 |
| 54 // Adds the given ChildMemoryCoordinator as a child of this coordinator. | 60 // Adds the given ChildMemoryCoordinator as a child of this coordinator. |
| 55 void AddChildForTesting(int dummy_render_process_id, | 61 void AddChildForTesting(int dummy_render_process_id, |
| 56 mojom::ChildMemoryCoordinatorPtr child); | 62 mojom::ChildMemoryCoordinatorPtr child); |
| 57 | 63 |
| 58 // Callback invoked by mojo when the child connection goes down. Exposed | 64 // Callback invoked by mojo when the child connection goes down. Exposed |
| (...skipping 20 matching lines...) Expand all Loading... |
| 79 }; | 85 }; |
| 80 | 86 |
| 81 // A map from process ID (RenderProcessHost::GetID()) to child process info. | 87 // A map from process ID (RenderProcessHost::GetID()) to child process info. |
| 82 using ChildInfoMap = std::map<int, ChildInfo>; | 88 using ChildInfoMap = std::map<int, ChildInfo>; |
| 83 | 89 |
| 84 // Tracks child processes. An entry is added when a renderer connects to | 90 // Tracks child processes. An entry is added when a renderer connects to |
| 85 // MemoryCoordinator and removed automatically when an underlying binding is | 91 // MemoryCoordinator and removed automatically when an underlying binding is |
| 86 // disconnected. | 92 // disconnected. |
| 87 ChildInfoMap children_; | 93 ChildInfoMap children_; |
| 88 | 94 |
| 95 base::MemoryState client_memory_state_; |
| 96 |
| 89 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinator); | 97 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinator); |
| 90 }; | 98 }; |
| 91 | 99 |
| 92 } // namespace content | 100 } // namespace content |
| 93 | 101 |
| 94 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ | 102 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ |
| OLD | NEW |