Chromium Code Reviews| Index: chrome/browser/oom_priority_manager.cc |
| diff --git a/chrome/browser/oom_priority_manager.cc b/chrome/browser/oom_priority_manager.cc |
| index adf635d6a034ae9d9e0a691a2d8838aacce32260..c68b38681f175d2254ca4135bad0316c35bcaeb4 100644 |
| --- a/chrome/browser/oom_priority_manager.cc |
| +++ b/chrome/browser/oom_priority_manager.cc |
| @@ -19,7 +19,9 @@ |
| #include "base/timer.h" |
| #include "base/utf_string_conversions.h" |
| #include "build/build_config.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/low_memory_observer.h" |
| +#include "chrome/browser/memory_details.h" |
| #include "chrome/browser/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| @@ -74,6 +76,42 @@ int64 IdFromTabContents(WebContents* web_contents) { |
| return reinterpret_cast<int64>(web_contents); |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// OomMemoryDetails logs details about all Chrome processes during an out-of- |
| +// memory event in an attempt to identify the culprit, then discards a tab and |
| +// deletes itself. |
| +class OomMemoryDetails : public MemoryDetails { |
| + public: |
| + OomMemoryDetails(); |
| + |
| + // MemoryDetails overrides: |
| + virtual void OnDetailsAvailable() OVERRIDE; |
| + |
| + private: |
| + virtual ~OomMemoryDetails() {} |
| + |
| + TimeTicks start_time_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OomMemoryDetails); |
| +}; |
| + |
| +OomMemoryDetails::OomMemoryDetails() { |
| + start_time_ = TimeTicks::Now(); |
| +} |
| + |
| +void OomMemoryDetails::OnDetailsAvailable() { |
| + TimeDelta delta = TimeTicks::Now() - start_time_; |
| + // These logs are collected by user feedback reports. We want them to help |
| + // diagnose user-reported problems with frequently discarded tabs. |
| + LOG(INFO) << "OOM details (" << delta.InMilliseconds() << " ms):\n" |
| + << ToLogString(); |
| + if (g_browser_process && g_browser_process->oom_priority_manager()) |
| + g_browser_process->oom_priority_manager()->DiscardTab(); |
| + // Delete ourselves so we don't have to worry about OomPriorityManager |
| + // deleting us when we're still working. |
| + delete this; |
|
Greg Spencer (Chromium)
2012/04/20 00:28:21
Interesting solution. I like it.
|
| +} |
| + |
| } // namespace |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -161,6 +199,12 @@ bool OomPriorityManager::DiscardTab() { |
| return false; |
| } |
| +void OomPriorityManager::LogMemoryAndDiscardTab() { |
| + // Deletes itself upon completion. |
| + OomMemoryDetails* details = new OomMemoryDetails(); |
| + details->StartFetch(); |
| +} |
| + |
| bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) { |
| for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); |
| browser_iterator != BrowserList::end(); ++browser_iterator) { |