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