| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void LogMemory(const std::string& title, const base::Closure& callback); | 117 void LogMemory(const std::string& title, const base::Closure& callback); |
| 118 | 118 |
| 119 // Used to set the test TickClock, which then gets used by NowTicks(). See | 119 // Used to set the test TickClock, which then gets used by NowTicks(). See |
| 120 // |test_tick_clock_| for more details. | 120 // |test_tick_clock_| for more details. |
| 121 void set_test_tick_clock(base::TickClock* test_tick_clock); | 121 void set_test_tick_clock(base::TickClock* test_tick_clock); |
| 122 | 122 |
| 123 // Returns the list of the stats for all renderers. Must be called on the UI | 123 // Returns the list of the stats for all renderers. Must be called on the UI |
| 124 // thread. | 124 // thread. |
| 125 TabStatsList GetUnsortedTabStats(); | 125 TabStatsList GetUnsortedTabStats(); |
| 126 | 126 |
| 127 // Add/remove observers. | |
| 128 void AddObserver(TabManagerObserver* observer); | 127 void AddObserver(TabManagerObserver* observer); |
| 129 void RemoveObserver(TabManagerObserver* observer); | 128 void RemoveObserver(TabManagerObserver* observer); |
| 130 | 129 |
| 131 // Returns the auto-discardable state of the tab. When true, the tab is | 130 // Returns the auto-discardable state of the tab. When true, the tab is |
| 132 // eligible to be automatically discarded when critical memory pressure hits, | 131 // eligible to be automatically discarded when critical memory pressure hits, |
| 133 // otherwise the tab is ignored and will never be automatically discarded. | 132 // otherwise the tab is ignored and will never be automatically discarded. |
| 134 // Note that this property doesn't block the discarding of the tab via other | 133 // Note that this property doesn't block the discarding of the tab via other |
| 135 // methods (about:discards for instance). | 134 // methods (about:discards for instance). |
| 136 bool IsTabAutoDiscardable(content::WebContents* contents) const; | 135 bool IsTabAutoDiscardable(content::WebContents* contents) const; |
| 137 | 136 |
| 138 // Sets/clears the auto-discardable state of the tab. | 137 // Sets/clears the auto-discardable state of the tab. |
| 139 void SetTabAutoDiscardableState(content::WebContents* contents, bool state); | 138 void SetTabAutoDiscardableState(content::WebContents* contents, bool state); |
| 140 | 139 |
| 140 // Returns true if |first| is considered less desirable to be killed than |
| 141 // |second|. |
| 142 static bool CompareTabStats(const TabStats& first, const TabStats& second); |
| 143 |
| 141 private: | 144 private: |
| 142 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); | 145 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); |
| 143 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); | 146 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); |
| 144 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); | 147 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); |
| 145 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); | 148 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); |
| 146 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); | 149 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); |
| 147 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); | 150 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); |
| 148 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); | 151 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); |
| 149 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); | 152 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); |
| 150 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); | 153 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 256 |
| 254 // Returns true if the tab is currently playing audio or has played audio | 257 // Returns true if the tab is currently playing audio or has played audio |
| 255 // recently, or if the tab is currently accessing the camera, microphone or | 258 // recently, or if the tab is currently accessing the camera, microphone or |
| 256 // mirroring the display. | 259 // mirroring the display. |
| 257 bool IsMediaTab(content::WebContents* contents) const; | 260 bool IsMediaTab(content::WebContents* contents) const; |
| 258 | 261 |
| 259 // Returns the WebContentsData associated with |contents|. Also takes care of | 262 // Returns the WebContentsData associated with |contents|. Also takes care of |
| 260 // creating one if needed. | 263 // creating one if needed. |
| 261 WebContentsData* GetWebContentsData(content::WebContents* contents) const; | 264 WebContentsData* GetWebContentsData(content::WebContents* contents) const; |
| 262 | 265 |
| 263 // Returns true if |first| is considered less desirable to be killed than | |
| 264 // |second|. | |
| 265 static bool CompareTabStats(TabStats first, TabStats second); | |
| 266 | |
| 267 // Returns either the system's clock or the test clock. See |test_tick_clock_| | 266 // Returns either the system's clock or the test clock. See |test_tick_clock_| |
| 268 // for more details. | 267 // for more details. |
| 269 base::TimeTicks NowTicks() const; | 268 base::TimeTicks NowTicks() const; |
| 270 | 269 |
| 271 // Dispatches a memory pressure message to a single child process, and | 270 // Dispatches a memory pressure message to a single child process, and |
| 272 // schedules another call to itself as long as memory pressure continues. | 271 // schedules another call to itself as long as memory pressure continues. |
| 273 void DoChildProcessDispatch(); | 272 void DoChildProcessDispatch(); |
| 274 | 273 |
| 275 // Implementation of DiscardTab. | 274 // Implementation of DiscardTab. |
| 276 bool DiscardTabImpl(); | 275 bool DiscardTabImpl(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 363 |
| 365 // Weak pointer factory used for posting delayed tasks to task_runner_. | 364 // Weak pointer factory used for posting delayed tasks to task_runner_. |
| 366 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 365 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 367 | 366 |
| 368 DISALLOW_COPY_AND_ASSIGN(TabManager); | 367 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 369 }; | 368 }; |
| 370 | 369 |
| 371 } // namespace memory | 370 } // namespace memory |
| 372 | 371 |
| 373 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 372 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |