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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); | 167 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); |
| 168 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); | 168 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); |
| 169 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); | 169 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); |
| 170 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); | 170 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); |
| 171 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); | 171 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); |
| 172 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectRecentlyUsedTabs); | 172 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectRecentlyUsedTabs); |
| 173 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectVideoTabs); | 173 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectVideoTabs); |
| 174 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ReloadDiscardedTabContextMenu); | 174 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ReloadDiscardedTabContextMenu); |
| 175 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, TabManagerBasics); | 175 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, TabManagerBasics); |
| 176 | 176 |
| 177 // This is needed so WebContentsData can call OnDiscardedStateChange. | 177 // This is needed so WebContentsData can call OnDiscardedStateChange, and |
| 178 friend class WebContensData; | 178 // can use PurgeAndSuspendState. |
| 179 friend class WebContentsData; | |
| 179 | 180 |
| 180 // Called by WebContentsData whenever the discard state of a WebContents | 181 // Called by WebContentsData whenever the discard state of a WebContents |
| 181 // changes, so that observers can be informed. | 182 // changes, so that observers can be informed. |
| 182 void OnDiscardedStateChange(content::WebContents* contents, | 183 void OnDiscardedStateChange(content::WebContents* contents, |
| 183 bool is_discarded); | 184 bool is_discarded); |
| 184 | 185 |
| 185 // Called by WebContentsData whenever the auto-discardable state of a | 186 // Called by WebContentsData whenever the auto-discardable state of a |
| 186 // WebContents changes, so that observers can be informed. | 187 // WebContents changes, so that observers can be informed. |
| 187 void OnAutoDiscardableStateChange(content::WebContents* contents, | 188 void OnAutoDiscardableStateChange(content::WebContents* contents, |
| 188 bool is_auto_discardable); | 189 bool is_auto_discardable); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 // If |active_model| is true, consider its first tab as being active. | 241 // If |active_model| is true, consider its first tab as being active. |
| 241 void AddTabStats(const TabStripModel* model, | 242 void AddTabStats(const TabStripModel* model, |
| 242 bool is_app, | 243 bool is_app, |
| 243 bool active_model, | 244 bool active_model, |
| 244 TabStatsList* stats_list); | 245 TabStatsList* stats_list); |
| 245 | 246 |
| 246 // Callback for when |update_timer_| fires. Takes care of executing the tasks | 247 // Callback for when |update_timer_| fires. Takes care of executing the tasks |
| 247 // that need to be run periodically (see comment in implementation). | 248 // that need to be run periodically (see comment in implementation). |
| 248 void UpdateTimerCallback(); | 249 void UpdateTimerCallback(); |
| 249 | 250 |
| 251 // Returns WebContents whose contents id matches the given tab-contents-id. | |
| 252 content::WebContents* GetWebContentsByContentsId(int64_t tab_contents_id); | |
| 253 | |
| 254 enum PurgeAndSuspendState { | |
|
haraken
2016/10/19 10:40:30
Add a comment about how the state transition happe
| |
| 255 BACKGROUNDED, | |
|
haraken
2016/10/19 10:40:30
I'd prefer renaming BACKGROUNDED to RUNNING (or so
tasak
2016/10/20 11:28:46
Done.
| |
| 256 RESUMED, | |
| 257 SUSPENDED, | |
| 258 }; | |
| 259 // Determines whether to update purge-and-suspend state and returns the | |
| 260 // next state. | |
| 261 bool ShouldUpdatePurgeAndSuspendState( | |
| 262 const base::TimeTicks& current_time, | |
| 263 const TabStats& tab, | |
| 264 const base::TimeDelta& purge_and_suspend_threshold, | |
| 265 PurgeAndSuspendState* next_state); | |
| 266 | |
| 250 // Purges and suspends renderers in backgrounded tabs. | 267 // Purges and suspends renderers in backgrounded tabs. |
| 251 void PurgeAndSuspendBackgroundedTabs(); | 268 void PurgeAndSuspendBackgroundedTabs(); |
| 252 | 269 |
| 253 // Does the actual discard by destroying the WebContents in |model| at |index| | 270 // Does the actual discard by destroying the WebContents in |model| at |index| |
| 254 // and replacing it by an empty one. Returns the new WebContents or NULL if | 271 // and replacing it by an empty one. Returns the new WebContents or NULL if |
| 255 // the operation fails (return value used only in testing). | 272 // the operation fails (return value used only in testing). |
| 256 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); | 273 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); |
| 257 | 274 |
| 258 // Called by the memory pressure listener when the memory pressure rises. | 275 // Called by the memory pressure listener when the memory pressure rises. |
| 259 void OnMemoryPressure( | 276 void OnMemoryPressure( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 399 |
| 383 // Weak pointer factory used for posting delayed tasks to task_runner_. | 400 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 384 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 401 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 385 | 402 |
| 386 DISALLOW_COPY_AND_ASSIGN(TabManager); | 403 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 387 }; | 404 }; |
| 388 | 405 |
| 389 } // namespace memory | 406 } // namespace memory |
| 390 | 407 |
| 391 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 408 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |