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_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ | 5 #ifndef CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ |
6 #define CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ | 6 #define CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/memory_coordinator_client.h" | 9 #include "base/memory/memory_coordinator_client.h" |
10 #include "content/common/child_memory_coordinator.mojom.h" | 10 #include "content/common/child_memory_coordinator.mojom.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 public: | 30 public: |
31 // Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr. | 31 // Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr. |
32 static ChildMemoryCoordinatorImpl* GetInstance(); | 32 static ChildMemoryCoordinatorImpl* GetInstance(); |
33 | 33 |
34 ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent, | 34 ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent, |
35 ChildMemoryCoordinatorDelegate* delegate); | 35 ChildMemoryCoordinatorDelegate* delegate); |
36 ~ChildMemoryCoordinatorImpl() override; | 36 ~ChildMemoryCoordinatorImpl() override; |
37 | 37 |
38 // mojom::ChildMemoryCoordinator implementations: | 38 // mojom::ChildMemoryCoordinator implementations: |
39 void OnStateChange(mojom::MemoryState state) override; | 39 void OnStateChange(mojom::MemoryState state) override; |
| 40 void SetRemainingGlobalBudget(int64_t remaining_global_budget_mb) override; |
| 41 |
| 42 // Returns the current memory state of this process. |
| 43 mojom::MemoryState GetCurrentMemoryState() const { |
| 44 return state_; |
| 45 } |
| 46 |
| 47 // Returns the remaining global budget usable in aggregate by all Chrome |
| 48 // processes. This indicates how many MB of memory are remaining for Chrome |
| 49 // processes to use before the memory coordinator will take efforts to reclaim |
| 50 // memory. A negative amount indicates that the coordinator is actively trying |
| 51 // to reclaim that much memory. |
| 52 int64_t GetRemainingGlobalBudget() const { |
| 53 return remaining_global_budget_mb_; |
| 54 } |
40 | 55 |
41 protected: | 56 protected: |
42 ChildMemoryCoordinatorDelegate* delegate() { return delegate_; } | 57 ChildMemoryCoordinatorDelegate* delegate() { return delegate_; } |
43 | 58 |
44 private: | 59 private: |
45 friend class ChildMemoryCoordinatorImplTest; | 60 friend class ChildMemoryCoordinatorImplTest; |
46 | 61 |
47 mojo::Binding<mojom::ChildMemoryCoordinator> binding_; | 62 mojo::Binding<mojom::ChildMemoryCoordinator> binding_; |
48 mojom::MemoryCoordinatorHandlePtr parent_; | 63 mojom::MemoryCoordinatorHandlePtr parent_; |
49 ChildMemoryCoordinatorDelegate* delegate_; | 64 ChildMemoryCoordinatorDelegate* delegate_; |
50 | 65 |
| 66 mojom::MemoryState state_; |
| 67 int64_t remaining_global_budget_mb_; |
| 68 |
51 DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImpl); | 69 DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImpl); |
52 }; | 70 }; |
53 | 71 |
54 // Factory function for creating a ChildMemoryCoordinator for the current | 72 // Factory function for creating a ChildMemoryCoordinator for the current |
55 // platform. Doesn't take the ownership of |delegate|. | 73 // platform. Doesn't take the ownership of |delegate|. |
56 CONTENT_EXPORT std::unique_ptr<ChildMemoryCoordinatorImpl> | 74 CONTENT_EXPORT std::unique_ptr<ChildMemoryCoordinatorImpl> |
57 CreateChildMemoryCoordinator(mojom::MemoryCoordinatorHandlePtr parent, | 75 CreateChildMemoryCoordinator(mojom::MemoryCoordinatorHandlePtr parent, |
58 ChildMemoryCoordinatorDelegate* delegate); | 76 ChildMemoryCoordinatorDelegate* delegate); |
59 | 77 |
60 } // namespace content | 78 } // namespace content |
61 | 79 |
62 #endif // CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ | 80 #endif // CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ |
OLD | NEW |