| 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 #include "chrome/browser/memory/oom_priority_manager.h" | 5 #include "chrome/browser/memory/oom_priority_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 145 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 146 TabStatsList stats_list; | 146 TabStatsList stats_list; |
| 147 stats_list.reserve(32); // 99% of users have < 30 tabs open | 147 stats_list.reserve(32); // 99% of users have < 30 tabs open |
| 148 | 148 |
| 149 // We go through each window to get all the tabs. Depending on the platform, | 149 // We go through each window to get all the tabs. Depending on the platform, |
| 150 // windows are either native or ash or both. We want to make sure to go | 150 // windows are either native or ash or both. We want to make sure to go |
| 151 // through them all, starting with the active window first (we use | 151 // through them all, starting with the active window first (we use |
| 152 // chrome::GetActiveDesktop to get the current used type). | 152 // chrome::GetActiveDesktop to get the current used type). |
| 153 AddTabStats(BrowserList::GetInstance(chrome::GetActiveDesktop()), true, | 153 AddTabStats(BrowserList::GetInstance(chrome::GetActiveDesktop()), true, |
| 154 &stats_list); | 154 &stats_list); |
| 155 if (chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_NATIVE) { | 155 if (chrome::GetActiveDesktop() != ui::HOST_DESKTOP_TYPE_NATIVE) { |
| 156 AddTabStats(BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE), | 156 AddTabStats(BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_NATIVE), false, |
| 157 false, &stats_list); | 157 &stats_list); |
| 158 } else if (chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH) { | 158 } else if (chrome::GetActiveDesktop() != ui::HOST_DESKTOP_TYPE_ASH) { |
| 159 AddTabStats(BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH), false, | 159 AddTabStats(BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_ASH), false, |
| 160 &stats_list); | 160 &stats_list); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Sort the data we collected so that least desirable to be | 163 // Sort the data we collected so that least desirable to be |
| 164 // killed is first, most desirable is last. | 164 // killed is first, most desirable is last. |
| 165 std::sort(stats_list.begin(), stats_list.end(), CompareTabStats); | 165 std::sort(stats_list.begin(), stats_list.end(), CompareTabStats); |
| 166 return stats_list; | 166 return stats_list; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // TODO(jamescook): This should consider tabs with references to other tabs, | 169 // TODO(jamescook): This should consider tabs with references to other tabs, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 371 } |
| 372 | 372 |
| 373 // This function is called when |update_timer_| fires. It will adjust the clock | 373 // This function is called when |update_timer_| fires. It will adjust the clock |
| 374 // if needed (if we detect that the machine was asleep) and will fire the stats | 374 // if needed (if we detect that the machine was asleep) and will fire the stats |
| 375 // updating on ChromeOS via the delegate. | 375 // updating on ChromeOS via the delegate. |
| 376 void OomPriorityManager::UpdateTimerCallback() { | 376 void OomPriorityManager::UpdateTimerCallback() { |
| 377 // If we shutting down, do not do anything. | 377 // If we shutting down, do not do anything. |
| 378 if (g_browser_process->IsShuttingDown()) | 378 if (g_browser_process->IsShuttingDown()) |
| 379 return; | 379 return; |
| 380 | 380 |
| 381 if (BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH)->empty() && | 381 if (BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_ASH)->empty() && |
| 382 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty()) | 382 BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_NATIVE)->empty()) |
| 383 return; | 383 return; |
| 384 | 384 |
| 385 // Check for a discontinuity in time caused by the machine being suspended. | 385 // Check for a discontinuity in time caused by the machine being suspended. |
| 386 if (!last_adjust_time_.is_null()) { | 386 if (!last_adjust_time_.is_null()) { |
| 387 TimeDelta suspend_time = TimeTicks::Now() - last_adjust_time_; | 387 TimeDelta suspend_time = TimeTicks::Now() - last_adjust_time_; |
| 388 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { | 388 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { |
| 389 // We were probably suspended, move our event timers forward in time so | 389 // We were probably suspended, move our event timers forward in time so |
| 390 // when we subtract them out later we are counting "uptime". | 390 // when we subtract them out later we are counting "uptime". |
| 391 start_time_ += suspend_time; | 391 start_time_ += suspend_time; |
| 392 if (!last_discard_time_.is_null()) | 392 if (!last_discard_time_.is_null()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // For the moment we only do something when we reach a critical state. | 451 // For the moment we only do something when we reach a critical state. |
| 452 if (memory_pressure_level == | 452 if (memory_pressure_level == |
| 453 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 453 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 454 LogMemoryAndDiscardTab(); | 454 LogMemoryAndDiscardTab(); |
| 455 } | 455 } |
| 456 // TODO(skuhne): If more memory pressure levels are introduced, we might | 456 // TODO(skuhne): If more memory pressure levels are introduced, we might |
| 457 // consider to call PurgeBrowserMemory() before CRITICAL is reached. | 457 // consider to call PurgeBrowserMemory() before CRITICAL is reached. |
| 458 } | 458 } |
| 459 | 459 |
| 460 } // namespace memory | 460 } // namespace memory |
| OLD | NEW |