| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 // Returns true if |first| is considered less desirable to be killed than | 153 // Returns true if |first| is considered less desirable to be killed than |
| 154 // |second|. | 154 // |second|. |
| 155 static bool CompareTabStats(const TabStats& first, const TabStats& second); | 155 static bool CompareTabStats(const TabStats& first, const TabStats& second); |
| 156 | 156 |
| 157 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as | 157 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as |
| 158 // the WebContents could be deleted if the user closed the tab. | 158 // the WebContents could be deleted if the user closed the tab. |
| 159 static int64_t IdFromWebContents(content::WebContents* web_contents); | 159 static int64_t IdFromWebContents(content::WebContents* web_contents); |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, |
| 163 ActivateTabResetPurgeAndSuspendState); |
| 164 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, NextPurgeAndSuspendState); |
| 162 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); | 165 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); |
| 163 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); | 166 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); |
| 164 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); | 167 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); |
| 165 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); | 168 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); |
| 166 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); | 169 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); |
| 167 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); | 170 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); |
| 168 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); | 171 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); |
| 169 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); | 172 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); |
| 170 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); | 173 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); |
| 171 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); | 174 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // purge-and-suspend modified time), and | 266 // purge-and-suspend modified time), and |
| 264 // - kSuspendedRendererLengthOfResumption time passes since the tab was | 267 // - kSuspendedRendererLengthOfResumption time passes since the tab was |
| 265 // resumed. | 268 // resumed. |
| 266 // SUSPENDED, RESUMED, RUNNING => RUNNING | 269 // SUSPENDED, RESUMED, RUNNING => RUNNING |
| 267 // - When ActiveTabChaged, the newly activated tab's state will be RUNNING. | 270 // - When ActiveTabChaged, the newly activated tab's state will be RUNNING. |
| 268 enum PurgeAndSuspendState { | 271 enum PurgeAndSuspendState { |
| 269 RUNNING, | 272 RUNNING, |
| 270 RESUMED, | 273 RESUMED, |
| 271 SUSPENDED, | 274 SUSPENDED, |
| 272 }; | 275 }; |
| 276 // Returns WebContents whose contents id matches the given tab_contents_id. |
| 277 content::WebContents* GetWebContentsById(int64_t tab_contents_id); |
| 278 |
| 279 // Returns the next state of the purge and suspend. |
| 280 PurgeAndSuspendState GetNextPurgeAndSuspendState( |
| 281 content::WebContents* content, |
| 282 base::TimeTicks current_time, |
| 283 const base::TimeDelta& time_to_first_suspension) const; |
| 273 | 284 |
| 274 // Purges and suspends renderers in backgrounded tabs. | 285 // Purges and suspends renderers in backgrounded tabs. |
| 275 void PurgeAndSuspendBackgroundedTabs(); | 286 void PurgeAndSuspendBackgroundedTabs(); |
| 276 | 287 |
| 277 // Does the actual discard by destroying the WebContents in |model| at |index| | 288 // Does the actual discard by destroying the WebContents in |model| at |index| |
| 278 // and replacing it by an empty one. Returns the new WebContents or NULL if | 289 // and replacing it by an empty one. Returns the new WebContents or NULL if |
| 279 // the operation fails (return value used only in testing). | 290 // the operation fails (return value used only in testing). |
| 280 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); | 291 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); |
| 281 | 292 |
| 282 // Called by the memory pressure listener when the memory pressure rises. | 293 // Called by the memory pressure listener when the memory pressure rises. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 417 |
| 407 // Weak pointer factory used for posting delayed tasks to task_runner_. | 418 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 408 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 419 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 409 | 420 |
| 410 DISALLOW_COPY_AND_ASSIGN(TabManager); | 421 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 411 }; | 422 }; |
| 412 | 423 |
| 413 } // namespace memory | 424 } // namespace memory |
| 414 | 425 |
| 415 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 426 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |