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

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

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

Powered by Google App Engine
This is Rietveld 408576698