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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/memory_pressure_listener.h"
13 #include "base/memory/singleton.h"
14 #include "content/common/content_export.h"
18 class RenderWidgetHostViewAuraTest
;
20 class CONTENT_EXPORT RendererFrameManagerClient
{
22 virtual ~RendererFrameManagerClient() {}
23 virtual void EvictCurrentFrame() = 0;
26 // This class is responsible for globally managing which renderers keep their
27 // compositor frame when offscreen. We actively discard compositor frames for
28 // offscreen tabs, but keep a minimum amount, as an LRU cache, to make switching
29 // between a small set of tabs faster. The limit is a soft limit, because
30 // clients can lock their frame to prevent it from being discarded, e.g. if the
31 // tab is visible, or while capturing a screenshot.
32 class CONTENT_EXPORT RendererFrameManager
{
34 static RendererFrameManager
* GetInstance();
36 void AddFrame(RendererFrameManagerClient
*, bool locked
);
37 void RemoveFrame(RendererFrameManagerClient
*);
38 void LockFrame(RendererFrameManagerClient
*);
39 void UnlockFrame(RendererFrameManagerClient
*);
41 size_t GetMaxNumberOfSavedFrames() const;
44 void set_max_number_of_saved_frames(size_t max_number_of_saved_frames
) {
45 max_number_of_saved_frames_
= max_number_of_saved_frames
;
47 void set_max_handles(float max_handles
) { max_handles_
= max_handles
; }
50 // Please remove when crbug.com/443824 has been fixed.
51 friend class RenderWidgetHostViewAuraTest
;
53 RendererFrameManager();
54 ~RendererFrameManager();
55 void CullUnlockedFrames(size_t saved_frame_limit
);
57 // React on memory pressure events to adjust the number of cached frames.
58 void OnMemoryPressure(
59 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level
);
61 friend struct DefaultSingletonTraits
<RendererFrameManager
>;
63 // Listens for system under pressure notifications and adjusts number of
64 // cached frames accordingly.
65 base::MemoryPressureListener memory_pressure_listener_
;
67 std::map
<RendererFrameManagerClient
*, size_t> locked_frames_
;
68 std::list
<RendererFrameManagerClient
*> unlocked_frames_
;
69 size_t max_number_of_saved_frames_
;
72 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager
);
75 } // namespace content
77 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_