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

Side by Side Diff: content/browser/renderer_host/renderer_frame_manager.h

Issue 2358433003: Make RendererFrameManager a client of memory coordinator (Closed)
Patch Set: Use MemoryCoordinatorProxy::GetCurrentMemoryState Created 4 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/renderer_host/renderer_frame_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/memory_coordinator_client.h"
14 #include "base/memory/memory_pressure_listener.h" 15 #include "base/memory/memory_pressure_listener.h"
15 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 class RenderWidgetHostViewAuraTest; 21 class RenderWidgetHostViewAuraTest;
21 22
22 class CONTENT_EXPORT RendererFrameManagerClient { 23 class CONTENT_EXPORT RendererFrameManagerClient {
23 public: 24 public:
24 virtual ~RendererFrameManagerClient() {} 25 virtual ~RendererFrameManagerClient() {}
25 virtual void EvictCurrentFrame() = 0; 26 virtual void EvictCurrentFrame() = 0;
26 }; 27 };
27 28
28 // This class is responsible for globally managing which renderers keep their 29 // This class is responsible for globally managing which renderers keep their
29 // compositor frame when offscreen. We actively discard compositor frames for 30 // compositor frame when offscreen. We actively discard compositor frames for
30 // offscreen tabs, but keep a minimum amount, as an LRU cache, to make switching 31 // offscreen tabs, but keep a minimum amount, as an LRU cache, to make switching
31 // between a small set of tabs faster. The limit is a soft limit, because 32 // between a small set of tabs faster. The limit is a soft limit, because
32 // clients can lock their frame to prevent it from being discarded, e.g. if the 33 // clients can lock their frame to prevent it from being discarded, e.g. if the
33 // tab is visible, or while capturing a screenshot. 34 // tab is visible, or while capturing a screenshot.
34 class CONTENT_EXPORT RendererFrameManager { 35 class CONTENT_EXPORT RendererFrameManager :
36 public base::MemoryCoordinatorClient {
35 public: 37 public:
36 static RendererFrameManager* GetInstance(); 38 static RendererFrameManager* GetInstance();
37 39
38 void AddFrame(RendererFrameManagerClient*, bool locked); 40 void AddFrame(RendererFrameManagerClient*, bool locked);
39 void RemoveFrame(RendererFrameManagerClient*); 41 void RemoveFrame(RendererFrameManagerClient*);
40 void LockFrame(RendererFrameManagerClient*); 42 void LockFrame(RendererFrameManagerClient*);
41 void UnlockFrame(RendererFrameManagerClient*); 43 void UnlockFrame(RendererFrameManagerClient*);
42 44
43 size_t GetMaxNumberOfSavedFrames() const; 45 size_t GetMaxNumberOfSavedFrames() const;
44 46
45 // For testing only 47 // For testing only
46 void set_max_number_of_saved_frames(size_t max_number_of_saved_frames) { 48 void set_max_number_of_saved_frames(size_t max_number_of_saved_frames) {
47 max_number_of_saved_frames_ = max_number_of_saved_frames; 49 max_number_of_saved_frames_ = max_number_of_saved_frames;
48 } 50 }
49 void set_max_handles(float max_handles) { max_handles_ = max_handles; } 51 void set_max_handles(float max_handles) { max_handles_ = max_handles; }
50 52
51 private: 53 private:
52 // Please remove when crbug.com/443824 has been fixed. 54 // Please remove when crbug.com/443824 has been fixed.
53 friend class RenderWidgetHostViewAuraTest; 55 friend class RenderWidgetHostViewAuraTest;
54 56
55 RendererFrameManager(); 57 RendererFrameManager();
56 ~RendererFrameManager(); 58 ~RendererFrameManager() override;
59
60 // base::MemoryCoordinatorClient implementation:
61 void OnMemoryStateChange(base::MemoryState state) override;
62
57 void CullUnlockedFrames(size_t saved_frame_limit); 63 void CullUnlockedFrames(size_t saved_frame_limit);
58 64
59 // React on memory pressure events to adjust the number of cached frames. 65 // React on memory pressure events to adjust the number of cached frames.
60 void OnMemoryPressure( 66 void OnMemoryPressure(
61 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); 67 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
62 68
69 void PurgeMemory(int percentage);
70
63 friend struct base::DefaultSingletonTraits<RendererFrameManager>; 71 friend struct base::DefaultSingletonTraits<RendererFrameManager>;
64 72
65 // Listens for system under pressure notifications and adjusts number of 73 // Listens for system under pressure notifications and adjusts number of
66 // cached frames accordingly. 74 // cached frames accordingly.
67 base::MemoryPressureListener memory_pressure_listener_; 75 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
68 76
69 std::map<RendererFrameManagerClient*, size_t> locked_frames_; 77 std::map<RendererFrameManagerClient*, size_t> locked_frames_;
70 std::list<RendererFrameManagerClient*> unlocked_frames_; 78 std::list<RendererFrameManagerClient*> unlocked_frames_;
71 size_t max_number_of_saved_frames_; 79 size_t max_number_of_saved_frames_;
72 float max_handles_; 80 float max_handles_;
73 81
74 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager); 82 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager);
75 }; 83 };
76 84
77 } // namespace content 85 } // namespace content
78 86
79 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ 87 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/renderer_frame_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698