| 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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // will be informed of each renderer's score, which is based on the status, so | 43 // will be informed of each renderer's score, which is based on the status, so |
| 44 // in case Chrome is not able to relieve the pressure quickly enough and the | 44 // in case Chrome is not able to relieve the pressure quickly enough and the |
| 45 // kernel is forced to kill processes, it will be able to do so using the same | 45 // kernel is forced to kill processes, it will be able to do so using the same |
| 46 // algorithm as the one used here. | 46 // algorithm as the one used here. |
| 47 // | 47 // |
| 48 // Note that the browser tests are only active for platforms that use | 48 // Note that the browser tests are only active for platforms that use |
| 49 // TabManager (CrOS only for now) and need to be adjusted accordingly if | 49 // TabManager (CrOS only for now) and need to be adjusted accordingly if |
| 50 // support for new platforms is added. | 50 // support for new platforms is added. |
| 51 class TabManager : public TabStripModelObserver { | 51 class TabManager : public TabStripModelObserver { |
| 52 public: | 52 public: |
| 53 // TODO(georgesak): Make this private once all external dependencies are | 53 // Needs to be public for DEFINE_WEB_CONTENTS_USER_DATA_KEY. |
| 54 // removed. | |
| 55 class WebContentsData; | 54 class WebContentsData; |
| 56 | 55 |
| 57 TabManager(); | 56 TabManager(); |
| 58 ~TabManager() override; | 57 ~TabManager() override; |
| 59 | 58 |
| 60 // Number of discard events since Chrome started. | 59 // Number of discard events since Chrome started. |
| 61 int discard_count() const { return discard_count_; } | 60 int discard_count() const { return discard_count_; } |
| 62 | 61 |
| 63 // See member comment. | 62 // See member comment. |
| 64 bool recent_tab_discard() const { return recent_tab_discard_; } | 63 bool recent_tab_discard() const { return recent_tab_discard_; } |
| 65 | 64 |
| 66 // If |discard_once| is set, tabs that get discarded once will never get | 65 // If |discard_once| is set, tabs that get discarded once will never get |
| 67 // discarded again. | 66 // discarded again. |
| 68 void Start(bool discard_once); | 67 void Start(bool discard_once); |
| 69 void Stop(); | 68 void Stop(); |
| 70 | 69 |
| 71 // Returns the list of the stats for all renderers. Must be called on the UI | 70 // Returns the list of the stats for all renderers. Must be called on the UI |
| 72 // thread. | 71 // thread. |
| 73 TabStatsList GetTabStats(); | 72 TabStatsList GetTabStats(); |
| 74 | 73 |
| 74 // Returns true if |contents| is currently discarded. |
| 75 bool IsTabDiscarded(content::WebContents* contents) const; |
| 76 |
| 75 // Discards a tab to free the memory occupied by its renderer. The tab still | 77 // Discards a tab to free the memory occupied by its renderer. The tab still |
| 76 // exists in the tab-strip; clicking on it will reload it. Returns true if it | 78 // exists in the tab-strip; clicking on it will reload it. Returns true if it |
| 77 // successfully found a tab and discarded it. | 79 // successfully found a tab and discarded it. |
| 78 bool DiscardTab(); | 80 bool DiscardTab(); |
| 79 | 81 |
| 80 // Discards a tab with the given unique ID. The tab still exists in the | 82 // Discards a tab with the given unique ID. The tab still exists in the |
| 81 // tab-strip; clicking on it will reload it. Returns true if it successfully | 83 // tab-strip; clicking on it will reload it. Returns true if it successfully |
| 82 // found a tab and discarded it. | 84 // found a tab and discarded it. |
| 83 content::WebContents* DiscardTabById(int64 target_web_contents_id); | 85 content::WebContents* DiscardTabById(int64 target_web_contents_id); |
| 84 | 86 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); | 142 content::WebContents* DiscardWebContentsAt(int index, TabStripModel* model); |
| 141 | 143 |
| 142 // Called by the memory pressure listener when the memory pressure rises. | 144 // Called by the memory pressure listener when the memory pressure rises. |
| 143 void OnMemoryPressure( | 145 void OnMemoryPressure( |
| 144 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); | 146 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
| 145 | 147 |
| 146 // TabStripModelObserver overrides. | 148 // TabStripModelObserver overrides. |
| 147 void TabChangedAt(content::WebContents* contents, | 149 void TabChangedAt(content::WebContents* contents, |
| 148 int index, | 150 int index, |
| 149 TabChangeType change_type) override; | 151 TabChangeType change_type) override; |
| 152 void ActiveTabChanged(content::WebContents* old_contents, |
| 153 content::WebContents* new_contents, |
| 154 int index, |
| 155 int reason) override; |
| 150 | 156 |
| 151 // Returns true if the tab is currently playing audio or has played audio | 157 // Returns true if the tab is currently playing audio or has played audio |
| 152 // recently. | 158 // recently. |
| 153 bool IsAudioTab(content::WebContents* contents) const; | 159 bool IsAudioTab(content::WebContents* contents) const; |
| 154 | 160 |
| 161 // Returns the WebContentsData associated with |contents|. Also takes care of |
| 162 // creating one if needed. |
| 163 WebContentsData* GetWebContentsData(content::WebContents* contents) const; |
| 164 |
| 155 // Returns true if |first| is considered less desirable to be killed than | 165 // Returns true if |first| is considered less desirable to be killed than |
| 156 // |second|. | 166 // |second|. |
| 157 static bool CompareTabStats(TabStats first, TabStats second); | 167 static bool CompareTabStats(TabStats first, TabStats second); |
| 158 | 168 |
| 159 // Timer to periodically update the stats of the renderers. | 169 // Timer to periodically update the stats of the renderers. |
| 160 base::RepeatingTimer update_timer_; | 170 base::RepeatingTimer update_timer_; |
| 161 | 171 |
| 162 // Timer to periodically report whether a tab has been discarded since the | 172 // Timer to periodically report whether a tab has been discarded since the |
| 163 // last time the timer has fired. | 173 // last time the timer has fired. |
| 164 base::RepeatingTimer recent_tab_discard_timer_; | 174 base::RepeatingTimer recent_tab_discard_timer_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 192 #endif | 202 #endif |
| 193 | 203 |
| 194 BrowserTabStripTracker browser_tab_strip_tracker_; | 204 BrowserTabStripTracker browser_tab_strip_tracker_; |
| 195 | 205 |
| 196 DISALLOW_COPY_AND_ASSIGN(TabManager); | 206 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 197 }; | 207 }; |
| 198 | 208 |
| 199 } // namespace memory | 209 } // namespace memory |
| 200 | 210 |
| 201 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 211 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
| OLD | NEW |