Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: content/browser/memory/memory_pressure_controller_impl.h

Issue 1641813002: Provide renderers with memory pressure signals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@contentapi
Patch Set: Addressed creis' comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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 {
23 public: 31 public:
32 // This method can be called from any thread.
33 static MemoryPressureControllerImpl* GetInstance();
34
24 // These methods must be called on the IO thread. 35 // These methods must be called on the IO thread.
25 void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter); 36 void OnMemoryMessageFilterAdded(MemoryMessageFilter* filter);
26 void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter); 37 void OnMemoryMessageFilterRemoved(MemoryMessageFilter* filter);
27 38
28 // These methods can be called from any thread. 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.
29 void SetPressureNotificationsSuppressedInAllProcesses(bool suppressed); 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.
30 void SimulatePressureNotificationInAllProcesses( 49 void SimulatePressureNotificationInAllProcesses(
31 base::MemoryPressureListener::MemoryPressureLevel level); 50 base::MemoryPressureListener::MemoryPressureLevel level);
51
52 // Sends a memory pressure notification to the specified browser child process
53 // via its attached MemoryMessageFilter.
32 void SendPressureNotification( 54 void SendPressureNotification(
33 const BrowserChildProcessHost* child_process_host, 55 const BrowserChildProcessHost* child_process_host,
34 base::MemoryPressureListener::MemoryPressureLevel level); 56 base::MemoryPressureListener::MemoryPressureLevel level);
57
58 // Sends a memory pressure notification to the specified renderer process via
59 // its attached MemoryMessageFilter.
35 void SendPressureNotification( 60 void SendPressureNotification(
36 const RenderProcessHost* render_process_host, 61 const RenderProcessHost* render_process_host,
37 base::MemoryPressureListener::MemoryPressureLevel level); 62 base::MemoryPressureListener::MemoryPressureLevel level);
38 63
39 // This method can be called from any thread.
40 static MemoryPressureController* GetInstance();
41
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698