Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: content/common/discardable_shared_memory_heap.h

Issue 1009203004: content: Add DeletedDiscardableSharedMemory IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: avoid updating trace counter and crash key unless bytes allocated changed Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/callback.h"
8 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
9 #include "base/containers/linked_list.h" 10 #include "base/containers/linked_list.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
12 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
13 14
14 namespace base { 15 namespace base {
15 class DiscardableSharedMemory; 16 class DiscardableSharedMemory;
16 } 17 }
17 18
(...skipping 23 matching lines...) Expand all
41 size_t length_; 42 size_t length_;
42 43
43 DISALLOW_COPY_AND_ASSIGN(Span); 44 DISALLOW_COPY_AND_ASSIGN(Span);
44 }; 45 };
45 46
46 explicit DiscardableSharedMemoryHeap(size_t block_size); 47 explicit DiscardableSharedMemoryHeap(size_t block_size);
47 ~DiscardableSharedMemoryHeap(); 48 ~DiscardableSharedMemoryHeap();
48 49
49 // Grow heap using |shared_memory| and return a span for this new memory. 50 // Grow heap using |shared_memory| and return a span for this new memory.
50 // |shared_memory| must be aligned to the block size and |size| must be a 51 // |shared_memory| must be aligned to the block size and |size| must be a
51 // multiple of the block size. 52 // multiple of the block size. |deleted_callback| is called when
53 // |shared_memory| has been deleted.
52 scoped_ptr<Span> Grow(scoped_ptr<base::DiscardableSharedMemory> shared_memory, 54 scoped_ptr<Span> Grow(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
53 size_t size); 55 size_t size,
56 const base::Closure& deleted_callback);
54 57
55 // Merge |span| into the free lists. This will coalesce |span| with 58 // Merge |span| into the free lists. This will coalesce |span| with
56 // neighboring free spans when possible. 59 // neighboring free spans when possible.
57 void MergeIntoFreeLists(scoped_ptr<Span> span); 60 void MergeIntoFreeLists(scoped_ptr<Span> span);
58 61
59 // Split an allocated span into two spans, one of length |blocks| followed 62 // Split an allocated span into two spans, one of length |blocks| followed
60 // by another span of length "span->length - blocks" blocks. Modifies |span| 63 // by another span of length "span->length - blocks" blocks. Modifies |span|
61 // to point to the first span of length |blocks|. Return second span. 64 // to point to the first span of length |blocks|. Return second span.
62 scoped_ptr<Span> Split(Span* span, size_t blocks); 65 scoped_ptr<Span> Split(Span* span, size_t blocks);
63 66
(...skipping 14 matching lines...) Expand all
78 size_t GetSize() const; 81 size_t GetSize() const;
79 82
80 // Returns bytes of memory currently in the free lists. 83 // Returns bytes of memory currently in the free lists.
81 size_t GetSizeOfFreeLists() const; 84 size_t GetSizeOfFreeLists() const;
82 85
83 private: 86 private:
84 class ScopedMemorySegment { 87 class ScopedMemorySegment {
85 public: 88 public:
86 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap, 89 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap,
87 scoped_ptr<base::DiscardableSharedMemory> shared_memory, 90 scoped_ptr<base::DiscardableSharedMemory> shared_memory,
88 size_t size); 91 size_t size,
92 const base::Closure& deleted_callback);
89 ~ScopedMemorySegment(); 93 ~ScopedMemorySegment();
90 94
91 bool IsUsed() const; 95 bool IsUsed() const;
92 bool IsResident() const; 96 bool IsResident() const;
93 97
94 private: 98 private:
95 DiscardableSharedMemoryHeap* const heap_; 99 DiscardableSharedMemoryHeap* const heap_;
96 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; 100 scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
97 const size_t size_; 101 const size_t size_;
102 const base::Closure deleted_callback_;
98 103
99 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment); 104 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment);
100 }; 105 };
101 106
102 void InsertIntoFreeList(scoped_ptr<Span> span); 107 void InsertIntoFreeList(scoped_ptr<Span> span);
103 scoped_ptr<Span> RemoveFromFreeList(Span* span); 108 scoped_ptr<Span> RemoveFromFreeList(Span* span);
104 scoped_ptr<Span> Carve(Span* span, size_t blocks); 109 scoped_ptr<Span> Carve(Span* span, size_t blocks);
105 void RegisterSpan(Span* span); 110 void RegisterSpan(Span* span);
106 void UnregisterSpan(Span* span); 111 void UnregisterSpan(Span* span);
107 bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory, 112 bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory,
(...skipping 18 matching lines...) Expand all
126 // is a free list of runs that consist of k blocks. The 256th entry is a 131 // is a free list of runs that consist of k blocks. The 256th entry is a
127 // free list of runs that have length >= 256 blocks. 132 // free list of runs that have length >= 256 blocks.
128 base::LinkedList<Span> free_spans_[256]; 133 base::LinkedList<Span> free_spans_[256];
129 134
130 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); 135 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap);
131 }; 136 };
132 137
133 } // namespace content 138 } // namespace content
134 139
135 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ 140 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698