Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| 6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 // The TabManager periodically updates (see | 49 // The TabManager periodically updates (see |
| 50 // |kAdjustmentIntervalSeconds| in the source) the status of renderers | 50 // |kAdjustmentIntervalSeconds| in the source) the status of renderers |
| 51 // which are then used by the algorithm embedded here for priority in being | 51 // which are then used by the algorithm embedded here for priority in being |
| 52 // killed upon OOM conditions. | 52 // killed upon OOM conditions. |
| 53 // | 53 // |
| 54 // The algorithm used favors killing tabs that are not selected, not pinned, | 54 // The algorithm used favors killing tabs that are not selected, not pinned, |
| 55 // and have been idle for longest, in that order of priority. | 55 // and have been idle for longest, in that order of priority. |
| 56 // | 56 // |
| 57 // On Chrome OS (via the delegate), the kernel (via /proc/<pid>/oom_score_adj) | 57 // On Chrome OS (via the delegate), the kernel (via /proc/<pid>/oom_score_adj) |
|
Georges Khalil
2016/04/19 13:55:19
Add a mention here about what we do on Android.
| |
| 58 // will be informed of each renderer's score, which is based on the status, so | 58 // will be informed of each renderer's score, which is based on the status, so |
| 59 // in case Chrome is not able to relieve the pressure quickly enough and the | 59 // in case Chrome is not able to relieve the pressure quickly enough and the |
| 60 // kernel is forced to kill processes, it will be able to do so using the same | 60 // kernel is forced to kill processes, it will be able to do so using the same |
| 61 // algorithm as the one used here. | 61 // algorithm as the one used here. |
| 62 // | 62 // |
| 63 // Note that the browser tests are only active for platforms that use | 63 // Note that the browser tests are only active for platforms that use |
| 64 // TabManager (CrOS only for now) and need to be adjusted accordingly if | 64 // TabManager (CrOS only for now) and need to be adjusted accordingly if |
| 65 // support for new platforms is added. | 65 // support for new platforms is added. |
| 66 class TabManager : public TabStripModelObserver { | 66 class TabManager : public TabStripModelObserver { |
| 67 public: | 67 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 // NOTE: This value needs to be big enough to allow a process to get over the | 138 // NOTE: This value needs to be big enough to allow a process to get over the |
| 139 // hump in responding to memory pressure, so there aren't multiple processes | 139 // hump in responding to memory pressure, so there aren't multiple processes |
| 140 // fighting for CPU and worse, temporary memory, while trying to free things | 140 // fighting for CPU and worse, temporary memory, while trying to free things |
| 141 // up. Similarly, it shouldn't be too large otherwise it will take too long | 141 // up. Similarly, it shouldn't be too large otherwise it will take too long |
| 142 // for the entire system to respond. Ideally, there would be a callback from a | 142 // for the entire system to respond. Ideally, there would be a callback from a |
| 143 // child process indicating that the message has been handled. In the meantime | 143 // child process indicating that the message has been handled. In the meantime |
| 144 // this is chosen to be sufficient to allow a worst-case V8+Oilpan GC to run, | 144 // this is chosen to be sufficient to allow a worst-case V8+Oilpan GC to run, |
| 145 // with a little slop. | 145 // with a little slop. |
| 146 enum : int { kRendererNotificationDelayInSeconds = 2 }; | 146 enum : int { kRendererNotificationDelayInSeconds = 2 }; |
| 147 | 147 |
| 148 enum : int { kSuspendTimersWhenBackgroundedDelayInSeconds = 5 * 60 }; | |
| 149 | |
| 148 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; | 150 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; |
| 149 | 151 |
| 150 // A callback that returns the current memory pressure level. | 152 // A callback that returns the current memory pressure level. |
| 151 using MemoryPressureLevelCallback = base::Callback<MemoryPressureLevel()>; | 153 using MemoryPressureLevelCallback = base::Callback<MemoryPressureLevel()>; |
| 152 | 154 |
| 153 // Callback that notifies a |renderer| of the memory pressure at a given | 155 // Callback that notifies a |renderer| of the memory pressure at a given |
| 154 // |level|. Provides a testing seam. | 156 // |level|. Provides a testing seam. |
| 155 using RendererNotificationCallback = base::Callback< | 157 using RendererNotificationCallback = base::Callback< |
| 156 void(const content::RenderProcessHost* /* renderer */, | 158 void(const content::RenderProcessHost* /* renderer */, |
| 157 MemoryPressureLevel /* level */)>; | 159 MemoryPressureLevel /* level */)>; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 | 325 |
| 324 // Weak pointer factory used for posting delayed tasks to task_runner_. | 326 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 325 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 327 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 326 | 328 |
| 327 DISALLOW_COPY_AND_ASSIGN(TabManager); | 329 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 328 }; | 330 }; |
| 329 | 331 |
| 330 } // namespace memory | 332 } // namespace memory |
| 331 | 333 |
| 332 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 334 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |