OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 MemoryCoordinator_h | 5 #ifndef MemoryCoordinator_h |
6 #define MemoryCoordinator_h | 6 #define MemoryCoordinator_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 #include "platform/wtf/Noncopyable.h" | 10 #include "platform/wtf/Noncopyable.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 : public GarbageCollected<MemoryCoordinator> { | 32 : public GarbageCollected<MemoryCoordinator> { |
33 WTF_MAKE_NONCOPYABLE(MemoryCoordinator); | 33 WTF_MAKE_NONCOPYABLE(MemoryCoordinator); |
34 | 34 |
35 public: | 35 public: |
36 static MemoryCoordinator& Instance(); | 36 static MemoryCoordinator& Instance(); |
37 | 37 |
38 // Whether the device Blink runs on is a low-end device. | 38 // Whether the device Blink runs on is a low-end device. |
39 // Can be overridden in layout tests via internals. | 39 // Can be overridden in layout tests via internals. |
40 static bool IsLowEndDevice(); | 40 static bool IsLowEndDevice(); |
41 | 41 |
42 // Caches whether this device is a low-end device in a static member. | 42 // Returns the amount of physical memory in megabytes on the device. |
43 // instance() is not used as it's a heap allocated object - meaning it's not | 43 static int64_t GetPhysicalMemoryMB(); |
44 // thread-safe as well as might break tests counting the heap size. | 44 |
| 45 // Override the value of the physical memory for testing. |
| 46 static void SetPhysicalMemoryMBForTesting(int64_t); |
| 47 |
| 48 // Caches whether this device is a low-end device and the device physical |
| 49 // memory in static members. instance() is not used as it's a heap allocated |
| 50 // object - meaning it's not thread-safe as well as might break tests counting |
| 51 // the heap size. |
45 static void Initialize(); | 52 static void Initialize(); |
46 | 53 |
47 void RegisterClient(MemoryCoordinatorClient*); | 54 void RegisterClient(MemoryCoordinatorClient*); |
48 void UnregisterClient(MemoryCoordinatorClient*); | 55 void UnregisterClient(MemoryCoordinatorClient*); |
49 | 56 |
50 // TODO(bashi): Deprecating. Remove this when MemoryPressureListener is | 57 // TODO(bashi): Deprecating. Remove this when MemoryPressureListener is |
51 // gone. | 58 // gone. |
52 void OnMemoryPressure(WebMemoryPressureLevel); | 59 void OnMemoryPressure(WebMemoryPressureLevel); |
53 | 60 |
54 void OnMemoryStateChange(MemoryState); | 61 void OnMemoryStateChange(MemoryState); |
55 | 62 |
56 void OnPurgeMemory(); | 63 void OnPurgeMemory(); |
57 | 64 |
58 DECLARE_TRACE(); | 65 DECLARE_TRACE(); |
59 | 66 |
60 private: | 67 private: |
61 friend class Internals; | 68 friend class Internals; |
62 | 69 |
63 static void SetIsLowEndDeviceForTesting(bool); | 70 static void SetIsLowEndDeviceForTesting(bool); |
64 | 71 |
65 MemoryCoordinator(); | 72 MemoryCoordinator(); |
66 | 73 |
67 void ClearMemory(); | 74 void ClearMemory(); |
68 | 75 |
69 static bool is_low_end_device_; | 76 static bool is_low_end_device_; |
| 77 static int64_t physical_memory_mb_; |
70 | 78 |
71 HeapHashSet<WeakMember<MemoryCoordinatorClient>> clients_; | 79 HeapHashSet<WeakMember<MemoryCoordinatorClient>> clients_; |
72 }; | 80 }; |
73 | 81 |
74 } // namespace blink | 82 } // namespace blink |
75 | 83 |
76 #endif // MemoryCoordinator_h | 84 #endif // MemoryCoordinator_h |
OLD | NEW |