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

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

Issue 1909903002: Enable TabManager on Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/memory/tab_manager_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/memory/tab_manager.h" 5 #include "chrome/browser/memory/tab_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 using content::BrowserThread; 63 using content::BrowserThread;
64 using content::WebContents; 64 using content::WebContents;
65 65
66 namespace memory { 66 namespace memory {
67 namespace { 67 namespace {
68 68
69 // The default interval in seconds after which to adjust the oom_score_adj 69 // The default interval in seconds after which to adjust the oom_score_adj
70 // value. 70 // value.
71 const int kAdjustmentIntervalSeconds = 10; 71 const int kAdjustmentIntervalSeconds = 10;
72 72
73 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
73 // For each period of this length record a statistic to indicate whether or not 74 // For each period of this length record a statistic to indicate whether or not
74 // the user experienced a low memory event. If this interval is changed, 75 // the user experienced a low memory event. If this interval is changed,
75 // Tabs.Discard.DiscardInLastMinute must be replaced with a new statistic. 76 // Tabs.Discard.DiscardInLastMinute must be replaced with a new statistic.
76 const int kRecentTabDiscardIntervalSeconds = 60; 77 const int kRecentTabDiscardIntervalSeconds = 60;
78 #endif
77 79
78 // If there has been no priority adjustment in this interval, assume the 80 // If there has been no priority adjustment in this interval, assume the
79 // machine was suspended and correct the timing statistics. 81 // machine was suspended and correct the timing statistics.
80 const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4; 82 const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4;
81 83
82 // The time during which a tab is protected from discarding after it stops being 84 // The time during which a tab is protected from discarding after it stops being
83 // audible. 85 // audible.
84 const int kAudioProtectionTimeSeconds = 60; 86 const int kAudioProtectionTimeSeconds = 60;
85 87
86 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as 88 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // On Chrome OS, tab manager is always started and tabs can be discarded more 192 // On Chrome OS, tab manager is always started and tabs can be discarded more
191 // than once. 193 // than once.
192 discard_once_ = false; 194 discard_once_ = false;
193 #endif 195 #endif
194 196
195 if (!update_timer_.IsRunning()) { 197 if (!update_timer_.IsRunning()) {
196 update_timer_.Start(FROM_HERE, 198 update_timer_.Start(FROM_HERE,
197 TimeDelta::FromSeconds(kAdjustmentIntervalSeconds), 199 TimeDelta::FromSeconds(kAdjustmentIntervalSeconds),
198 this, &TabManager::UpdateTimerCallback); 200 this, &TabManager::UpdateTimerCallback);
199 } 201 }
202
203 // MemoryPressureMonitor is not implemented on Linux so far and tabs are never
204 // discarded.
205 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
200 if (!recent_tab_discard_timer_.IsRunning()) { 206 if (!recent_tab_discard_timer_.IsRunning()) {
201 recent_tab_discard_timer_.Start( 207 recent_tab_discard_timer_.Start(
202 FROM_HERE, TimeDelta::FromSeconds(kRecentTabDiscardIntervalSeconds), 208 FROM_HERE, TimeDelta::FromSeconds(kRecentTabDiscardIntervalSeconds),
203 this, &TabManager::RecordRecentTabDiscard); 209 this, &TabManager::RecordRecentTabDiscard);
204 } 210 }
205 start_time_ = NowTicks(); 211 start_time_ = NowTicks();
206 // Create a |MemoryPressureListener| to listen for memory events. 212 // Create a |MemoryPressureListener| to listen for memory events.
207 base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get(); 213 base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get();
208 if (monitor) { 214 if (monitor) {
209 memory_pressure_listener_.reset(new base::MemoryPressureListener( 215 memory_pressure_listener_.reset(new base::MemoryPressureListener(
210 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this)))); 216 base::Bind(&TabManager::OnMemoryPressure, base::Unretained(this))));
211 base::MemoryPressureListener::MemoryPressureLevel level = 217 base::MemoryPressureListener::MemoryPressureLevel level =
212 monitor->GetCurrentPressureLevel(); 218 monitor->GetCurrentPressureLevel();
213 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 219 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
214 OnMemoryPressure(level); 220 OnMemoryPressure(level);
215 } 221 }
216 } 222 }
223 #endif
217 } 224 }
218 225
219 void TabManager::Stop() { 226 void TabManager::Stop() {
220 update_timer_.Stop(); 227 update_timer_.Stop();
221 recent_tab_discard_timer_.Stop(); 228 recent_tab_discard_timer_.Stop();
222 memory_pressure_listener_.reset(); 229 memory_pressure_listener_.reset();
223 } 230 }
224 231
225 TabStatsList TabManager::GetTabStats() { 232 TabStatsList TabManager::GetTabStats() {
226 TabStatsList stats_list(GetUnsortedTabStats()); 233 TabStatsList stats_list(GetUnsortedTabStats());
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 847 }
841 } else { 848 } else {
842 // The code here can only be tested under a full browser test. 849 // The code here can only be tested under a full browser test.
843 AddTabStats(&stats_list); 850 AddTabStats(&stats_list);
844 } 851 }
845 852
846 return stats_list; 853 return stats_list;
847 } 854 }
848 855
849 } // namespace memory 856 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | chrome/browser/memory/tab_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698