| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_IMPL_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/memory_pressure_listener.h" | |
| 13 #include "base/memory/singleton.h" | |
| 14 #include "content/common/content_export.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 class BrowserChildProcessHost; | |
| 19 class MemoryMessageFilter; | |
| 20 class RenderProcessHost; | |
| 21 | |
| 22 // Controller for memory pressure IPC messages. Each child process owns and | |
| 23 // registers a MemoryMessageFilter, which can be used to both suppress and | |
| 24 // simulate memory pressure messages across processes. This controller | |
| 25 // coordinates suppressing and simulation of messages, as well as allows for | |
| 26 // messages to be forwarded to individual processes. This allows the browser | |
| 27 // process to control what memory pressure messages are seen in child processes. | |
| 28 // For more details see content/browser/memory/memory_message_filter.h and | |
| 29 // content/child/memory/child_memory_message_filter.h. | |
| 30 class CONTENT_EXPORT MemoryPressureControllerImpl { | |
| 31 public: | |
| 32 // This method can be called from any thread. | |
| 33 static MemoryPressureControllerImpl* GetInstance(); | |
| 34 | |
| 35 // These methods must be called on the IO thread. | |
| 36 void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter); | |
| 37 void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter); | |
| 38 | |
| 39 // These methods can be called from any thread. | |
| 40 | |
| 41 // Suppresses all memory pressure messages from passing through all attached | |
| 42 // MemoryMessageFilters. Any messages sent through a "suppressed" filter will | |
| 43 // be ignored on the receiving end. | |
| 44 void SetPressureNotificationsSuppressedInAllProcesses(bool suppressed); | |
| 45 | |
| 46 // Simulates memory pressure in all processes by invoking | |
| 47 // SimulatePressureNotification on all attached MemoryMessageFilters. These | |
| 48 // messages will be received even if suppression is enabled. | |
| 49 void SimulatePressureNotificationInAllProcesses( | |
| 50 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 51 | |
| 52 // Sends a memory pressure notification to the specified browser child process | |
| 53 // via its attached MemoryMessageFilter. | |
| 54 void SendPressureNotification( | |
| 55 const BrowserChildProcessHost* child_process_host, | |
| 56 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 57 | |
| 58 // Sends a memory pressure notification to the specified renderer process via | |
| 59 // its attached MemoryMessageFilter. | |
| 60 void SendPressureNotification( | |
| 61 const RenderProcessHost* render_process_host, | |
| 62 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 63 | |
| 64 protected: | |
| 65 virtual ~MemoryPressureControllerImpl(); | |
| 66 | |
| 67 private: | |
| 68 friend struct base::DefaultSingletonTraits<MemoryPressureControllerImpl>; | |
| 69 | |
| 70 MemoryPressureControllerImpl(); | |
| 71 | |
| 72 // Implementation of the various SendPressureNotification methods. | |
| 73 void SendPressureNotificationImpl( | |
| 74 const void* child_process_host, | |
| 75 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 76 | |
| 77 // Map from untyped process host pointers to the associated memory message | |
| 78 // filters in the browser process. Always accessed on the IO thread. | |
| 79 typedef std::map<const void*, scoped_refptr<MemoryMessageFilter>> | |
| 80 MemoryMessageFilterMap; | |
| 81 MemoryMessageFilterMap memory_message_filters_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(MemoryPressureControllerImpl); | |
| 84 }; | |
| 85 | |
| 86 } // namespace content | |
| 87 | |
| 88 #endif // CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_IMPL_H_ | |
| OLD | NEW |