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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void set_test_tick_clock(base::TickClock* test_tick_clock); | 121 void set_test_tick_clock(base::TickClock* test_tick_clock); |
122 | 122 |
123 // Returns the list of the stats for all renderers. Must be called on the UI | 123 // Returns the list of the stats for all renderers. Must be called on the UI |
124 // thread. | 124 // thread. |
125 TabStatsList GetUnsortedTabStats(); | 125 TabStatsList GetUnsortedTabStats(); |
126 | 126 |
127 // Add/remove observers. | 127 // Add/remove observers. |
128 void AddObserver(TabManagerObserver* observer); | 128 void AddObserver(TabManagerObserver* observer); |
129 void RemoveObserver(TabManagerObserver* observer); | 129 void RemoveObserver(TabManagerObserver* observer); |
130 | 130 |
| 131 // Returns the auto-discardable state of the tab. When true, the tab is |
| 132 // eligible to be automatically discarded when critical memory pressure hits, |
| 133 // otherwise the tab is ignored and will never be automatically discarded. |
| 134 // Note that this property doesn't block the discarding of the tab via other |
| 135 // methods (about:discards for instance). |
| 136 bool IsTabAutoDiscardable(content::WebContents* contents) const; |
| 137 |
| 138 // Sets/clears the auto-discardable state of the tab. |
| 139 void SetTabAutoDiscardableState(content::WebContents* contents, bool state); |
| 140 |
131 private: | 141 private: |
| 142 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); |
132 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); | 143 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); |
133 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); | 144 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); |
134 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); | 145 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); |
135 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); | 146 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); |
136 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); | 147 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); |
137 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); | 148 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); |
138 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); | 149 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); |
139 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); | 150 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); |
140 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); | 151 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); |
141 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectRecentlyUsedTabs); | 152 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectRecentlyUsedTabs); |
142 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectVideoTabs); | 153 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectVideoTabs); |
143 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ReloadDiscardedTabContextMenu); | 154 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ReloadDiscardedTabContextMenu); |
144 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, TabManagerBasics); | 155 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, TabManagerBasics); |
145 | 156 |
146 // This is needed so WebContentsData can call OnDiscardedStateChange. | 157 // This is needed so WebContentsData can call OnDiscardedStateChange. |
147 friend class WebContensData; | 158 friend class WebContensData; |
148 | 159 |
149 // Called by WebContentsData whenever the discard state of a WebContents | 160 // Called by WebContentsData whenever the discard state of a WebContents |
150 // changes, so that observers can be informed. | 161 // changes, so that observers can be informed. |
151 void OnDiscardedStateChange(content::WebContents* contents, | 162 void OnDiscardedStateChange(content::WebContents* contents, |
152 bool is_discarded); | 163 bool is_discarded); |
153 | 164 |
| 165 // Called by WebContentsData whenever the auto-discardable state of a |
| 166 // WebContents changes, so that observers can be informed. |
| 167 void OnAutoDiscardableStateChange(content::WebContents* contents, |
| 168 bool is_auto_discardable); |
| 169 |
154 // The time that a renderer is given to react to a memory pressure | 170 // The time that a renderer is given to react to a memory pressure |
155 // notification before another renderer is also notified. This prevents all | 171 // notification before another renderer is also notified. This prevents all |
156 // renderers from receiving and acting upon notifications simultaneously, | 172 // renderers from receiving and acting upon notifications simultaneously, |
157 // which can quickly overload a system. Exposed for unittesting. | 173 // which can quickly overload a system. Exposed for unittesting. |
158 // NOTE: This value needs to be big enough to allow a process to get over the | 174 // NOTE: This value needs to be big enough to allow a process to get over the |
159 // hump in responding to memory pressure, so there aren't multiple processes | 175 // hump in responding to memory pressure, so there aren't multiple processes |
160 // fighting for CPU and worse, temporary memory, while trying to free things | 176 // fighting for CPU and worse, temporary memory, while trying to free things |
161 // up. Similarly, it shouldn't be too large otherwise it will take too long | 177 // up. Similarly, it shouldn't be too large otherwise it will take too long |
162 // for the entire system to respond. Ideally, there would be a callback from a | 178 // for the entire system to respond. Ideally, there would be a callback from a |
163 // child process indicating that the message has been handled. In the meantime | 179 // child process indicating that the message has been handled. In the meantime |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 364 |
349 // Weak pointer factory used for posting delayed tasks to task_runner_. | 365 // Weak pointer factory used for posting delayed tasks to task_runner_. |
350 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 366 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
351 | 367 |
352 DISALLOW_COPY_AND_ASSIGN(TabManager); | 368 DISALLOW_COPY_AND_ASSIGN(TabManager); |
353 }; | 369 }; |
354 | 370 |
355 } // namespace memory | 371 } // namespace memory |
356 | 372 |
357 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 373 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
OLD | NEW |