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

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

Issue 1045433002: Migrate ChromeOS to base::MemoryPressureMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 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
« no previous file with comments | « content/browser/memory_pressure_observer.cc ('k') | content/content_browser.gypi » ('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 #include "content/browser/renderer_host/renderer_frame_manager.h" 5 #include "content/browser/renderer_host/renderer_frame_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/memory_pressure_listener.h" 11 #include "base/memory/memory_pressure_listener.h"
12 #include "base/memory/memory_pressure_monitor.h"
12 #include "base/memory/shared_memory.h" 13 #include "base/memory/shared_memory.h"
13 #include "base/sys_info.h" 14 #include "base/sys_info.h"
14 #include "content/common/host_shared_bitmap_manager.h" 15 #include "content/common/host_shared_bitmap_manager.h"
15 16
16 #if defined(OS_CHROMEOS)
17 #include "base/chromeos/memory_pressure_observer_chromeos.h"
18 #include "content/browser/browser_main_loop.h"
19 #endif
20
21 namespace content { 17 namespace content {
22 namespace { 18 namespace {
23 19
24 const int kModeratePressurePercentage = 50; 20 const int kModeratePressurePercentage = 50;
25 const int kCriticalPressurePercentage = 10; 21 const int kCriticalPressurePercentage = 10;
26 22
27 } // namespace 23 } // namespace
28 24
29 RendererFrameManager* RendererFrameManager::GetInstance() { 25 RendererFrameManager* RendererFrameManager::GetInstance() {
30 return Singleton<RendererFrameManager>::get(); 26 return Singleton<RendererFrameManager>::get();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (locked_count > 1) { 64 if (locked_count > 1) {
69 locked_frames_[frame]--; 65 locked_frames_[frame]--;
70 } else { 66 } else {
71 RemoveFrame(frame); 67 RemoveFrame(frame);
72 unlocked_frames_.push_front(frame); 68 unlocked_frames_.push_front(frame);
73 CullUnlockedFrames(GetMaxNumberOfSavedFrames()); 69 CullUnlockedFrames(GetMaxNumberOfSavedFrames());
74 } 70 }
75 } 71 }
76 72
77 size_t RendererFrameManager::GetMaxNumberOfSavedFrames() const { 73 size_t RendererFrameManager::GetMaxNumberOfSavedFrames() const {
78 #if defined(OS_CHROMEOS) 74 base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get();
79 content::BrowserMainLoop* browser_main_loop =
80 content::BrowserMainLoop::GetInstance();
81 75
82 // Unit tests can come here without a BrowserMainLoop instance. 76 if (!monitor)
83 if (!browser_main_loop)
84 return max_number_of_saved_frames_;
85
86 base::MemoryPressureObserverChromeOS* observer =
87 browser_main_loop->memory_pressure_observer();
88
89 if (!observer)
90 return max_number_of_saved_frames_; 77 return max_number_of_saved_frames_;
91 78
92 // Until we have a global OnMemoryPressureChanged event we need to query the 79 // Until we have a global OnMemoryPressureChanged event we need to query the
93 // value from our specific pressure observer. 80 // value from our specific pressure monitor.
94 int percentage = 100; 81 int percentage = 100;
95 switch (observer->GetCurrentPressureLevel()) { 82 switch (monitor->GetCurrentPressureLevel()) {
96 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: 83 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
97 percentage = 100; 84 percentage = 100;
98 break; 85 break;
99 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: 86 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
100 percentage = kModeratePressurePercentage; 87 percentage = kModeratePressurePercentage;
101 break; 88 break;
102 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: 89 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
103 percentage = kCriticalPressurePercentage; 90 percentage = kCriticalPressurePercentage;
104 break; 91 break;
105 } 92 }
106 size_t frames = (max_number_of_saved_frames_ * percentage) / 100; 93 size_t frames = (max_number_of_saved_frames_ * percentage) / 100;
107 return std::max(static_cast<size_t>(1), frames); 94 return std::max(static_cast<size_t>(1), frames);
108 #else
109 return max_number_of_saved_frames_;
110 #endif
111 } 95 }
112 96
113 RendererFrameManager::RendererFrameManager() 97 RendererFrameManager::RendererFrameManager()
114 : memory_pressure_listener_( 98 : memory_pressure_listener_(
115 base::Bind(&RendererFrameManager::OnMemoryPressure, 99 base::Bind(&RendererFrameManager::OnMemoryPressure,
116 base::Unretained(this))) { 100 base::Unretained(this))) {
117 // Note: With the destruction of this class the |memory_pressure_listener_| 101 // Note: With the destruction of this class the |memory_pressure_listener_|
118 // gets destroyed and the observer will remove itself. 102 // gets destroyed and the observer will remove itself.
119 max_number_of_saved_frames_ = 103 max_number_of_saved_frames_ =
120 #if defined(OS_ANDROID) 104 #if defined(OS_ANDROID)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 percentage = kCriticalPressurePercentage; 145 percentage = kCriticalPressurePercentage;
162 break; 146 break;
163 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: 147 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
164 // No need to change anything when there is no pressure. 148 // No need to change anything when there is no pressure.
165 return; 149 return;
166 } 150 }
167 CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100)); 151 CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100));
168 } 152 }
169 153
170 } // namespace content 154 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory_pressure_observer.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698