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

Unified Diff: chrome/browser/chromeos/memory/oom_priority_manager.cc

Issue 681733003: Removed the ProcessHandle from the RendererClosedDetails payload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed chromeos dependency Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/memory/oom_priority_manager.cc
diff --git a/chrome/browser/chromeos/memory/oom_priority_manager.cc b/chrome/browser/chromeos/memory/oom_priority_manager.cc
index 823207f9ffa1726ffe25d14afbea0d9f3e82d501..ff1214022a1a75e09b762ece9a76083f589dd5e5 100644
--- a/chrome/browser/chromeos/memory/oom_priority_manager.cc
+++ b/chrome/browser/chromeos/memory/oom_priority_manager.cc
@@ -171,7 +171,7 @@ OomPriorityManager::TabStats::~TabStats() {
}
OomPriorityManager::OomPriorityManager()
- : focused_tab_pid_(0),
+ : focused_tab_process_id_(0),
low_memory_observer_(new LowMemoryObserver),
discard_count_(0),
recent_tab_discard_(false) {
@@ -218,14 +218,14 @@ void OomPriorityManager::Stop() {
std::vector<base::string16> OomPriorityManager::GetTabTitles() {
TabStatsList stats = GetTabStatsOnUIThread();
- base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_);
+ base::AutoLock oom_score_autolock(oom_score_lock_);
std::vector<base::string16> titles;
titles.reserve(stats.size());
TabStatsList::iterator it = stats.begin();
for ( ; it != stats.end(); ++it) {
base::string16 str;
str.reserve(4096);
- int score = pid_to_oom_score_[it->renderer_handle];
+ int score = oom_score_map_[it->child_process_id];
str += base::IntToString16(score);
str += base::ASCIIToUTF16(" - ");
str += it->title;
@@ -456,10 +456,13 @@ bool OomPriorityManager::CompareTabStats(TabStats first,
void OomPriorityManager::AdjustFocusedTabScoreOnFileThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_);
+ base::AutoLock oom_score_autolock(oom_score_lock_);
+ base::ProcessHandle pid = content::RenderProcessHost::FromID(
+ focused_tab_process_id_)->GetHandle();
content::ZygoteHost::GetInstance()->AdjustRendererOOMScore(
- focused_tab_pid_, chrome::kLowestRendererOomScore);
- pid_to_oom_score_[focused_tab_pid_] = chrome::kLowestRendererOomScore;
+ pid, chrome::kLowestRendererOomScore);
+ oom_score_map_[focused_tab_process_id_] =
+ chrome::kLowestRendererOomScore;
}
void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() {
@@ -472,35 +475,28 @@ void OomPriorityManager::OnFocusTabScoreAdjustmentTimeout() {
void OomPriorityManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- base::ProcessHandle handle = 0;
- base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_);
+ base::AutoLock oom_score_autolock(oom_score_lock_);
switch (type) {
- case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
- handle =
- content::Details<content::RenderProcessHost::RendererClosedDetails>(
- details)->handle;
- pid_to_oom_score_.erase(handle);
- break;
- }
+ case content::NOTIFICATION_RENDERER_PROCESS_CLOSED:
case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
- handle = content::Source<content::RenderProcessHost>(source)->
- GetHandle();
- pid_to_oom_score_.erase(handle);
+ content::RenderProcessHost* host =
+ content::Source<content::RenderProcessHost>(source).ptr();
+ oom_score_map_.erase(host->GetID());
break;
}
case content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED: {
bool visible = *content::Details<bool>(details).ptr();
if (visible) {
- focused_tab_pid_ =
+ focused_tab_process_id_ =
content::Source<content::RenderWidgetHost>(source).ptr()->
- GetProcess()->GetHandle();
+ GetProcess()->GetID();
// If the currently focused tab already has a lower score, do not
// set it. This can happen in case the newly focused tab is script
// connected to the previous tab.
ProcessScoreMap::iterator it;
- it = pid_to_oom_score_.find(focused_tab_pid_);
- if (it == pid_to_oom_score_.end()
+ it = oom_score_map_.find(focused_tab_process_id_);
+ if (it == oom_score_map_.end()
|| it->second != chrome::kLowestRendererOomScore) {
// By starting a timer we guarantee that the tab is focused for
// certain amount of time. Secondly, it also does not add overhead
@@ -581,6 +577,7 @@ OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() {
stats.is_discarded = model->IsTabDiscarded(i);
stats.last_active = contents->GetLastActiveTime();
stats.renderer_handle = contents->GetRenderProcessHost()->GetHandle();
+ stats.child_process_id = contents->GetRenderProcessHost()->GetID();
stats.title = contents->GetTitle();
stats.tab_contents_id = IdFromWebContents(contents);
stats_list.push_back(stats);
@@ -596,9 +593,9 @@ OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() {
}
// static
-std::vector<base::ProcessHandle> OomPriorityManager::GetProcessHandles(
+std::vector<int> OomPriorityManager::GetChildProcessIds(
const TabStatsList& stats_list) {
- std::vector<base::ProcessHandle> process_handles;
+ std::vector<int> child_process_ids;
std::set<base::ProcessHandle> already_seen;
for (TabStatsList::const_iterator iterator = stats_list.begin();
iterator != stats_list.end(); ++iterator) {
@@ -613,21 +610,20 @@ std::vector<base::ProcessHandle> OomPriorityManager::GetProcessHandles(
continue;
}
- process_handles.push_back(iterator->renderer_handle);
+ child_process_ids.push_back(iterator->child_process_id);
}
- return process_handles;
+ return child_process_ids;
}
void OomPriorityManager::AdjustOomPrioritiesOnFileThread(
TabStatsList stats_list) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_);
+ base::AutoLock oom_score_autolock(oom_score_lock_);
// Remove any duplicate PIDs. Order of the list is maintained, so each
// renderer process will take on the oom_score_adj of the most important
// (least likely to be killed) tab.
- std::vector<base::ProcessHandle> process_handles =
- GetProcessHandles(stats_list);
+ std::vector<int> child_process_ids = GetChildProcessIds(stats_list);
// Now we assign priorities based on the sorted list. We're
// assigning priorities in the range of kLowestRendererOomScore to
@@ -643,18 +639,18 @@ void OomPriorityManager::AdjustOomPrioritiesOnFileThread(
const int kPriorityRange = chrome::kHighestRendererOomScore -
chrome::kLowestRendererOomScore;
float priority_increment =
- static_cast<float>(kPriorityRange) / process_handles.size();
- for (std::vector<base::ProcessHandle>::iterator iterator =
- process_handles.begin();
- iterator != process_handles.end(); ++iterator) {
+ static_cast<float>(kPriorityRange) / child_process_ids.size();
+ for (int child_process_id : child_process_ids) {
int score = static_cast<int>(priority + 0.5f);
- ProcessScoreMap::iterator it = pid_to_oom_score_.find(*iterator);
+ ProcessScoreMap::iterator it =
+ oom_score_map_.find(child_process_id);
// If a process has the same score as the newly calculated value,
// do not set it.
- if (it == pid_to_oom_score_.end() || it->second != score) {
- content::ZygoteHost::GetInstance()->AdjustRendererOOMScore(*iterator,
- score);
- pid_to_oom_score_[*iterator] = score;
+ if (it == oom_score_map_.end() || it->second != score) {
+ base::ProcessHandle pid =
+ content::RenderProcessHost::FromID(child_process_id)->GetHandle();
+ content::ZygoteHost::GetInstance()->AdjustRendererOOMScore(pid, score);
+ oom_score_map_[child_process_id] = score;
}
priority += priority_increment;
}

Powered by Google App Engine
This is Rietveld 408576698