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

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: fix chromeos compile 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
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 #if defined(OS_CHROMEOS)
17 #include "base/chromeos/memory_pressure_observer_chromeos.h"
18 #include "content/browser/browser_main_loop.h" 18 #include "content/browser/browser_main_loop.h"
Mr4D (OOO till 08-26) 2015/04/13 15:10:52 This can go. (with the OS_CHROMEOS) part.
dmichael (off chromium) 2015/04/13 21:02:15 Done.
19 #endif 19 #endif
20 20
21 namespace content { 21 namespace content {
22 namespace { 22 namespace {
23 23
24 const int kModeratePressurePercentage = 50; 24 const int kModeratePressurePercentage = 50;
25 const int kCriticalPressurePercentage = 10; 25 const int kCriticalPressurePercentage = 10;
26 26
27 } // namespace 27 } // namespace
28 28
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (locked_count > 1) { 68 if (locked_count > 1) {
69 locked_frames_[frame]--; 69 locked_frames_[frame]--;
70 } else { 70 } else {
71 RemoveFrame(frame); 71 RemoveFrame(frame);
72 unlocked_frames_.push_front(frame); 72 unlocked_frames_.push_front(frame);
73 CullUnlockedFrames(GetMaxNumberOfSavedFrames()); 73 CullUnlockedFrames(GetMaxNumberOfSavedFrames());
74 } 74 }
75 } 75 }
76 76
77 size_t RendererFrameManager::GetMaxNumberOfSavedFrames() const { 77 size_t RendererFrameManager::GetMaxNumberOfSavedFrames() const {
78 #if defined(OS_CHROMEOS) 78 #if defined(OS_CHROMEOS)
Mr4D (OOO till 08-26) 2015/04/13 15:10:52 I think that you do not want here #if defined(OS_C
dmichael (off chromium) 2015/04/13 21:02:16 I was aiming for minimizing the change here so we
79 content::BrowserMainLoop* browser_main_loop = 79 content::BrowserMainLoop* browser_main_loop =
80 content::BrowserMainLoop::GetInstance(); 80 content::BrowserMainLoop::GetInstance();
Mr4D (OOO till 08-26) 2015/04/13 15:10:52 You do not need the browser_main_loop anymore.
dmichael (off chromium) 2015/04/13 21:02:16 Ah, thanks. Done.
81 81
82 // Unit tests can come here without a BrowserMainLoop instance. 82 // Unit tests can come here without a BrowserMainLoop instance.
83 if (!browser_main_loop) 83 if (!browser_main_loop)
84 return max_number_of_saved_frames_; 84 return max_number_of_saved_frames_;
85 85
86 base::MemoryPressureObserverChromeOS* observer = 86 base::MemoryPressureMonitor* monitor = base::MemoryPressureMonitor::Get();
87 browser_main_loop->memory_pressure_observer();
88 87
89 if (!observer) 88 if (!monitor)
90 return max_number_of_saved_frames_; 89 return max_number_of_saved_frames_;
91 90
92 // Until we have a global OnMemoryPressureChanged event we need to query the 91 // Until we have a global OnMemoryPressureChanged event we need to query the
93 // value from our specific pressure observer. 92 // value from our specific pressure monitor.
94 int percentage = 100; 93 int percentage = 100;
95 switch (observer->GetCurrentPressureLevel()) { 94 switch (monitor->GetCurrentPressureLevel()) {
96 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: 95 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
97 percentage = 100; 96 percentage = 100;
98 break; 97 break;
99 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: 98 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
100 percentage = kModeratePressurePercentage; 99 percentage = kModeratePressurePercentage;
101 break; 100 break;
102 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: 101 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
103 percentage = kCriticalPressurePercentage; 102 percentage = kCriticalPressurePercentage;
104 break; 103 break;
105 } 104 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 percentage = kCriticalPressurePercentage; 160 percentage = kCriticalPressurePercentage;
162 break; 161 break;
163 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: 162 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
164 // No need to change anything when there is no pressure. 163 // No need to change anything when there is no pressure.
165 return; 164 return;
166 } 165 }
167 CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100)); 166 CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100));
168 } 167 }
169 168
170 } // namespace content 169 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698