Chromium Code Reviews| 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 #ifndef COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_MONITOR_H_ | 5 #ifndef COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_MONITOR_H_ |
| 6 #define COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_MONITOR_H_ | 6 #define COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_MONITOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/memory_coordinator/common/memory_coordinator_export.h" | 11 #include "components/memory_coordinator/common/memory_coordinator_export.h" |
| 12 | 12 |
| 13 namespace base { | |
| 14 struct SystemMemoryInfoKB; | |
| 15 } | |
| 16 | |
| 13 namespace memory_coordinator { | 17 namespace memory_coordinator { |
| 14 | 18 |
| 19 // A class for fetching system information used by a memory monitor. This can | |
|
chrisha
2016/09/07 21:25:09
I'd move this to below the MemoryMonitor definitio
bcwhite
2016/09/08 16:36:49
Done.
| |
| 20 // be subclassed for testing or if a particular MemoryMonitor implementation | |
| 21 // needs additional functionality. | |
| 22 class MEMORY_COORDINATOR_EXPORT MemoryMonitorDelegate { | |
| 23 public: | |
| 24 MemoryMonitorDelegate() {} | |
| 25 virtual ~MemoryMonitorDelegate(); | |
| 26 | |
| 27 // Returns system memory information. | |
| 28 virtual void GetSystemMemoryInfo(base::SystemMemoryInfoKB* mem_info); | |
| 29 | |
| 30 private: | |
| 31 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorDelegate); | |
| 32 }; | |
| 33 | |
| 15 // A simple class that monitors the amount of free memory available on a system. | 34 // A simple class that monitors the amount of free memory available on a system. |
| 16 // This is an interface to facilitate dependency injection for testing. | 35 // This is an interface to facilitate dependency injection for testing. |
| 17 class MEMORY_COORDINATOR_EXPORT MemoryMonitor { | 36 class MEMORY_COORDINATOR_EXPORT MemoryMonitor { |
| 18 public: | 37 public: |
| 19 MemoryMonitor() {} | 38 MemoryMonitor() {} |
| 20 virtual ~MemoryMonitor() {} | 39 virtual ~MemoryMonitor() {} |
| 21 | 40 |
| 22 // Returns the amount of free memory available on the system until the system | 41 // Returns the amount of free memory available on the system until the system |
| 23 // will be in a critical state. Critical is as defined by the OS (swapping | 42 // will be in a critical state. Critical is as defined by the OS (swapping |
| 24 // will occur, or physical memory will run out, etc). It is possible for this | 43 // will occur, or physical memory will run out, etc). It is possible for this |
| 25 // to return negative values, in which case that much memory would have to be | 44 // to return negative values, in which case that much memory would have to be |
| 26 // freed in order to exit a critical memory state. | 45 // freed in order to exit a critical memory state. |
| 27 virtual int GetFreeMemoryUntilCriticalMB() = 0; | 46 virtual int GetFreeMemoryUntilCriticalMB() = 0; |
| 28 | 47 |
| 29 private: | 48 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(MemoryMonitor); | 49 DISALLOW_COPY_AND_ASSIGN(MemoryMonitor); |
| 31 }; | 50 }; |
| 32 | 51 |
| 33 // Factory function for creating a monitor for the current platform. | 52 // Factory function for creating a monitor for the current platform. |
| 34 MEMORY_COORDINATOR_EXPORT std::unique_ptr<MemoryMonitor> CreateMemoryMonitor(); | 53 MEMORY_COORDINATOR_EXPORT std::unique_ptr<MemoryMonitor> CreateMemoryMonitor(); |
| 35 | 54 |
| 36 } // namespace memory_coordinator | 55 } // namespace memory_coordinator |
| 37 | 56 |
| 38 #endif // COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_MONITOR_H_ | 57 #endif // COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_MONITOR_H_ |
| OLD | NEW |