| 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 "content/public/browser/memory_coordinator_delegate.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 // NOTE: Memory coordinator is under development and not fully working. | 18 // NOTE: Memory coordinator is under development and not fully working. |
| 18 // TODO(bashi): Add more explanations when we implement memory coordinator V0. | 19 // TODO(bashi): Add more explanations when we implement memory coordinator V0. |
| 19 | 20 |
| 20 class MemoryCoordinatorHandleImpl; | 21 class MemoryCoordinatorHandleImpl; |
| 21 | 22 |
| 22 // MemoryCoordinator is responsible for the whole memory management accross the | 23 // MemoryCoordinator is responsible for the whole memory management accross the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 MemoryCoordinator(); | 53 MemoryCoordinator(); |
| 53 | 54 |
| 54 // Adds the given ChildMemoryCoordinator as a child of this coordinator. | 55 // Adds the given ChildMemoryCoordinator as a child of this coordinator. |
| 55 void AddChildForTesting(int dummy_render_process_id, | 56 void AddChildForTesting(int dummy_render_process_id, |
| 56 mojom::ChildMemoryCoordinatorPtr child); | 57 mojom::ChildMemoryCoordinatorPtr child); |
| 57 | 58 |
| 58 // Callback invoked by mojo when the child connection goes down. Exposed | 59 // Callback invoked by mojo when the child connection goes down. Exposed |
| 59 // for testing. | 60 // for testing. |
| 60 void OnConnectionError(int render_process_id); | 61 void OnConnectionError(int render_process_id); |
| 61 | 62 |
| 63 // Returns true when a given renderer can be suspended. |
| 64 bool CanSuspendRenderer(int render_process_id); |
| 65 |
| 62 private: | 66 private: |
| 63 friend struct base::DefaultSingletonTraits<MemoryCoordinator>; | 67 friend struct base::DefaultSingletonTraits<MemoryCoordinator>; |
| 64 | 68 |
| 65 // Helper function of CreateHandle and AddChildForTesting. | 69 // Helper function of CreateHandle and AddChildForTesting. |
| 66 void CreateChildInfoMapEntry( | 70 void CreateChildInfoMapEntry( |
| 67 int render_process_id, | 71 int render_process_id, |
| 68 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); | 72 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); |
| 69 | 73 |
| 70 // Stores information about any known child processes. | 74 // Stores information about any known child processes. |
| 71 struct ChildInfo { | 75 struct ChildInfo { |
| 72 // This object must be compatible with STL containers. | 76 // This object must be compatible with STL containers. |
| 73 ChildInfo(); | 77 ChildInfo(); |
| 74 ChildInfo(const ChildInfo& rhs); | 78 ChildInfo(const ChildInfo& rhs); |
| 75 ~ChildInfo(); | 79 ~ChildInfo(); |
| 76 | 80 |
| 77 mojom::MemoryState memory_state; | 81 mojom::MemoryState memory_state; |
| 78 std::unique_ptr<MemoryCoordinatorHandleImpl> handle; | 82 std::unique_ptr<MemoryCoordinatorHandleImpl> handle; |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 // A map from process ID (RenderProcessHost::GetID()) to child process info. | 85 // A map from process ID (RenderProcessHost::GetID()) to child process info. |
| 82 using ChildInfoMap = std::map<int, ChildInfo>; | 86 using ChildInfoMap = std::map<int, ChildInfo>; |
| 83 | 87 |
| 84 // Tracks child processes. An entry is added when a renderer connects to | 88 // Tracks child processes. An entry is added when a renderer connects to |
| 85 // MemoryCoordinator and removed automatically when an underlying binding is | 89 // MemoryCoordinator and removed automatically when an underlying binding is |
| 86 // disconnected. | 90 // disconnected. |
| 87 ChildInfoMap children_; | 91 ChildInfoMap children_; |
| 88 | 92 |
| 93 std::unique_ptr<MemoryCoordinatorDelegate> delegate_; |
| 94 |
| 89 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinator); | 95 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinator); |
| 90 }; | 96 }; |
| 91 | 97 |
| 92 } // namespace content | 98 } // namespace content |
| 93 | 99 |
| 94 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ | 100 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_H_ |
| OLD | NEW |