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

Side by Side Diff: mojo/services/html_viewer/discardable_memory_allocator.h

Issue 1016493002: Add a DiscardableMemoryShmemeAllocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit tests 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_
6 #define MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_
7
8 #include <list>
9
10 #include "base/memory/discardable_memory_shmem_allocator.h"
11
12 namespace html_viewer {
13
14 // A discarable memory allocator which will unallocate chunks on new
15 // allocations.
16 class DiscardableMemoryAllocator
17 : public base::DiscardableMemoryShmemAllocator {
18 public:
19 class OwnedMemoryChunk;
jamesr 2015/03/17 23:26:19 does this forward declaration need to be public?
Elliot Glaysher 2015/03/18 20:36:22 It does if I want to hide the implementation of Di
20
21 DiscardableMemoryAllocator(size_t max_memory);
jamesr 2015/03/17 23:26:19 explicit
22 ~DiscardableMemoryAllocator() override;
23
24 // Overridden from DiscardableMemoryShmemAllocator:
25 scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory(
26 size_t size) override;
27
28 private:
29 friend class OwnedMemoryChunk;
30
31 void MoveToBack(std::list<OwnedMemoryChunk*>::iterator it);
32
33 // The amount of memory we can allocate before we try to free unlocked chunks.
34 const size_t max_memory_;
35
36 // A count of the sum of memory. Used to trigger discarding the oldest
37 // memory.
38 size_t total_live_memory_;
39
40 // A linked list of allocated chunks so that the tail is the newest chunks,
41 // and the head is the oldest chunks. On Lock()ing a chunk, it is sent to the
42 // back of this list.
43 std::list<OwnedMemoryChunk*> live_chunks_;
44
45 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator);
46 };
47
48 } // namespace html_viewer
49
50 #endif // MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698