| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); | 166 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); |
| 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 FRIEND_TEST_ALL_PREFIXES(TabManagerWebContentsDataTest, PurgeAndSuspendState); |
| 176 | 177 |
| 177 // This is needed so WebContentsData can call OnDiscardedStateChange. | 178 // This is needed so WebContentsData can call OnDiscardedStateChange, and |
| 178 friend class WebContensData; | 179 // can use PurgeAndSuspendState. |
| 180 friend class WebContentsData; |
| 179 | 181 |
| 180 // Called by WebContentsData whenever the discard state of a WebContents | 182 // Called by WebContentsData whenever the discard state of a WebContents |
| 181 // changes, so that observers can be informed. | 183 // changes, so that observers can be informed. |
| 182 void OnDiscardedStateChange(content::WebContents* contents, | 184 void OnDiscardedStateChange(content::WebContents* contents, |
| 183 bool is_discarded); | 185 bool is_discarded); |
| 184 | 186 |
| 185 // Called by WebContentsData whenever the auto-discardable state of a | 187 // Called by WebContentsData whenever the auto-discardable state of a |
| 186 // WebContents changes, so that observers can be informed. | 188 // WebContents changes, so that observers can be informed. |
| 187 void OnAutoDiscardableStateChange(content::WebContents* contents, | 189 void OnAutoDiscardableStateChange(content::WebContents* contents, |
| 188 bool is_auto_discardable); | 190 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. | 242 // If |active_model| is true, consider its first tab as being active. |
| 241 void AddTabStats(const TabStripModel* model, | 243 void AddTabStats(const TabStripModel* model, |
| 242 bool is_app, | 244 bool is_app, |
| 243 bool active_model, | 245 bool active_model, |
| 244 TabStatsList* stats_list); | 246 TabStatsList* stats_list); |
| 245 | 247 |
| 246 // Callback for when |update_timer_| fires. Takes care of executing the tasks | 248 // Callback for when |update_timer_| fires. Takes care of executing the tasks |
| 247 // that need to be run periodically (see comment in implementation). | 249 // that need to be run periodically (see comment in implementation). |
| 248 void UpdateTimerCallback(); | 250 void UpdateTimerCallback(); |
| 249 | 251 |
| 252 // Initially PurgeAndSuspendState is RUNNING. |
| 253 // RUNNING => SUSPENDED |
| 254 // - A tab has been backgrounded for more than purge-and-suspend-time |
| 255 // seconds. |
| 256 // SUSPENDED => RESUMED |
| 257 // - A suspended tab is still suspended (i.e. last active time < last |
| 258 // purge-and-suspend modified time), and |
| 259 // - kMaxTimeRendererAllowedToBeSuspendedBeforeResume time passes since |
| 260 // since the tab was suspended. |
| 261 // RESUMED => SUSPENDED |
| 262 // - A resumed tab is still backgrounded (i.e. last active time < last |
| 263 // purge-and-suspend modified time), and |
| 264 // - kSuspendedRendererLengthOfResumption time passes since the tab was |
| 265 // resumed. |
| 266 // SUSPENDED, RESUMED, RUNNING => RUNNING |
| 267 // - When ActiveTabChaged, the newly activated tab's state will be RUNNING. |
| 268 enum PurgeAndSuspendState { |
| 269 RUNNING, |
| 270 RESUMED, |
| 271 SUSPENDED, |
| 272 }; |
| 273 |
| 250 // Purges and suspends renderers in backgrounded tabs. | 274 // Purges and suspends renderers in backgrounded tabs. |
| 251 void PurgeAndSuspendBackgroundedTabs(); | 275 void PurgeAndSuspendBackgroundedTabs(); |
| 252 | 276 |
| 253 // Does the actual discard by destroying the WebContents in |model| at |index| | 277 // 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 | 278 // and replacing it by an empty one. Returns the new WebContents or NULL if |
| 255 // the operation fails (return value used only in testing). | 279 // the operation fails (return value used only in testing). |
| 256 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); | 280 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); |
| 257 | 281 |
| 258 // Called by the memory pressure listener when the memory pressure rises. | 282 // Called by the memory pressure listener when the memory pressure rises. |
| 259 void OnMemoryPressure( | 283 void OnMemoryPressure( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 406 |
| 383 // Weak pointer factory used for posting delayed tasks to task_runner_. | 407 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 384 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 408 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 385 | 409 |
| 386 DISALLOW_COPY_AND_ASSIGN(TabManager); | 410 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 387 }; | 411 }; |
| 388 | 412 |
| 389 } // namespace memory | 413 } // namespace memory |
| 390 | 414 |
| 391 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 415 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |