| 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 CONTENT_BROWSER_MEMORY_TEST_MEMORY_MONITOR_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_TEST_MEMORY_MONITOR_H_ |
| 6 #define CONTENT_BROWSER_MEMORY_TEST_MEMORY_MONITOR_H_ | 6 #define CONTENT_BROWSER_MEMORY_TEST_MEMORY_MONITOR_H_ |
| 7 | 7 |
| 8 #include "content/browser/memory/memory_monitor.h" | 8 #include "content/browser/memory/memory_monitor.h" |
| 9 | 9 |
| 10 #include "base/process/process_metrics.h" | 10 #include "base/process/process_metrics.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 // A delegate that allows mocking the various inputs to MemoryMonitor. | 14 // A delegate that allows mocking the various inputs to MemoryMonitor. |
| 15 class TestMemoryMonitorDelegate : public MemoryMonitorDelegate { | 15 class TestMemoryMonitorDelegate : public MemoryMonitorDelegate { |
| 16 public: | 16 public: |
| 17 TestMemoryMonitorDelegate() : calls_(0) { mem_info_ = {}; } | 17 TestMemoryMonitorDelegate() { mem_info_ = {}; } |
| 18 ~TestMemoryMonitorDelegate() override; | 18 ~TestMemoryMonitorDelegate() override; |
| 19 | 19 |
| 20 void GetSystemMemoryInfo(base::SystemMemoryInfoKB* mem_info) override; | 20 void GetSystemMemoryInfo(base::SystemMemoryInfoKB* mem_info) override; |
| 21 bool GetSystemMemoryPressure(int* mem_pressure) override; |
| 21 | 22 |
| 22 size_t calls() const { return calls_; } | 23 size_t calls() const { return calls_; } |
| 23 void ResetCalls() { calls_ = 0; } | 24 void ResetCalls() { calls_ = 0; } |
| 24 | 25 |
| 26 void SetMemoryPressure(int mem_pressure) { |
| 27 mem_pressure_ = mem_pressure; |
| 28 mem_pressure_valid_ = true; |
| 29 } |
| 30 |
| 25 void SetTotalMemoryKB(int total_memory_kb) { | 31 void SetTotalMemoryKB(int total_memory_kb) { |
| 26 mem_info_.total = total_memory_kb; | 32 mem_info_.total = total_memory_kb; |
| 27 } | 33 } |
| 28 | 34 |
| 29 protected: | 35 protected: |
| 30 // Because the fields of SystemMemoryInfoKB vary depending on the operating | 36 // Because the fields of SystemMemoryInfoKB vary depending on the operating |
| 31 // system, specific derived classes will have to provide methods to load | 37 // system, specific derived classes will have to provide methods to load |
| 32 // values into |mem_info_|; | 38 // values into |mem_info_|; |
| 33 base::SystemMemoryInfoKB mem_info_; | 39 base::SystemMemoryInfoKB mem_info_; |
| 34 | 40 |
| 35 private: | 41 private: |
| 36 size_t calls_; | 42 int mem_pressure_ = -1; |
| 43 int mem_pressure_valid_ = false; |
| 44 size_t calls_ = 0; |
| 37 | 45 |
| 38 DISALLOW_COPY_AND_ASSIGN(TestMemoryMonitorDelegate); | 46 DISALLOW_COPY_AND_ASSIGN(TestMemoryMonitorDelegate); |
| 39 }; | 47 }; |
| 40 | 48 |
| 41 } // namespace content | 49 } // namespace content |
| 42 | 50 |
| 43 #endif // CONTENT_BROWSER_MEMORY_TEST_MEMORY_MONITOR_H_ | 51 #endif // CONTENT_BROWSER_MEMORY_TEST_MEMORY_MONITOR_H_ |
| OLD | NEW |