| 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" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/common/memory_coordinator.mojom.h" | 12 #include "content/common/memory_coordinator.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 // NOTE: Memory coordinator is under development and not fully working. | 17 // NOTE: Memory coordinator is under development and not fully working. |
| 18 // TODO(bashi): Add more explanations when we implement memory coordinator V0. | 18 // TODO(bashi): Add more explanations when we implement memory coordinator V0. |
| 19 | 19 |
| 20 class MemoryCoordinatorHandleImpl; | 20 class MemoryCoordinatorHandleImpl; |
| 21 | 21 |
| 22 // MemoryCoordinator is responsible for the whole memory management accross the | 22 // MemoryCoordinator is responsible for the whole memory management accross the |
| 23 // browser and child proceeses. It dispatches memory events to its clients and | 23 // browser and child proceeses. It dispatches memory events to its clients and |
| 24 // child processes based on its best knowledge of the memory usage. | 24 // child processes based on its best knowledge of the memory usage. |
| 25 class CONTENT_EXPORT MemoryCoordinator { | 25 class CONTENT_EXPORT MemoryCoordinator { |
| 26 public: | 26 public: |
| 27 ~MemoryCoordinator(); | 27 ~MemoryCoordinator(); |
| 28 | 28 |
| 29 // Returns true when memory coordinator is enabled. |
| 30 static bool IsEnabled(); |
| 31 |
| 29 // Singleton factory/accessor. | 32 // Singleton factory/accessor. |
| 30 static MemoryCoordinator* GetInstance(); | 33 static MemoryCoordinator* GetInstance(); |
| 31 | 34 |
| 32 // Creates a handle to the provided child process. | 35 // Creates a handle to the provided child process. |
| 33 void CreateHandle(int render_process_id, | 36 void CreateHandle(int render_process_id, |
| 34 mojom::MemoryCoordinatorHandleRequest request); | 37 mojom::MemoryCoordinatorHandleRequest request); |
| 35 | 38 |
| 36 // Returns number of children. Only used for testing. | 39 // Returns number of children. Only used for testing. |
| 37 size_t NumChildrenForTesting(); | 40 size_t NumChildrenForTesting(); |
| 38 | 41 |
| 39 // Dispatches a memory state change to the provided process. Returns true if | 42 // Dispatches a memory state change to the provided process. Returns true if |
| 40 // the process is tracked by this coordinator and successfully dispatches, | 43 // the process is tracked by this coordinator and successfully dispatches, |
| 41 // returns false otherwise. | 44 // returns false otherwise. |
| 42 bool SetMemoryState( | 45 bool SetMemoryState( |
| 43 int render_process_id, mojom::MemoryState memory_state); | 46 int render_process_id, mojom::MemoryState memory_state); |
| 44 | 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 // Purges and suspends a child. This is an experimental mechanism and |
| 53 // should not be exposed as an API. Returns true when memory coordinator |
| 54 // sends a request to purge and suspend to the child process. |
| 55 bool PurgeAndSuspendChild(int render_process_id); |
| 56 |
| 49 protected: | 57 protected: |
| 50 // Constructor. Protected as this is a singleton, but accessible for | 58 // Constructor. Protected as this is a singleton, but accessible for |
| 51 // unittests. | 59 // unittests. |
| 52 MemoryCoordinator(); | 60 MemoryCoordinator(); |
| 53 | 61 |
| 54 // Adds the given ChildMemoryCoordinator as a child of this coordinator. | 62 // Adds the given ChildMemoryCoordinator as a child of this coordinator. |
| 55 void AddChildForTesting(int dummy_render_process_id, | 63 void AddChildForTesting(int dummy_render_process_id, |
| 56 mojom::ChildMemoryCoordinatorPtr child); | 64 mojom::ChildMemoryCoordinatorPtr child); |
| 57 | 65 |
| 58 // Callback invoked by mojo when the child connection goes down. Exposed | 66 // Callback invoked by mojo when the child connection goes down. Exposed |
| (...skipping 26 matching lines...) Expand all Loading... |
| 85 // MemoryCoordinator and removed automatically when an underlying binding is | 93 // MemoryCoordinator and removed automatically when an underlying binding is |
| 86 // disconnected. | 94 // disconnected. |
| 87 ChildInfoMap children_; | 95 ChildInfoMap children_; |
| 88 | 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 |