Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / renderer_host / renderer_frame_manager.h
blob8a789ef22cc6d876dd432b5539cd7aac701d7840
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_
8 #include <list>
9 #include <map>
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"
16 namespace content {
18 class RenderWidgetHostViewAuraTest;
20 class CONTENT_EXPORT RendererFrameManagerClient {
21 public:
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 {
33 public:
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;
43 // For testing only
44 void set_max_handles(float max_handles) { max_handles_ = max_handles; }
46 private:
47 // Please remove when crbug.com/443824 has been fixed.
48 friend class RenderWidgetHostViewAuraTest;
50 RendererFrameManager();
51 ~RendererFrameManager();
52 void CullUnlockedFrames(size_t saved_frame_limit);
54 // React on memory pressure events to adjust the number of cached frames.
55 void OnMemoryPressure(
56 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
58 friend struct DefaultSingletonTraits<RendererFrameManager>;
60 // Listens for system under pressure notifications and adjusts number of
61 // cached frames accordingly.
62 base::MemoryPressureListener memory_pressure_listener_;
64 std::map<RendererFrameManagerClient*, size_t> locked_frames_;
65 std::list<RendererFrameManagerClient*> unlocked_frames_;
66 size_t max_number_of_saved_frames_;
67 float max_handles_;
69 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager);
72 } // namespace content
74 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_