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

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

Issue 2023643002: Add ARC app icons to the Task Manager UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert back to the original test code Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_delegate_chromeos.h" 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 bool IsArcMemoryManagementEnabled() { 137 bool IsArcMemoryManagementEnabled() {
138 return base::FeatureList::IsEnabled(features::kArcMemoryManagement); 138 return base::FeatureList::IsEnabled(features::kArcMemoryManagement);
139 } 139 }
140 140
141 } // namespace 141 } // namespace
142 142
143 std::ostream& operator<<( 143 std::ostream& operator<<(
144 std::ostream& out, const TabManagerDelegate::Candidate& candidate) { 144 std::ostream& out, const TabManagerDelegate::Candidate& candidate) {
145 if (candidate.is_arc_app) { 145 if (candidate.is_arc_app) {
146 out << "app " << candidate.app->pid 146 out << "app " << candidate.app->pid()
147 << " (" << candidate.app->process_name << ")"; 147 << " (" << candidate.app->process_name() << ")";
148 } else { 148 } else {
149 out << "tab " << candidate.tab->renderer_handle; 149 out << "tab " << candidate.tab->renderer_handle;
150 } 150 }
151 out << " with priority " << candidate.priority; 151 out << " with priority " << candidate.priority;
152 return out; 152 return out;
153 } 153 }
154 154
155 // Holds the info of a newly focused tab or app window. The focused process is 155 // Holds the info of a newly focused tab or app window. The focused process is
156 // set to highest priority (lowest OOM score), but not immediately. To avoid 156 // set to highest priority (lowest OOM score), but not immediately. To avoid
157 // redundant settings the OOM score adjusting only happens after a timeout. If 157 // redundant settings the OOM score adjusting only happens after a timeout. If
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 const std::vector<arc::ArcProcess>& arc_processes) { 606 const std::vector<arc::ArcProcess>& arc_processes) {
607 607
608 std::vector<Candidate> candidates; 608 std::vector<Candidate> candidates;
609 candidates.reserve(tab_list.size() + arc_processes.size()); 609 candidates.reserve(tab_list.size() + arc_processes.size());
610 610
611 for (const auto& tab : tab_list) { 611 for (const auto& tab : tab_list) {
612 candidates.push_back(Candidate(&tab, TabStatsToPriority(tab))); 612 candidates.push_back(Candidate(&tab, TabStatsToPriority(tab)));
613 } 613 }
614 614
615 for (const auto& app : arc_processes) { 615 for (const auto& app : arc_processes) {
616 Candidate candidate(&app, AppStateToPriority(app.process_state)); 616 Candidate candidate(&app, AppStateToPriority(app.process_state()));
617 // Skip persistent android processes since we should never kill them. 617 // Skip persistent android processes since we should never kill them.
618 // Also don't ajust OOM score so their score remains min oom_score_adj. 618 // Also don't ajust OOM score so their score remains min oom_score_adj.
619 if (candidate.priority >= ProcessPriority::ANDROID_PERSISTENT) 619 if (candidate.priority >= ProcessPriority::ANDROID_PERSISTENT)
620 continue; 620 continue;
621 candidates.push_back(candidate); 621 candidates.push_back(candidate);
622 } 622 }
623 623
624 // Sort candidates according to priority. 624 // Sort candidates according to priority.
625 // TODO(cylee): Missing LRU property. Fix it when apps has the information. 625 // TODO(cylee): Missing LRU property. Fix it when apps has the information.
626 std::sort(candidates.begin(), candidates.end()); 626 std::sort(candidates.begin(), candidates.end());
(...skipping 30 matching lines...) Expand all
657 // they're in the active window. Since the user experience would be bad. 657 // they're in the active window. Since the user experience would be bad.
658 if ((!entry.is_arc_app && 658 if ((!entry.is_arc_app &&
659 entry.priority >= ProcessPriority::CHROME_SELECTED) || 659 entry.priority >= ProcessPriority::CHROME_SELECTED) ||
660 (entry.is_arc_app && 660 (entry.is_arc_app &&
661 entry.priority >= ProcessPriority::ANDROID_TOP_INACTIVE)) { 661 entry.priority >= ProcessPriority::ANDROID_TOP_INACTIVE)) {
662 VLOG(2) << "Skipped killing " << entry; 662 VLOG(2) << "Skipped killing " << entry;
663 continue; 663 continue;
664 } 664 }
665 if (entry.is_arc_app) { 665 if (entry.is_arc_app) {
666 int estimated_memory_freed_kb = 666 int estimated_memory_freed_kb =
667 mem_stat_->EstimatedMemoryFreedKB(entry.app->pid); 667 mem_stat_->EstimatedMemoryFreedKB(entry.app->pid());
668 if (KillArcProcess(entry.app->nspid)) { 668 if (KillArcProcess(entry.app->nspid())) {
669 target_memory_to_free_kb -= estimated_memory_freed_kb; 669 target_memory_to_free_kb -= estimated_memory_freed_kb;
670 uma_->ReportKill(estimated_memory_freed_kb); 670 uma_->ReportKill(estimated_memory_freed_kb);
671 VLOG(2) << "Killed " << entry; 671 VLOG(2) << "Killed " << entry;
672 } 672 }
673 } else { 673 } else {
674 int64_t tab_id = entry.tab->tab_contents_id; 674 int64_t tab_id = entry.tab->tab_contents_id;
675 int estimated_memory_freed_kb = 675 int estimated_memory_freed_kb =
676 mem_stat_->EstimatedMemoryFreedKB(entry.tab->renderer_handle); 676 mem_stat_->EstimatedMemoryFreedKB(entry.tab->renderer_handle);
677 if (KillTab(tab_id)) { 677 if (KillTab(tab_id)) {
678 target_memory_to_free_kb -= estimated_memory_freed_kb; 678 target_memory_to_free_kb -= estimated_memory_freed_kb;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // use up the full range. 775 // use up the full range.
776 int num = (rend - rbegin); 776 int num = (rend - rbegin);
777 const float priority_increment = 777 const float priority_increment =
778 static_cast<float>(range_end - range_begin) / num; 778 static_cast<float>(range_end - range_begin) / num;
779 779
780 float priority = range_begin; 780 float priority = range_begin;
781 for (auto cur = rbegin; cur != rend; ++cur) { 781 for (auto cur = rbegin; cur != rend; ++cur) {
782 int score = static_cast<int>(priority + 0.5f); 782 int score = static_cast<int>(priority + 0.5f);
783 if (cur->is_arc_app) { 783 if (cur->is_arc_app) {
784 // Use pid as map keys so it's globally unique. 784 // Use pid as map keys so it's globally unique.
785 (*new_map)[cur->app->pid] = score; 785 (*new_map)[cur->app->pid()] = score;
786 int cur_app_pid_score = 0; 786 int cur_app_pid_score = 0;
787 { 787 {
788 base::AutoLock oom_score_autolock(oom_score_lock_); 788 base::AutoLock oom_score_autolock(oom_score_lock_);
789 cur_app_pid_score = oom_score_map_[cur->app->pid]; 789 cur_app_pid_score = oom_score_map_[cur->app->pid()];
790 } 790 }
791 if (cur_app_pid_score != score) { 791 if (cur_app_pid_score != score) {
792 VLOG(3) << "Set OOM score " << score << " for " << *cur; 792 VLOG(3) << "Set OOM score " << score << " for " << *cur;
793 SetOomScoreAdjForApp(cur->app->nspid, score); 793 SetOomScoreAdjForApp(cur->app->nspid(), score);
794 } 794 }
795 } else { 795 } else {
796 base::ProcessHandle process_handle = cur->tab->renderer_handle; 796 base::ProcessHandle process_handle = cur->tab->renderer_handle;
797 // 1. tab_list contains entries for already-discarded tabs. If the PID 797 // 1. tab_list contains entries for already-discarded tabs. If the PID
798 // (renderer_handle) is zero, we don't need to adjust the oom_score. 798 // (renderer_handle) is zero, we don't need to adjust the oom_score.
799 // 2. Only add unseen process handle so if there's multiple tab maps to 799 // 2. Only add unseen process handle so if there's multiple tab maps to
800 // the same process, the process is set to an OOM score based on its "most 800 // the same process, the process is set to an OOM score based on its "most
801 // important" tab. 801 // important" tab.
802 if (process_handle != 0 && 802 if (process_handle != 0 &&
803 new_map->find(process_handle) == new_map->end()) { 803 new_map->find(process_handle) == new_map->end()) {
(...skipping 12 matching lines...) Expand all
816 } 816 }
817 } 817 }
818 priority += priority_increment; 818 priority += priority_increment;
819 } 819 }
820 820
821 if (oom_score_for_tabs.size()) 821 if (oom_score_for_tabs.size())
822 SetOomScoreAdjForTabs(oom_score_for_tabs); 822 SetOomScoreAdjForTabs(oom_score_for_tabs);
823 } 823 }
824 824
825 } // namespace memory 825 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_process_service.cc ('k') | chrome/browser/memory/tab_manager_delegate_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698