| 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_H_ | |
| 6 #define CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_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 class CONTENT_EXPORT MemoryPressureController { | |
| 23 public: | |
| 24 // These methods must be called on the IO thread. | |
| 25 void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter); | |
| 26 void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter); | |
| 27 | |
| 28 // These methods can be called from any thread. | |
| 29 void SetPressureNotificationsSuppressedInAllProcesses(bool suppressed); | |
| 30 void SimulatePressureNotificationInAllProcesses( | |
| 31 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 32 void SendPressureNotification( | |
| 33 const BrowserChildProcessHost* child_process_host, | |
| 34 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 35 void SendPressureNotification( | |
| 36 const RenderProcessHost* render_process_host, | |
| 37 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 38 | |
| 39 // This method can be called from any thread. | |
| 40 static MemoryPressureController* GetInstance(); | |
| 41 | |
| 42 protected: | |
| 43 virtual ~MemoryPressureController(); | |
| 44 | |
| 45 private: | |
| 46 friend struct base::DefaultSingletonTraits<MemoryPressureController>; | |
| 47 | |
| 48 MemoryPressureController(); | |
| 49 | |
| 50 // Implementation of the various SendPressureNotification methods. | |
| 51 void SendPressureNotificationImpl( | |
| 52 const void* child_process_host, | |
| 53 base::MemoryPressureListener::MemoryPressureLevel level); | |
| 54 | |
| 55 // Map from untyped process host pointers to the associated memory message | |
| 56 // filters in the browser process. Always accessed on the IO thread. | |
| 57 typedef std::map<const void*, scoped_refptr<MemoryMessageFilter>> | |
| 58 MemoryMessageFilterMap; | |
| 59 MemoryMessageFilterMap memory_message_filters_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(MemoryPressureController); | |
| 62 }; | |
| 63 | |
| 64 } // namespace content | |
| 65 | |
| 66 #endif // CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ | |
| OLD | NEW |