OLD | NEW |
---|---|
(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 #include "content/browser/renderer_host/renderer_frame_manager.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/sys_info.h" | |
9 | |
10 namespace content { | |
11 | |
12 //////////////////////////////////////////////////////////////////////////////// | |
danakj
2013/10/28 21:39:21
What's up with these comment things? Is this a c/b
piman
2013/10/28 22:08:38
Not particularly, but I removed from here where it
| |
13 // RendererFrameManager | |
14 | |
15 RendererFrameManager* RendererFrameManager::GetInstance() { | |
16 return Singleton<RendererFrameManager>::get(); | |
17 } | |
18 | |
19 void RendererFrameManager::AddFrame(RendererFrameManagerClient* frame, | |
20 bool visible) { | |
21 RemoveFrame(frame); | |
22 if (visible) | |
23 visible_frames_.insert(frame); | |
24 else | |
25 hidden_frames_.push_front(frame); | |
26 CullHiddenFrames(); | |
27 } | |
28 | |
29 void RendererFrameManager::RemoveFrame(RendererFrameManagerClient* frame) { | |
30 visible_frames_.erase(frame); | |
31 hidden_frames_.remove(frame); | |
32 } | |
33 | |
34 void RendererFrameManager::SetFrameVisibility(RendererFrameManagerClient* frame, | |
35 bool visible) { | |
36 if (visible) { | |
37 hidden_frames_.remove(frame); | |
38 visible_frames_.insert(frame); | |
39 } else { | |
40 visible_frames_.erase(frame); | |
41 hidden_frames_.push_front(frame); | |
42 CullHiddenFrames(); | |
43 } | |
44 } | |
45 | |
46 RendererFrameManager::RendererFrameManager() | |
47 : max_number_of_saved_frames_( | |
48 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256))) {} | |
49 | |
50 RendererFrameManager::~RendererFrameManager() {} | |
51 | |
52 void RendererFrameManager::CullHiddenFrames() { | |
53 while (!hidden_frames_.empty() && | |
54 hidden_frames_.size() + visible_frames_.size() > | |
55 max_number_of_saved_frames()) { | |
56 size_t old_size = hidden_frames_.size(); | |
57 // Should remove self from list. | |
58 hidden_frames_.back()->EvictCurrentFrame(); | |
59 DCHECK_EQ(hidden_frames_.size() + 1, old_size); | |
60 } | |
61 } | |
62 | |
63 } // namespace content | |
OLD | NEW |