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