| 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 // Initially PurgeAndSuspendState is RUNNING. |
| 255 // RUNNING => SUSPENDED |
| 256 // - Some tab has been backgrounded for more than purge-and-suspend-time |
| 257 // seconds. |
| 258 // SUSPENDED => RESUMED |
| 259 // - A suspended tab is still suspended (i.e. last active time < last |
| 260 // purge-and-suspend modified time), and |
| 261 // - kMaxTimeRendererAllowedToBeSuspendedBeforeResume time passes since |
| 262 // since the tab was suspended. |
| 263 // RESUMED => SUSPENDED |
| 264 // - A resumed tab is still backgrounded (i.e. last active time < last |
| 265 // purge-and-suspend modified time), and |
| 266 // - kSuspendedRendererLengthOfResumption time passes since the tab was |
| 267 // resumed. |
| 268 // SUSPENDED, RESUMED => SUSPENDED |
| 269 // - Since it is difficult to capture OnProcessBackgrounded or |
| 270 // OnProcessForegrounded in TabManager, compare last active time with |
| 271 // last purge-and-suspend modified time. |
| 272 // - if last active time > last purge-and-suspend modified time, |
| 273 // the tab was foregrounded and is not suspended. |
| 274 // So we treat the state as RUNNING. |
| 275 enum PurgeAndSuspendState { |
| 276 RUNNING, |
| 277 RESUMED, |
| 278 SUSPENDED, |
| 279 }; |
| 280 // Determines whether to update purge-and-suspend state and returns the |
| 281 // next state. |
| 282 bool ShouldUpdatePurgeAndSuspendState( |
| 283 const base::TimeTicks& current_time, |
| 284 const TabStats& tab, |
| 285 const base::TimeDelta& purge_and_suspend_threshold, |
| 286 PurgeAndSuspendState* next_state); |
| 287 |
| 250 // Purges and suspends renderers in backgrounded tabs. | 288 // Purges and suspends renderers in backgrounded tabs. |
| 251 void PurgeAndSuspendBackgroundedTabs(); | 289 void PurgeAndSuspendBackgroundedTabs(); |
| 252 | 290 |
| 253 // Does the actual discard by destroying the WebContents in |model| at |index| | 291 // 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 | 292 // and replacing it by an empty one. Returns the new WebContents or NULL if |
| 255 // the operation fails (return value used only in testing). | 293 // the operation fails (return value used only in testing). |
| 256 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); | 294 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); |
| 257 | 295 |
| 258 // Called by the memory pressure listener when the memory pressure rises. | 296 // Called by the memory pressure listener when the memory pressure rises. |
| 259 void OnMemoryPressure( | 297 void OnMemoryPressure( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 420 |
| 383 // Weak pointer factory used for posting delayed tasks to task_runner_. | 421 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 384 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 422 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 385 | 423 |
| 386 DISALLOW_COPY_AND_ASSIGN(TabManager); | 424 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 387 }; | 425 }; |
| 388 | 426 |
| 389 } // namespace memory | 427 } // namespace memory |
| 390 | 428 |
| 391 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 429 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |