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 // 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, RUNNING => RUNNING | |
| 269 // - When ActiveTabChaged, the newly activted tab's state will be RUNNING. | |
|
haraken
2016/10/20 16:52:16
activated
| |
| 270 enum PurgeAndSuspendState { | |
| 271 RUNNING, | |
| 272 RESUMED, | |
| 273 SUSPENDED, | |
| 274 }; | |
| 275 // Determines whether to update purge-and-suspend state and returns the | |
| 276 // next state. | |
| 277 bool ShouldUpdatePurgeAndSuspendState( | |
| 278 const base::TimeTicks& current_time, | |
| 279 const TabStats& tab, | |
| 280 const base::TimeDelta& purge_and_suspend_threshold, | |
| 281 PurgeAndSuspendState* next_state); | |
| 282 | |
| 250 // Purges and suspends renderers in backgrounded tabs. | 283 // Purges and suspends renderers in backgrounded tabs. |
| 251 void PurgeAndSuspendBackgroundedTabs(); | 284 void PurgeAndSuspendBackgroundedTabs(); |
| 252 | 285 |
| 253 // Does the actual discard by destroying the WebContents in |model| at |index| | 286 // 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 | 287 // and replacing it by an empty one. Returns the new WebContents or NULL if |
| 255 // the operation fails (return value used only in testing). | 288 // the operation fails (return value used only in testing). |
| 256 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); | 289 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); |
| 257 | 290 |
| 258 // Called by the memory pressure listener when the memory pressure rises. | 291 // Called by the memory pressure listener when the memory pressure rises. |
| 259 void OnMemoryPressure( | 292 void OnMemoryPressure( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 415 |
| 383 // Weak pointer factory used for posting delayed tasks to task_runner_. | 416 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 384 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 417 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 385 | 418 |
| 386 DISALLOW_COPY_AND_ASSIGN(TabManager); | 419 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 387 }; | 420 }; |
| 388 | 421 |
| 389 } // namespace memory | 422 } // namespace memory |
| 390 | 423 |
| 391 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 424 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |