| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/memory/memory_pressure_controller_impl.h" | 5 #include "content/browser/memory/memory_pressure_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/feature_list.h" |
| 8 #include "content/browser/memory/memory_message_filter.h" | 9 #include "content/browser/memory/memory_message_filter.h" |
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/common/content_features.h" |
| 12 |
| 13 namespace features { |
| 14 |
| 15 // This experiment controls whether memory pressure notifications to |
| 16 // renderers are broadcast. |
| 17 const base::Feature kEnableBroadcastMemoryPressure = { |
| 18 "EnableBroadcastMemoryPressure", base::FEATURE_ENABLED_BY_DEFAULT, |
| 19 }; |
| 20 |
| 21 } // namespace features |
| 10 | 22 |
| 11 namespace content { | 23 namespace content { |
| 12 | 24 |
| 13 MemoryPressureControllerImpl::MemoryPressureControllerImpl() {} | 25 MemoryPressureControllerImpl::MemoryPressureControllerImpl() {} |
| 14 | 26 |
| 15 MemoryPressureControllerImpl::~MemoryPressureControllerImpl() {} | 27 MemoryPressureControllerImpl::~MemoryPressureControllerImpl() {} |
| 16 | 28 |
| 17 void MemoryPressureControllerImpl::OnMemoryMessageFilterAdded( | 29 void MemoryPressureControllerImpl::OnMemoryMessageFilterAdded( |
| 18 MemoryMessageFilter* filter) { | 30 MemoryMessageFilter* filter) { |
| 19 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 31 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 20 | 32 |
| 21 // Add the message filter to the set of all memory message filters and check | 33 // Add the message filter to the set of all memory message filters and check |
| 22 // that it wasn't there beforehand. | 34 // that it wasn't there beforehand. |
| 23 const bool success = | 35 const bool success = |
| 24 memory_message_filters_.insert( | 36 memory_message_filters_ |
| 25 std::make_pair(filter->process_host(), filter)) | 37 .insert(std::make_pair(filter->process_host(), filter)) |
| 26 .second; | 38 .second; |
| 27 DCHECK(success); | 39 DCHECK(success); |
| 28 | 40 |
| 29 // There's no need to send a message to the child process if memory pressure | 41 // There's no need to send a message to the child process if memory pressure |
| 30 // notifications are not suppressed. | 42 // notifications are not suppressed. |
| 31 if (base::MemoryPressureListener::AreNotificationsSuppressed()) | 43 if (base::MemoryPressureListener::AreNotificationsSuppressed()) |
| 32 filter->SendSetPressureNotificationsSuppressed(true); | 44 filter->SendSetPressureNotificationsSuppressed(true); |
| 33 } | 45 } |
| 34 | 46 |
| 35 void MemoryPressureControllerImpl::OnMemoryMessageFilterRemoved( | 47 void MemoryPressureControllerImpl::OnMemoryMessageFilterRemoved( |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
| 121 BrowserThread::IO, FROM_HERE, | 133 BrowserThread::IO, FROM_HERE, |
| 122 base::Bind(&MemoryPressureControllerImpl::SendPressureNotificationImpl, | 134 base::Bind(&MemoryPressureControllerImpl::SendPressureNotificationImpl, |
| 123 base::Unretained(this), child_process_host, level)); | 135 base::Unretained(this), child_process_host, level)); |
| 124 return; | 136 return; |
| 125 } | 137 } |
| 126 | 138 |
| 127 if (base::MemoryPressureListener::AreNotificationsSuppressed()) | 139 if (base::MemoryPressureListener::AreNotificationsSuppressed()) |
| 128 return; | 140 return; |
| 129 | 141 |
| 142 // This desktop-only experiment can disable the memory pressure broadcasts. |
| 143 #if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || \ |
| 144 defined(OS_WIN) |
| 145 if (!base::FeatureList::IsEnabled(features::kEnableBroadcastMemoryPressure)) |
| 146 return; |
| 147 #endif |
| 148 |
| 130 // Find the appropriate message filter and dispatch the message. | 149 // Find the appropriate message filter and dispatch the message. |
| 131 auto it = memory_message_filters_.find(child_process_host); | 150 auto it = memory_message_filters_.find(child_process_host); |
| 132 if (it != memory_message_filters_.end()) | 151 if (it != memory_message_filters_.end()) |
| 133 it->second->SendPressureNotification(level); | 152 it->second->SendPressureNotification(level); |
| 134 } | 153 } |
| 135 | 154 |
| 136 } // namespace content | 155 } // namespace content |
| OLD | NEW |