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/chromeos/oom_priority_manager.h" | 5 #include "chrome/browser/chromeos/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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 // deleting us when we're still working. | 118 // deleting us when we're still working. |
| 119 Release(); | 119 Release(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace | 122 } // namespace |
| 123 | 123 |
| 124 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
| 125 // OomPriorityManager | 125 // OomPriorityManager |
| 126 | 126 |
| 127 OomPriorityManager::TabStats::TabStats() | 127 OomPriorityManager::TabStats::TabStats() |
| 128 : is_pinned(false), | 128 : is_app(false), |
| 129 is_pinned(false), | |
| 129 is_selected(false), | 130 is_selected(false), |
| 130 is_discarded(false), | 131 is_discarded(false), |
| 131 sudden_termination_allowed(false), | 132 sudden_termination_allowed(false), |
| 132 renderer_handle(0), | 133 renderer_handle(0), |
| 133 tab_contents_id(0) { | 134 tab_contents_id(0) { |
| 134 } | 135 } |
| 135 | 136 |
| 136 OomPriorityManager::TabStats::~TabStats() { | 137 OomPriorityManager::TabStats::~TabStats() { |
| 137 } | 138 } |
| 138 | 139 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 titles.reserve(stats.size()); | 184 titles.reserve(stats.size()); |
| 184 TabStatsList::iterator it = stats.begin(); | 185 TabStatsList::iterator it = stats.begin(); |
| 185 for ( ; it != stats.end(); ++it) { | 186 for ( ; it != stats.end(); ++it) { |
| 186 string16 str; | 187 string16 str; |
| 187 str.reserve(4096); | 188 str.reserve(4096); |
| 188 str += it->title; | 189 str += it->title; |
| 189 str += ASCIIToUTF16(" ("); | 190 str += ASCIIToUTF16(" ("); |
| 190 int score = pid_to_oom_score_[it->renderer_handle]; | 191 int score = pid_to_oom_score_[it->renderer_handle]; |
| 191 str += base::IntToString16(score); | 192 str += base::IntToString16(score); |
| 192 str += ASCIIToUTF16(")"); | 193 str += ASCIIToUTF16(")"); |
| 193 str += ASCIIToUTF16(it->sudden_termination_allowed ? " sudden_ok " : ""); | 194 str += ASCIIToUTF16(it->is_app ? " app" : ""); |
|
Greg Spencer (Chromium)
2012/08/21 18:51:42
Did you mean to remove the output of the sudden_te
| |
| 195 str += ASCIIToUTF16(it->is_pinned ? " pinned" : ""); | |
| 194 str += ASCIIToUTF16(it->is_discarded ? " discarded" : ""); | 196 str += ASCIIToUTF16(it->is_discarded ? " discarded" : ""); |
| 195 titles.push_back(str); | 197 titles.push_back(str); |
| 196 } | 198 } |
| 197 return titles; | 199 return titles; |
| 198 } | 200 } |
| 199 | 201 |
| 200 // TODO(jamescook): This should consider tabs with references to other tabs, | 202 // TODO(jamescook): This should consider tabs with references to other tabs, |
| 201 // such as tabs created with JavaScript window.open(). We might want to | 203 // such as tabs created with JavaScript window.open(). We might want to |
| 202 // discard the entire set together, or use that in the priority computation. | 204 // discard the entire set together, or use that in the priority computation. |
| 203 bool OomPriorityManager::DiscardTab() { | 205 bool OomPriorityManager::DiscardTab() { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 bool OomPriorityManager::CompareTabStats(TabStats first, | 309 bool OomPriorityManager::CompareTabStats(TabStats first, |
| 308 TabStats second) { | 310 TabStats second) { |
| 309 // Being currently selected is most important. | 311 // Being currently selected is most important. |
| 310 if (first.is_selected != second.is_selected) | 312 if (first.is_selected != second.is_selected) |
| 311 return first.is_selected == true; | 313 return first.is_selected == true; |
| 312 | 314 |
| 313 // Being pinned is second most important. | 315 // Being pinned is second most important. |
| 314 if (first.is_pinned != second.is_pinned) | 316 if (first.is_pinned != second.is_pinned) |
| 315 return first.is_pinned == true; | 317 return first.is_pinned == true; |
| 316 | 318 |
| 319 // Being an app is important too, as you're the only visible surface in the | |
| 320 // window and we don't want to discard that. | |
| 321 if (first.is_app != second.is_app) | |
| 322 return first.is_app == true; | |
| 323 | |
| 317 // TODO(jamescook): Incorporate sudden_termination_allowed into the sort | 324 // TODO(jamescook): Incorporate sudden_termination_allowed into the sort |
| 318 // order. We don't do this now because pages with unload handlers set | 325 // order. We don't do this now because pages with unload handlers set |
| 319 // sudden_termination_allowed false, and that covers too many common pages | 326 // sudden_termination_allowed false, and that covers too many common pages |
| 320 // with ad networks and statistics scripts. Ideally we would like to check | 327 // with ad networks and statistics scripts. Ideally we would like to check |
| 321 // for beforeUnload handlers, which are likely to present a dialog asking | 328 // for beforeUnload handlers, which are likely to present a dialog asking |
| 322 // if the user wants to discard state. crbug.com/123049 | 329 // if the user wants to discard state. crbug.com/123049 |
| 323 | 330 |
| 324 // Being more recently selected is more important. | 331 // Being more recently selected is more important. |
| 325 return first.last_selected > second.last_selected; | 332 return first.last_selected > second.last_selected; |
| 326 } | 333 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() { | 435 OomPriorityManager::TabStatsList OomPriorityManager::GetTabStatsOnUIThread() { |
| 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 430 TabStatsList stats_list; | 437 TabStatsList stats_list; |
| 431 stats_list.reserve(32); // 99% of users have < 30 tabs open | 438 stats_list.reserve(32); // 99% of users have < 30 tabs open |
| 432 bool browser_active = true; | 439 bool browser_active = true; |
| 433 for (BrowserList::const_reverse_iterator browser_iterator = | 440 for (BrowserList::const_reverse_iterator browser_iterator = |
| 434 BrowserList::begin_last_active(); | 441 BrowserList::begin_last_active(); |
| 435 browser_iterator != BrowserList::end_last_active(); | 442 browser_iterator != BrowserList::end_last_active(); |
| 436 ++browser_iterator) { | 443 ++browser_iterator) { |
| 437 Browser* browser = *browser_iterator; | 444 Browser* browser = *browser_iterator; |
| 445 bool is_browser_for_app = browser->is_app(); | |
| 438 const TabStripModel* model = browser->tab_strip_model(); | 446 const TabStripModel* model = browser->tab_strip_model(); |
| 439 for (int i = 0; i < model->count(); i++) { | 447 for (int i = 0; i < model->count(); i++) { |
| 440 WebContents* contents = model->GetTabContentsAt(i)->web_contents(); | 448 WebContents* contents = model->GetTabContentsAt(i)->web_contents(); |
| 441 if (!contents->IsCrashed()) { | 449 if (!contents->IsCrashed()) { |
| 442 TabStats stats; | 450 TabStats stats; |
| 451 stats.is_app = is_browser_for_app; | |
| 443 stats.is_pinned = model->IsTabPinned(i); | 452 stats.is_pinned = model->IsTabPinned(i); |
| 444 stats.is_selected = browser_active && model->IsTabSelected(i); | 453 stats.is_selected = browser_active && model->IsTabSelected(i); |
| 445 stats.is_discarded = model->IsTabDiscarded(i); | 454 stats.is_discarded = model->IsTabDiscarded(i); |
| 446 stats.sudden_termination_allowed = | 455 stats.sudden_termination_allowed = |
| 447 contents->GetRenderProcessHost()->SuddenTerminationAllowed(); | 456 contents->GetRenderProcessHost()->SuddenTerminationAllowed(); |
| 448 stats.last_selected = contents->GetLastSelectedTime(); | 457 stats.last_selected = contents->GetLastSelectedTime(); |
| 449 stats.renderer_handle = contents->GetRenderProcessHost()->GetHandle(); | 458 stats.renderer_handle = contents->GetRenderProcessHost()->GetHandle(); |
| 450 stats.title = contents->GetTitle(); | 459 stats.title = contents->GetTitle(); |
| 451 stats.tab_contents_id = IdFromTabContents(contents); | 460 stats.tab_contents_id = IdFromTabContents(contents); |
| 452 stats_list.push_back(stats); | 461 stats_list.push_back(stats); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 510 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
| 502 iterator->renderer_handle, score); | 511 iterator->renderer_handle, score); |
| 503 pid_to_oom_score_[iterator->renderer_handle] = score; | 512 pid_to_oom_score_[iterator->renderer_handle] = score; |
| 504 } | 513 } |
| 505 priority += priority_increment; | 514 priority += priority_increment; |
| 506 } | 515 } |
| 507 } | 516 } |
| 508 } | 517 } |
| 509 | 518 |
| 510 } // namespace chromeos | 519 } // namespace chromeos |
| OLD | NEW |