| 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/memory/oom_priority_manager.h" | 5 #include "chrome/browser/chromeos/memory/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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/process.h" | 16 #include "base/process.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 23 #include "base/time.h" | 23 #include "base/time.h" |
| 24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 27 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| 28 #include "chrome/browser/chromeos/memory/low_memory_observer.h" | |
| 29 #include "chrome/browser/memory_details.h" | 28 #include "chrome/browser/memory_details.h" |
| 30 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_iterator.h" | 30 #include "chrome/browser/ui/browser_iterator.h" |
| 32 #include "chrome/browser/ui/browser_list.h" | 31 #include "chrome/browser/ui/browser_list.h" |
| 33 #include "chrome/browser/ui/host_desktop.h" | 32 #include "chrome/browser/ui/host_desktop.h" |
| 34 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 33 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/browser/ui/tabs/tab_utils.h" | 35 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 37 #include "chrome/common/chrome_constants.h" | 36 #include "chrome/common/chrome_constants.h" |
| 38 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "chromeos/memory/low_memory_listener.h" |
| 40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
| 42 #include "content/public/browser/notification_types.h" | 42 #include "content/public/browser/notification_types.h" |
| 43 #include "content/public/browser/render_process_host.h" | 43 #include "content/public/browser/render_process_host.h" |
| 44 #include "content/public/browser/render_widget_host.h" | 44 #include "content/public/browser/render_widget_host.h" |
| 45 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/browser/zygote_host_linux.h" | 46 #include "content/public/browser/zygote_host_linux.h" |
| 47 #include "ui/base/text/bytes_formatting.h" | 47 #include "ui/base/text/bytes_formatting.h" |
| 48 | 48 |
| 49 using base::TimeDelta; | 49 using base::TimeDelta; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 OomPriorityManager::TabStats::~TabStats() { | 168 OomPriorityManager::TabStats::~TabStats() { |
| 169 } | 169 } |
| 170 | 170 |
| 171 OomPriorityManager::OomPriorityManager() | 171 OomPriorityManager::OomPriorityManager() |
| 172 : focused_tab_pid_(0), | 172 : focused_tab_pid_(0), |
| 173 discard_count_(0), | 173 discard_count_(0), |
| 174 recent_tab_discard_(false) { | 174 recent_tab_discard_(false) { |
| 175 // We only need the low memory observer if we want to discard tabs. | 175 // We only need the low memory observer if we want to discard tabs. |
| 176 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDiscardTabs)) | 176 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDiscardTabs)) |
| 177 low_memory_observer_.reset(new LowMemoryObserver); | 177 low_memory_listener_.reset(new LowMemoryListener(this)); |
| 178 | 178 |
| 179 registrar_.Add(this, | 179 registrar_.Add(this, |
| 180 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 180 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 181 content::NotificationService::AllBrowserContextsAndSources()); | 181 content::NotificationService::AllBrowserContextsAndSources()); |
| 182 registrar_.Add(this, | 182 registrar_.Add(this, |
| 183 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 183 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 184 content::NotificationService::AllBrowserContextsAndSources()); | 184 content::NotificationService::AllBrowserContextsAndSources()); |
| 185 registrar_.Add(this, | 185 registrar_.Add(this, |
| 186 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 186 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 187 content::NotificationService::AllBrowserContextsAndSources()); | 187 content::NotificationService::AllBrowserContextsAndSources()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 198 this, | 198 this, |
| 199 &OomPriorityManager::AdjustOomPriorities); | 199 &OomPriorityManager::AdjustOomPriorities); |
| 200 } | 200 } |
| 201 if (!recent_tab_discard_timer_.IsRunning()) { | 201 if (!recent_tab_discard_timer_.IsRunning()) { |
| 202 recent_tab_discard_timer_.Start( | 202 recent_tab_discard_timer_.Start( |
| 203 FROM_HERE, | 203 FROM_HERE, |
| 204 TimeDelta::FromSeconds(kRecentTabDiscardIntervalSeconds), | 204 TimeDelta::FromSeconds(kRecentTabDiscardIntervalSeconds), |
| 205 this, | 205 this, |
| 206 &OomPriorityManager::RecordRecentTabDiscard); | 206 &OomPriorityManager::RecordRecentTabDiscard); |
| 207 } | 207 } |
| 208 if (low_memory_observer_.get()) | 208 if (low_memory_listener_.get()) |
| 209 low_memory_observer_->Start(); | 209 low_memory_listener_->Start(); |
| 210 start_time_ = TimeTicks::Now(); | 210 start_time_ = TimeTicks::Now(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void OomPriorityManager::Stop() { | 213 void OomPriorityManager::Stop() { |
| 214 timer_.Stop(); | 214 timer_.Stop(); |
| 215 recent_tab_discard_timer_.Stop(); | 215 recent_tab_discard_timer_.Stop(); |
| 216 if (low_memory_observer_.get()) | 216 if (low_memory_listener_.get()) |
| 217 low_memory_observer_->Stop(); | 217 low_memory_listener_->Stop(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 std::vector<string16> OomPriorityManager::GetTabTitles() { | 220 std::vector<string16> OomPriorityManager::GetTabTitles() { |
| 221 TabStatsList stats = GetTabStatsOnUIThread(); | 221 TabStatsList stats = GetTabStatsOnUIThread(); |
| 222 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); | 222 base::AutoLock pid_to_oom_score_autolock(pid_to_oom_score_lock_); |
| 223 std::vector<string16> titles; | 223 std::vector<string16> titles; |
| 224 titles.reserve(stats.size()); | 224 titles.reserve(stats.size()); |
| 225 TabStatsList::iterator it = stats.begin(); | 225 TabStatsList::iterator it = stats.begin(); |
| 226 for ( ; it != stats.end(); ++it) { | 226 for ( ; it != stats.end(); ++it) { |
| 227 string16 str; | 227 string16 str; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 if (it == pid_to_oom_score_.end() || it->second != score) { | 631 if (it == pid_to_oom_score_.end() || it->second != score) { |
| 632 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 632 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
| 633 iterator->renderer_handle, score); | 633 iterator->renderer_handle, score); |
| 634 pid_to_oom_score_[iterator->renderer_handle] = score; | 634 pid_to_oom_score_[iterator->renderer_handle] = score; |
| 635 } | 635 } |
| 636 priority += priority_increment; | 636 priority += priority_increment; |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 | 640 |
| 641 void OomPriorityManager::OnMemoryLow() { |
| 642 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 643 LogMemoryAndDiscardTab(); |
| 644 } |
| 645 |
| 641 } // namespace chromeos | 646 } // namespace chromeos |
| OLD | NEW |