OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/memory/memory_monitor_win.h" | 5 #include "content/browser/memory/memory_monitor_win.h" |
6 | 6 |
7 #include "base/process/process_metrics.h" | 7 #include "base/process/process_metrics.h" |
8 | 8 |
9 // TODO(chrisha): Implement a mechanism for observing swapping, and updating the | 9 // TODO(chrisha): Implement a mechanism for observing swapping, and updating the |
10 // memory threshold on a per machine basis. | 10 // memory threshold on a per machine basis. |
(...skipping 26 matching lines...) Expand all Loading... |
37 // available memory, paging until that is the case. | 37 // available memory, paging until that is the case. |
38 const int MemoryMonitorWin::kLargeMemoryTargetFreeMB = 400; | 38 const int MemoryMonitorWin::kLargeMemoryTargetFreeMB = 400; |
39 | 39 |
40 MemoryMonitorWin::MemoryMonitorWin(MemoryMonitorDelegate* delegate, | 40 MemoryMonitorWin::MemoryMonitorWin(MemoryMonitorDelegate* delegate, |
41 int target_free_mb) | 41 int target_free_mb) |
42 : delegate_(delegate), target_free_mb_(target_free_mb) {} | 42 : delegate_(delegate), target_free_mb_(target_free_mb) {} |
43 | 43 |
44 int MemoryMonitorWin::GetFreeMemoryUntilCriticalMB() { | 44 int MemoryMonitorWin::GetFreeMemoryUntilCriticalMB() { |
45 base::SystemMemoryInfoKB mem_info = {}; | 45 base::SystemMemoryInfoKB mem_info = {}; |
46 delegate_->GetSystemMemoryInfo(&mem_info); | 46 delegate_->GetSystemMemoryInfo(&mem_info); |
47 int free_mb = mem_info.avail_phys / kKBperMB; | 47 int free_mb = mem_info.free / kKBperMB; |
48 free_mb -= target_free_mb_; | 48 free_mb -= target_free_mb_; |
49 return free_mb; | 49 return free_mb; |
50 } | 50 } |
51 | 51 |
52 // static | 52 // static |
53 std::unique_ptr<MemoryMonitorWin> MemoryMonitorWin::Create( | 53 std::unique_ptr<MemoryMonitorWin> MemoryMonitorWin::Create( |
54 MemoryMonitorDelegate* delegate) { | 54 MemoryMonitorDelegate* delegate) { |
55 return std::unique_ptr<MemoryMonitorWin>(new MemoryMonitorWin( | 55 return std::unique_ptr<MemoryMonitorWin>(new MemoryMonitorWin( |
56 delegate, GetTargetFreeMB(delegate))); | 56 delegate, GetTargetFreeMB(delegate))); |
57 } | 57 } |
(...skipping 12 matching lines...) Expand all Loading... |
70 return MemoryMonitorWin::kLargeMemoryTargetFreeMB; | 70 return MemoryMonitorWin::kLargeMemoryTargetFreeMB; |
71 return MemoryMonitorWin::kSmallMemoryTargetFreeMB; | 71 return MemoryMonitorWin::kSmallMemoryTargetFreeMB; |
72 } | 72 } |
73 | 73 |
74 // Implementation of factory function defined in memory_monitor.h. | 74 // Implementation of factory function defined in memory_monitor.h. |
75 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { | 75 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { |
76 return MemoryMonitorWin::Create(&g_memory_monitor_win_delegate); | 76 return MemoryMonitorWin::Create(&g_memory_monitor_win_delegate); |
77 } | 77 } |
78 | 78 |
79 } // namespace content | 79 } // namespace content |
OLD | NEW |