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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 public NotificationObserver, | 40 public NotificationObserver, |
41 public base::NonThreadSafe { | 41 public base::NonThreadSafe { |
42 public: | 42 public: |
43 MemoryCoordinatorImpl(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 43 MemoryCoordinatorImpl(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
44 std::unique_ptr<MemoryMonitor> monitor); | 44 std::unique_ptr<MemoryMonitor> monitor); |
45 ~MemoryCoordinatorImpl() override; | 45 ~MemoryCoordinatorImpl() override; |
46 | 46 |
47 // MemoryCoordinator implementations: | 47 // MemoryCoordinator implementations: |
48 void Start() override; | 48 void Start() override; |
49 void OnChildAdded(int render_process_id) override; | 49 void OnChildAdded(int render_process_id) override; |
50 base::MemoryState GetCurrentMemoryState() const override; | |
51 void SetCurrentMemoryStateForTesting(base::MemoryState memory_state) override; | |
52 int64_t GetRemainingGlobalBudget() const override; | |
50 | 53 |
51 MemoryMonitor* memory_monitor() { return memory_monitor_.get(); } | 54 MemoryMonitor* memory_monitor() { return memory_monitor_.get(); } |
52 | 55 |
53 base::MemoryState GetCurrentMemoryState() const override; | |
54 void SetCurrentMemoryStateForTesting(base::MemoryState memory_state) override; | |
55 | |
56 // NotificationObserver implementation: | 56 // NotificationObserver implementation: |
57 void Observe(int type, | 57 void Observe(int type, |
58 const NotificationSource& source, | 58 const NotificationSource& source, |
59 const NotificationDetails& details) override; | 59 const NotificationDetails& details) override; |
60 | 60 |
61 private: | 61 private: |
62 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextState); | 62 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextState); |
63 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, UpdateState); | 63 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, UpdateState); |
64 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, SetMemoryStateForTesting); | 64 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, SetMemoryStateForTesting); |
65 | 65 |
66 friend struct MemoryCoordinatorSingletonTraits; | 66 friend struct MemoryCoordinatorSingletonTraits; |
67 | 67 |
68 using MemoryState = base::MemoryState; | 68 using MemoryState = base::MemoryState; |
69 | 69 |
70 // Calculates the next global state from the amount of free memory using | 70 // Calculates the next global state from the amount of free memory using |
71 // a heuristic. | 71 // a heuristic. |
72 MemoryState CalculateNextState(); | 72 MemoryState CalculateNextState(int free_memory_until_critical_mb); |
haraken
2016/11/05 12:52:21
int => int64_t ?
chrisha
2016/11/07 19:33:41
(Decided to move everything in the other direction
| |
73 | |
74 // Calculates the remaining global budget. | |
75 int64_t CalculateRemainingGlobalBudget(int free_memory_until_critical_mb); | |
73 | 76 |
74 // Updates the global state and notifies state changes to clients (lives in | 77 // Updates the global state and notifies state changes to clients (lives in |
75 // the browser) and child processes (renderers) if necessary. | 78 // the browser) and child processes (renderers) if necessary. |
76 void UpdateState(); | 79 void UpdateState(); |
77 | 80 |
78 // Notifies a state change to in-process clients. | 81 // Notifies a state change to in-process clients. |
79 void NotifyStateToClients(); | 82 void NotifyStateToClients(); |
80 | 83 |
81 // Notifies a state change to child processes. | 84 // Notifies a state change to child processes. |
82 void NotifyStateToChildren(); | 85 void NotifyStateToChildren(); |
83 | 86 |
87 // Notifies a change in remaining global budget to children. | |
88 void NotifyRemainingGlobalBudgetToChildren(); | |
89 | |
84 // Schedules a task to update the global state. The task will be executed | 90 // Schedules a task to update the global state. The task will be executed |
85 // after |delay| has passed. | 91 // after |delay| has passed. |
86 void ScheduleUpdateState(base::TimeDelta delay); | 92 void ScheduleUpdateState(base::TimeDelta delay); |
87 | 93 |
88 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 94 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
89 NotificationRegistrar notification_registrar_; | 95 NotificationRegistrar notification_registrar_; |
90 std::unique_ptr<MemoryMonitor> memory_monitor_; | 96 std::unique_ptr<MemoryMonitor> memory_monitor_; |
91 base::Closure update_state_callback_; | 97 base::Closure update_state_callback_; |
92 base::MemoryState current_state_ = MemoryState::NORMAL; | 98 base::MemoryState current_state_ = MemoryState::NORMAL; |
93 base::TimeTicks last_state_change_; | 99 base::TimeTicks last_state_change_; |
100 int64_t remaining_global_budget_mb_; | |
94 | 101 |
95 // Validates parameters defined below. | 102 // Validates parameters defined below. |
96 bool ValidateParameters(); | 103 bool ValidateParameters(); |
97 | 104 |
98 // Parameters to control the heuristic. | 105 // Parameters to control the heuristic. |
99 | 106 |
100 // The median size of a renderer on the current platform. This is used to | 107 // The median size of a renderer on the current platform. This is used to |
101 // convert the amount of free memory to an expected number of new renderers | 108 // convert the amount of free memory to an expected number of new renderers |
102 // that could be started before hitting critical memory pressure. | 109 // that could be started before hitting critical memory pressure. |
103 int expected_renderer_size_; | 110 int expected_renderer_size_; |
(...skipping 19 matching lines...) Expand all Loading... | |
123 base::TimeDelta monitoring_interval_; | 130 base::TimeDelta monitoring_interval_; |
124 | 131 |
125 base::WeakPtrFactory<MemoryCoordinatorImpl> weak_ptr_factory_; | 132 base::WeakPtrFactory<MemoryCoordinatorImpl> weak_ptr_factory_; |
126 | 133 |
127 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); | 134 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); |
128 }; | 135 }; |
129 | 136 |
130 } // namespace content | 137 } // namespace content |
131 | 138 |
132 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 139 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
OLD | NEW |