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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 stats_list); | 473 stats_list); |
474 // The active browser window is processed in the first iteration. | 474 // The active browser window is processed in the first iteration. |
475 browser_active = false; | 475 browser_active = false; |
476 } | 476 } |
477 } | 477 } |
478 | 478 |
479 void TabManager::AddTabStats(const TabStripModel* model, | 479 void TabManager::AddTabStats(const TabStripModel* model, |
480 bool is_app, | 480 bool is_app, |
481 bool active_model, | 481 bool active_model, |
482 TabStatsList* stats_list) { | 482 TabStatsList* stats_list) { |
483 for (int i = 0; i < model->count(); i++) { | 483 for (int i = 0; i < model->count(); i++) { |
484 WebContents* contents = model->GetWebContentsAt(i); | 484 WebContents* contents = model->GetWebContentsAt(i); |
485 if (!contents->IsCrashed()) { | 485 if (!contents->IsCrashed()) { |
486 TabStats stats; | 486 TabStats stats; |
487 stats.is_app = is_app; | 487 stats.is_app = is_app; |
488 stats.is_internal_page = | 488 stats.is_internal_page = |
489 IsInternalPage(contents->GetLastCommittedURL()); | 489 IsInternalPage(contents->GetLastCommittedURL()); |
490 stats.is_media = IsMediaTab(contents); | 490 stats.is_media = IsMediaTab(contents); |
491 stats.is_pinned = model->IsTabPinned(i); | 491 stats.is_pinned = model->IsTabPinned(i); |
492 stats.is_selected = active_model && model->IsTabSelected(i); | 492 stats.is_selected = active_model && model->IsTabSelected(i); |
493 stats.is_discarded = GetWebContentsData(contents)->IsDiscarded(); | 493 stats.is_discarded = GetWebContentsData(contents)->IsDiscarded(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { | 525 if (suspend_time.InSeconds() > kSuspendThresholdSeconds) { |
526 // System was probably suspended, move the event timers forward in time so | 526 // System was probably suspended, move the event timers forward in time so |
527 // when they get subtracted out later, "uptime" is being counted. | 527 // when they get subtracted out later, "uptime" is being counted. |
528 start_time_ += suspend_time; | 528 start_time_ += suspend_time; |
529 if (!last_discard_time_.is_null()) | 529 if (!last_discard_time_.is_null()) |
530 last_discard_time_ += suspend_time; | 530 last_discard_time_ += suspend_time; |
531 } | 531 } |
532 } | 532 } |
533 last_adjust_time_ = NowTicks(); | 533 last_adjust_time_ = NowTicks(); |
534 | 534 |
535 #if defined(OS_ANDROID) | |
Georges Khalil
2016/04/19 13:55:19
Move this to an android delegate, similar to chrom
| |
536 auto tab_stats = GetUnsortedTabStats(); | |
537 for (auto& tab : tab_stats) { | |
538 if (!tab.render_process_host->IsProcessBackgrounded()) | |
539 continue; | |
540 if (NowTicks() - tab.last_active < | |
541 base::TimeDelta::FromSeconds( | |
542 kSuspendTimersWhenBackgroundedDelayInSeconds)) { | |
543 continue; | |
544 } | |
545 tab.render_process_host->Suspend(); | |
546 } | |
547 #endif | |
548 | |
535 #if defined(OS_CHROMEOS) | 549 #if defined(OS_CHROMEOS) |
536 TabStatsList stats_list = GetTabStats(); | 550 TabStatsList stats_list = GetTabStats(); |
537 // This starts the CrOS specific OOM adjustments in /proc/<pid>/oom_score_adj. | 551 // This starts the CrOS specific OOM adjustments in /proc/<pid>/oom_score_adj. |
538 delegate_->AdjustOomPriorities(stats_list); | 552 delegate_->AdjustOomPriorities(stats_list); |
539 #endif | 553 #endif |
540 } | 554 } |
541 | 555 |
542 bool TabManager::CanDiscardTab(int64_t target_web_contents_id) const { | 556 bool TabManager::CanDiscardTab(int64_t target_web_contents_id) const { |
543 TabStripModel* model; | 557 TabStripModel* model; |
544 int idx = FindTabStripModelById(target_web_contents_id, &model); | 558 int idx = FindTabStripModelById(target_web_contents_id, &model); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 } | 854 } |
841 } else { | 855 } else { |
842 // The code here can only be tested under a full browser test. | 856 // The code here can only be tested under a full browser test. |
843 AddTabStats(&stats_list); | 857 AddTabStats(&stats_list); |
844 } | 858 } |
845 | 859 |
846 return stats_list; | 860 return stats_list; |
847 } | 861 } |
848 | 862 |
849 } // namespace memory | 863 } // namespace memory |
OLD | NEW |