Chromium Code Reviews| 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/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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 // Things to collect on the browser thread (because TabStripModel isn't thread | 198 // Things to collect on the browser thread (because TabStripModel isn't thread |
| 199 // safe): | 199 // safe): |
| 200 // 1) whether or not a tab is pinned | 200 // 1) whether or not a tab is pinned |
| 201 // 2) last time a tab was selected | 201 // 2) last time a tab was selected |
| 202 // 3) is the tab currently selected | 202 // 3) is the tab currently selected |
| 203 TabStatsList TabManager::GetTabStats() { | 203 TabStatsList TabManager::GetTabStats() { |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 205 TabStatsList stats_list; | 205 TabStatsList stats_list; |
| 206 stats_list.reserve(32); // 99% of users have < 30 tabs open | 206 stats_list.reserve(32); // 99% of users have < 30 tabs open |
| 207 | 207 |
| 208 // Go through each window to get all the tabs. Depending on the platform, | 208 // Go through each window to get all the tabs. |
| 209 // windows are either native or ash or both. The goal is to make sure to go | 209 AddTabStats(BrowserList::GetInstance(), true, &stats_list); |
|
sky
2016/01/27 02:41:44
Can you remove BrowserList as an arg to AddTabStat
scottmg
2016/01/27 18:10:32
Done.
| |
| 210 // through them all, starting with the active window first (use | |
| 211 // chrome::GetActiveDesktop to get the current used type). | |
| 212 AddTabStats(BrowserList::GetInstance(chrome::GetActiveDesktop()), true, | |
| 213 &stats_list); | |
| 214 if (chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_NATIVE) { | |
| 215 AddTabStats(BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE), | |
| 216 false, &stats_list); | |
| 217 } else if (chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH) { | |
| 218 AddTabStats(BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH), false, | |
| 219 &stats_list); | |
| 220 } | |
| 221 | 210 |
| 222 // Sort the collected data so that least desirable to be killed is first, most | 211 // Sort the collected data so that least desirable to be killed is first, most |
| 223 // desirable is last. | 212 // desirable is last. |
| 224 std::sort(stats_list.begin(), stats_list.end(), CompareTabStats); | 213 std::sort(stats_list.begin(), stats_list.end(), CompareTabStats); |
| 225 return stats_list; | 214 return stats_list; |
| 226 } | 215 } |
| 227 | 216 |
| 228 bool TabManager::IsTabDiscarded(content::WebContents* contents) const { | 217 bool TabManager::IsTabDiscarded(content::WebContents* contents) const { |
| 229 return GetWebContentsData(contents)->IsDiscarded(); | 218 return GetWebContentsData(contents)->IsDiscarded(); |
| 230 } | 219 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 } | 442 } |
| 454 | 443 |
| 455 // This function is called when |update_timer_| fires. It will adjust the clock | 444 // This function is called when |update_timer_| fires. It will adjust the clock |
| 456 // if needed (if it detects that the machine was asleep) and will fire the stats | 445 // if needed (if it detects that the machine was asleep) and will fire the stats |
| 457 // updating on ChromeOS via the delegate. | 446 // updating on ChromeOS via the delegate. |
| 458 void TabManager::UpdateTimerCallback() { | 447 void TabManager::UpdateTimerCallback() { |
| 459 // If Chrome is shutting down, do not do anything. | 448 // If Chrome is shutting down, do not do anything. |
| 460 if (g_browser_process->IsShuttingDown()) | 449 if (g_browser_process->IsShuttingDown()) |
| 461 return; | 450 return; |
| 462 | 451 |
| 463 if (BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH)->empty() && | 452 if (BrowserList::GetInstance()->empty()) |
| 464 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty()) | |
| 465 return; | 453 return; |
| 466 | 454 |
| 467 // Check for a discontinuity in time caused by the machine being suspended. | 455 // Check for a discontinuity in time caused by the machine being suspended. |
| 468 if (!last_adjust_time_.is_null()) { | 456 if (!last_adjust_time_.is_null()) { |
| 469 TimeDelta suspend_time = NowTicks() - last_adjust_time_; | 457 TimeDelta suspend_time = NowTicks() - last_adjust_time_; |
| 470 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { | 458 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { |
| 471 // System was probably suspended, move the event timers forward in time so | 459 // System was probably suspended, move the event timers forward in time so |
| 472 // when they get subtracted out later, "uptime" is being counted. | 460 // when they get subtracted out later, "uptime" is being counted. |
| 473 start_time_ += suspend_time; | 461 start_time_ += suspend_time; |
| 474 if (!last_discard_time_.is_null()) | 462 if (!last_discard_time_.is_null()) |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 } | 650 } |
| 663 | 651 |
| 664 TimeTicks TabManager::NowTicks() const { | 652 TimeTicks TabManager::NowTicks() const { |
| 665 if (!test_tick_clock_) | 653 if (!test_tick_clock_) |
| 666 return TimeTicks::Now(); | 654 return TimeTicks::Now(); |
| 667 | 655 |
| 668 return test_tick_clock_->NowTicks(); | 656 return test_tick_clock_->NowTicks(); |
| 669 } | 657 } |
| 670 | 658 |
| 671 } // namespace memory | 659 } // namespace memory |
| OLD | NEW |