| Index: chrome/browser/oom_priority_manager.cc
|
| diff --git a/chrome/browser/oom_priority_manager.cc b/chrome/browser/oom_priority_manager.cc
|
| index cff350c12f0e271d533de8ae06433334465f16b5..429f817f975dbcc86df6a2336f60d290af15bf53 100644
|
| --- a/chrome/browser/oom_priority_manager.cc
|
| +++ b/chrome/browser/oom_priority_manager.cc
|
| @@ -20,7 +20,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"
|
| @@ -76,6 +78,43 @@ 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() {
|
| + AddRef(); // Released in OnDetailsAvailable().
|
| + 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.
|
| + Release();
|
| +}
|
| +
|
| } // namespace
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -168,6 +207,12 @@ bool OomPriorityManager::DiscardTab() {
|
| return false;
|
| }
|
|
|
| +void OomPriorityManager::LogMemoryAndDiscardTab() {
|
| + // Deletes itself upon completion.
|
| + OomMemoryDetails* details = new OomMemoryDetails();
|
| + details->StartFetch(MemoryDetails::SKIP_USER_METRICS);
|
| +}
|
| +
|
| bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) {
|
| for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
|
| browser_iterator != BrowserList::end(); ++browser_iterator) {
|
|
|