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 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_IMPL_H_ |
6 #define CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/memory_pressure_listener.h" | 12 #include "base/memory/memory_pressure_listener.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 class BrowserChildProcessHost; | 18 class BrowserChildProcessHost; |
19 class MemoryMessageFilter; | 19 class MemoryMessageFilter; |
20 class RenderProcessHost; | 20 class RenderProcessHost; |
21 | 21 |
22 class CONTENT_EXPORT MemoryPressureController { | 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 forward to individual processes. This allows the browser | |
Charlie Reis
2016/01/29 19:46:56
nit: forwarded
chrisha
2016/01/29 21:12:12
Done.
| |
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 { | |
Charlie Reis
2016/01/29 19:46:56
It'd be more common to have this derive from Memor
chrisha
2016/01/29 21:12:12
Yeah... I wasn't 100% sure whether or not this was
| |
23 public: | 31 public: |
24 // These methods must be called on the IO thread. | 32 // These methods must be called on the IO thread. |
25 void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter); | 33 void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter); |
26 void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter); | 34 void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter); |
27 | 35 |
28 // These methods can be called from any thread. | 36 // These methods can be called from any thread. |
37 | |
38 // Suppresses all memory pressure messages from passing through all attached | |
39 // MemoryMessageFilters. Any messages sent through a "suppressed" filter will | |
40 // be ignored on the receiving end. | |
29 void SetPressureNotificationsSuppressedInAllProcesses(bool suppressed); | 41 void SetPressureNotificationsSuppressedInAllProcesses(bool suppressed); |
42 | |
43 // Simulates memory pressure in all processes by invoking | |
44 // SimulatePressureNotification on all attached MemoryMessageFilters. These | |
45 // messages will be received even if suppression is enabled. | |
30 void SimulatePressureNotificationInAllProcesses( | 46 void SimulatePressureNotificationInAllProcesses( |
31 base::MemoryPressureListener::MemoryPressureLevel level); | 47 base::MemoryPressureListener::MemoryPressureLevel level); |
48 | |
49 // Sends a memory pressure notification to the specified browser child process | |
50 // via its attached MemoryMessageFilter. | |
32 void SendPressureNotification( | 51 void SendPressureNotification( |
33 const BrowserChildProcessHost* child_process_host, | 52 const BrowserChildProcessHost* child_process_host, |
34 base::MemoryPressureListener::MemoryPressureLevel level); | 53 base::MemoryPressureListener::MemoryPressureLevel level); |
54 | |
55 // Sends a memory pressure notification to the specified renderer process via | |
56 // its attached MemoryMessageFilter. | |
35 void SendPressureNotification( | 57 void SendPressureNotification( |
36 const RenderProcessHost* render_process_host, | 58 const RenderProcessHost* render_process_host, |
37 base::MemoryPressureListener::MemoryPressureLevel level); | 59 base::MemoryPressureListener::MemoryPressureLevel level); |
38 | 60 |
39 // This method can be called from any thread. | 61 // This method can be called from any thread. |
40 static MemoryPressureController* GetInstance(); | 62 static MemoryPressureControllerImpl* GetInstance(); |
Charlie Reis
2016/01/29 19:46:56
nit: Move this to be the first public method.
chrisha
2016/01/29 21:12:12
Done.
| |
41 | 63 |
42 protected: | 64 protected: |
43 virtual ~MemoryPressureController(); | 65 virtual ~MemoryPressureControllerImpl(); |
44 | 66 |
45 private: | 67 private: |
46 friend struct base::DefaultSingletonTraits<MemoryPressureController>; | 68 friend struct base::DefaultSingletonTraits<MemoryPressureControllerImpl>; |
47 | 69 |
48 MemoryPressureController(); | 70 MemoryPressureControllerImpl(); |
49 | 71 |
50 // Implementation of the various SendPressureNotification methods. | 72 // Implementation of the various SendPressureNotification methods. |
51 void SendPressureNotificationImpl( | 73 void SendPressureNotificationImpl( |
52 const void* child_process_host, | 74 const void* child_process_host, |
53 base::MemoryPressureListener::MemoryPressureLevel level); | 75 base::MemoryPressureListener::MemoryPressureLevel level); |
54 | 76 |
55 // Map from untyped process host pointers to the associated memory message | 77 // Map from untyped process host pointers to the associated memory message |
56 // filters in the browser process. Always accessed on the IO thread. | 78 // filters in the browser process. Always accessed on the IO thread. |
57 typedef std::map<const void*, scoped_refptr<MemoryMessageFilter>> | 79 typedef std::map<const void*, scoped_refptr<MemoryMessageFilter>> |
58 MemoryMessageFilterMap; | 80 MemoryMessageFilterMap; |
59 MemoryMessageFilterMap memory_message_filters_; | 81 MemoryMessageFilterMap memory_message_filters_; |
60 | 82 |
61 DISALLOW_COPY_AND_ASSIGN(MemoryPressureController); | 83 DISALLOW_COPY_AND_ASSIGN(MemoryPressureControllerImpl); |
62 }; | 84 }; |
63 | 85 |
64 } // namespace content | 86 } // namespace content |
65 | 87 |
66 #endif // CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_H_ | 88 #endif // CONTENT_BROWSER_MEMORY_MEMORY_PRESSURE_CONTROLLER_IMPL_H_ |
OLD | NEW |