| 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/memory_pressure_monitor.h" | 9 #include "base/memory/memory_pressure_monitor.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 static MemoryCoordinator* GetInstance(); | 31 static MemoryCoordinator* GetInstance(); |
| 32 | 32 |
| 33 // Starts monitoring memory usage. After calling this method, memory | 33 // Starts monitoring memory usage. After calling this method, memory |
| 34 // coordinator will start dispatching state changes. | 34 // coordinator will start dispatching state changes. |
| 35 virtual void Start() {} | 35 virtual void Start() {} |
| 36 | 36 |
| 37 // Creates a handle to the provided child process. | 37 // Creates a handle to the provided child process. |
| 38 void CreateHandle(int render_process_id, | 38 void CreateHandle(int render_process_id, |
| 39 mojom::MemoryCoordinatorHandleRequest request); | 39 mojom::MemoryCoordinatorHandleRequest request); |
| 40 | 40 |
| 41 // Returns number of children. Only used for testing. | |
| 42 size_t NumChildrenForTesting(); | |
| 43 | |
| 44 // Dispatches a memory state change to the provided process. Returns true if | 41 // Dispatches a memory state change to the provided process. Returns true if |
| 45 // the process is tracked by this coordinator and successfully dispatches, | 42 // the process is tracked by this coordinator and successfully dispatches, |
| 46 // returns false otherwise. | 43 // returns false otherwise. |
| 47 bool SetChildMemoryState( | 44 bool SetChildMemoryState( |
| 48 int render_process_id, mojom::MemoryState memory_state); | 45 int render_process_id, mojom::MemoryState memory_state); |
| 49 | 46 |
| 50 // Returns the memory state of the specified render process. Returns UNKNOWN | 47 // Returns the memory state of the specified render process. Returns UNKNOWN |
| 51 // if the process is not tracked by this coordinator. | 48 // if the process is not tracked by this coordinator. |
| 52 mojom::MemoryState GetChildMemoryState(int render_process_id) const; | 49 mojom::MemoryState GetChildMemoryState(int render_process_id) const; |
| 53 | 50 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 mojom::MemoryState memory_state; | 96 mojom::MemoryState memory_state; |
| 100 std::unique_ptr<MemoryCoordinatorHandleImpl> handle; | 97 std::unique_ptr<MemoryCoordinatorHandleImpl> handle; |
| 101 }; | 98 }; |
| 102 | 99 |
| 103 // A map from process ID (RenderProcessHost::GetID()) to child process info. | 100 // A map from process ID (RenderProcessHost::GetID()) to child process info. |
| 104 using ChildInfoMap = std::map<int, ChildInfo>; | 101 using ChildInfoMap = std::map<int, ChildInfo>; |
| 105 | 102 |
| 106 ChildInfoMap& children() { return children_; } | 103 ChildInfoMap& children() { return children_; } |
| 107 | 104 |
| 108 private: | 105 private: |
| 106 #if !defined(OS_MACOSX) |
| 107 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorTest, HandleAdded); |
| 108 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorTest, CanSuspendRenderer); |
| 109 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorTest, CanThrottleRenderer); |
| 110 #endif |
| 111 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorTest, |
| 112 ChildRemovedOnConnectionError); |
| 113 |
| 114 void SetDelegateForTesting( |
| 115 std::unique_ptr<MemoryCoordinatorDelegate> delegate); |
| 116 |
| 109 // Helper function of CreateHandle and AddChildForTesting. | 117 // Helper function of CreateHandle and AddChildForTesting. |
| 110 void CreateChildInfoMapEntry( | 118 void CreateChildInfoMapEntry( |
| 111 int render_process_id, | 119 int render_process_id, |
| 112 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); | 120 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); |
| 113 | 121 |
| 114 // Tracks child processes. An entry is added when a renderer connects to | 122 // Tracks child processes. An entry is added when a renderer connects to |
| 115 // MemoryCoordinator and removed automatically when an underlying binding is | 123 // MemoryCoordinator and removed automatically when an underlying binding is |
| 116 // disconnected. | 124 // disconnected. |
| 117 ChildInfoMap children_; | 125 ChildInfoMap children_; |
| 118 | 126 |
| 119 std::unique_ptr<MemoryCoordinatorDelegate> delegate_; | 127 std::unique_ptr<MemoryCoordinatorDelegate> delegate_; |
| 120 | 128 |
| 121 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinator); | 129 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinator); |
| 122 }; | 130 }; |
| 123 | 131 |
| 124 } // namespace content | 132 } // namespace content |
| 125 | 133 |
| 126 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ | 134 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ |
| OLD | NEW |