Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/browser/memory/tab_manager.h

Issue 1400823003: Creates BrowserTabStripTracker to consolidate common code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback and git cl format Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/memory_pressure_listener.h" 13 #include "base/memory/memory_pressure_listener.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "chrome/browser/memory/tab_stats.h" 17 #include "chrome/browser/memory/tab_stats.h"
18 #include "chrome/browser/ui/browser_list_observer.h" 18 #include "chrome/browser/ui/browser_tab_strip_tracker.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
20 20
21 class BrowserList; 21 class BrowserList;
22 class GURL; 22 class GURL;
23 23
24 namespace memory { 24 namespace memory {
25 25
26 #if defined(OS_CHROMEOS) 26 #if defined(OS_CHROMEOS)
27 class TabManagerDelegate; 27 class TabManagerDelegate;
28 #endif 28 #endif
29 29
30 // The TabManager periodically updates (see 30 // The TabManager periodically updates (see
31 // |kAdjustmentIntervalSeconds| in the source) the status of renderers 31 // |kAdjustmentIntervalSeconds| in the source) the status of renderers
32 // which are then used by the algorithm embedded here for priority in being 32 // which are then used by the algorithm embedded here for priority in being
33 // killed upon OOM conditions. 33 // killed upon OOM conditions.
34 // 34 //
35 // The algorithm used favors killing tabs that are not selected, not pinned, 35 // The algorithm used favors killing tabs that are not selected, not pinned,
36 // and have been idle for longest, in that order of priority. 36 // and have been idle for longest, in that order of priority.
37 // 37 //
38 // On Chrome OS (via the delegate), the kernel (via /proc/<pid>/oom_score_adj) 38 // On Chrome OS (via the delegate), the kernel (via /proc/<pid>/oom_score_adj)
39 // will be informed of each renderer's score, which is based on the status, so 39 // will be informed of each renderer's score, which is based on the status, so
40 // in case Chrome is not able to relieve the pressure quickly enough and the 40 // in case Chrome is not able to relieve the pressure quickly enough and the
41 // kernel is forced to kill processes, it will be able to do so using the same 41 // kernel is forced to kill processes, it will be able to do so using the same
42 // algorithm as the one used here. 42 // algorithm as the one used here.
43 // 43 //
44 // Note that the browser tests are only active for platforms that use 44 // Note that the browser tests are only active for platforms that use
45 // TabManager (CrOS only for now) and need to be adjusted accordingly if 45 // TabManager (CrOS only for now) and need to be adjusted accordingly if
46 // support for new platforms is added. 46 // support for new platforms is added.
47 class TabManager : public chrome::BrowserListObserver, 47 class TabManager : public TabStripModelObserver {
48 public TabStripModelObserver {
49 public: 48 public:
50 TabManager(); 49 TabManager();
51 ~TabManager() override; 50 ~TabManager() override;
52 51
53 // Number of discard events since Chrome started. 52 // Number of discard events since Chrome started.
54 int discard_count() const { return discard_count_; } 53 int discard_count() const { return discard_count_; }
55 54
56 // See member comment. 55 // See member comment.
57 bool recent_tab_discard() const { return recent_tab_discard_; } 56 bool recent_tab_discard() const { return recent_tab_discard_; }
58 57
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 119
121 // Goes through a list of checks to see if a tab is allowed to be discarded by 120 // Goes through a list of checks to see if a tab is allowed to be discarded by
122 // the automatic tab discarding mechanism. Note that this is not used when 121 // the automatic tab discarding mechanism. Note that this is not used when
123 // discarding a particular tab from about:discards. 122 // discarding a particular tab from about:discards.
124 bool CanDiscardTab(int64 target_web_contents_id) const; 123 bool CanDiscardTab(int64 target_web_contents_id) const;
125 124
126 // Called by the memory pressure listener when the memory pressure rises. 125 // Called by the memory pressure listener when the memory pressure rises.
127 void OnMemoryPressure( 126 void OnMemoryPressure(
128 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); 127 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
129 128
130 // chrome::BrowserListObserver overrides.
131 void OnBrowserAdded(Browser* browser) override;
132 void OnBrowserRemoved(Browser* browser) override;
133
134 // TabStripModelObserver overrides. 129 // TabStripModelObserver overrides.
135 void TabChangedAt(content::WebContents* contents, 130 void TabChangedAt(content::WebContents* contents,
136 int index, 131 int index,
137 TabChangeType change_type) override; 132 TabChangeType change_type) override;
138 133
139 // Returns true if the tab is currently playing audio or has played audio 134 // Returns true if the tab is currently playing audio or has played audio
140 // recently. 135 // recently.
141 bool IsAudioTab(content::WebContents* contents) const; 136 bool IsAudioTab(content::WebContents* contents) const;
142 137
143 // Returns true if |first| is considered less desirable to be killed than 138 // Returns true if |first| is considered less desirable to be killed than
(...skipping 28 matching lines...) Expand all
172 // used for statistics normalized by usage. 167 // used for statistics normalized by usage.
173 bool recent_tab_discard_; 168 bool recent_tab_discard_;
174 169
175 // Whether we ever only discard a tab once. 170 // Whether we ever only discard a tab once.
176 bool discard_once_; 171 bool discard_once_;
177 172
178 #if defined(OS_CHROMEOS) 173 #if defined(OS_CHROMEOS)
179 scoped_ptr<TabManagerDelegate> delegate_; 174 scoped_ptr<TabManagerDelegate> delegate_;
180 #endif 175 #endif
181 176
177 BrowserTabStripTracker browser_tab_strip_tracker_;
178
182 DISALLOW_COPY_AND_ASSIGN(TabManager); 179 DISALLOW_COPY_AND_ASSIGN(TabManager);
183 }; 180 };
184 181
185 } // namespace memory 182 } // namespace memory
186 183
187 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ 184 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_navigation/web_navigation_api.cc ('k') | chrome/browser/memory/tab_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698