| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 
| 6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 
| 7 | 7 | 
| 8 #include <bitset> |  | 
| 9 |  | 
| 10 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" | 
| 11 #include "base/containers/linked_list.h" | 9 #include "base/containers/linked_list.h" | 
| 12 #include "base/memory/linked_ptr.h" |  | 
| 13 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" | 
| 14 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" | 
| 15 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" | 
| 16 | 13 | 
| 17 namespace base { | 14 namespace base { | 
| 18 class DiscardableSharedMemory; | 15 class DiscardableSharedMemory; | 
| 19 } | 16 } | 
| 20 | 17 | 
| 21 namespace content { | 18 namespace content { | 
| 22 | 19 | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 61 | 58 | 
| 62   // Split an allocated span into two spans, one of length |blocks| followed | 59   // Split an allocated span into two spans, one of length |blocks| followed | 
| 63   // by another span of length "span->length - blocks" blocks. Modifies |span| | 60   // by another span of length "span->length - blocks" blocks. Modifies |span| | 
| 64   // to point to the first span of length |blocks|. Return second span. | 61   // to point to the first span of length |blocks|. Return second span. | 
| 65   scoped_ptr<Span> Split(Span* span, size_t blocks); | 62   scoped_ptr<Span> Split(Span* span, size_t blocks); | 
| 66 | 63 | 
| 67   // Search free list for span that satisfies the request for |blocks| of | 64   // Search free list for span that satisfies the request for |blocks| of | 
| 68   // memory. If found, the span is removed from the free list and returned. | 65   // memory. If found, the span is removed from the free list and returned. | 
| 69   scoped_ptr<Span> SearchFreeList(size_t blocks); | 66   scoped_ptr<Span> SearchFreeList(size_t blocks); | 
| 70 | 67 | 
| 71   // Release shared memory segments that have been purged. Returns bytes of | 68   // Release free shared memory segments. | 
| 72   // memory that were released. | 69   void ReleaseFreeMemory(); | 
| 73   size_t ReleaseFreeMemory(); | 70 | 
|  | 71   // Release shared memory segments that have been purged. | 
|  | 72   void ReleasePurgedMemory(); | 
|  | 73 | 
|  | 74   // Returns total bytes of memory in heap. | 
|  | 75   size_t GetSize() const; | 
|  | 76 | 
|  | 77   // Returns bytes of memory currently in the free list. | 
|  | 78   size_t GetFreeListSize() const; | 
| 74 | 79 | 
| 75  private: | 80  private: | 
|  | 81   class ScopedMemorySegment { | 
|  | 82    public: | 
|  | 83     ScopedMemorySegment(DiscardableSharedMemoryHeap* heap, | 
|  | 84                         scoped_ptr<base::DiscardableSharedMemory> shared_memory, | 
|  | 85                         size_t size); | 
|  | 86     ~ScopedMemorySegment(); | 
|  | 87 | 
|  | 88     bool IsUsed() const; | 
|  | 89     bool IsResident() const; | 
|  | 90 | 
|  | 91    private: | 
|  | 92     DiscardableSharedMemoryHeap* const heap_; | 
|  | 93     scoped_ptr<base::DiscardableSharedMemory> shared_memory_; | 
|  | 94     const size_t size_; | 
|  | 95 | 
|  | 96     DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment); | 
|  | 97   }; | 
|  | 98 | 
| 76   scoped_ptr<Span> RemoveFromFreeList(Span* span); | 99   scoped_ptr<Span> RemoveFromFreeList(Span* span); | 
| 77   scoped_ptr<Span> Carve(Span* span, size_t blocks); | 100   scoped_ptr<Span> Carve(Span* span, size_t blocks); | 
| 78   void RegisterSpan(Span* span); | 101   void RegisterSpan(Span* span); | 
| 79   void UnregisterSpan(Span* span); | 102   void UnregisterSpan(Span* span); | 
| 80   void ReleaseMemory(base::DiscardableSharedMemory* shared_memory); | 103   bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory, | 
|  | 104                     size_t size); | 
|  | 105   bool IsMemoryResident(const base::DiscardableSharedMemory* shared_memory); | 
|  | 106   void ReleaseMemory(const base::DiscardableSharedMemory* shared_memory, | 
|  | 107                      size_t size); | 
| 81 | 108 | 
| 82   size_t block_size_; | 109   size_t block_size_; | 
|  | 110   size_t num_blocks_; | 
|  | 111   size_t num_free_blocks_; | 
| 83 | 112 | 
| 84   // Discardable shared memory instances. | 113   // Vector of memory segments. | 
| 85   ScopedVector<base::DiscardableSharedMemory> shared_memory_segments_; | 114   ScopedVector<ScopedMemorySegment> memory_segments_; | 
| 86 | 115 | 
| 87   // Mapping from first/last block of span to Span instance. | 116   // Mapping from first/last block of span to Span instance. | 
| 88   typedef base::hash_map<size_t, Span*> SpanMap; | 117   typedef base::hash_map<size_t, Span*> SpanMap; | 
| 89   SpanMap spans_; | 118   SpanMap spans_; | 
| 90 | 119 | 
| 91   // Linked-list of free discardable memory regions. | 120   // Linked-list of free discardable memory regions. | 
| 92   base::LinkedList<Span> free_spans_; | 121   base::LinkedList<Span> free_spans_; | 
| 93 | 122 | 
| 94   DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); | 123   DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); | 
| 95 }; | 124 }; | 
| 96 | 125 | 
| 97 }  // namespace content | 126 }  // namespace content | 
| 98 | 127 | 
| 99 #endif  // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 128 #endif  // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 
| OLD | NEW | 
|---|