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

Side by Side Diff: content/renderer/render_process_discardable_memory_provider.h

Issue 15650016: [Not for review] Discardable memory emulation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "base/hash_tables.h"
6 #include "base/memory/discardable_memory.h"
7 #include "content/common/content_export.h"
8 #include "content/renderer/render_process_visibility_manager.h"
9
10 #if defined(COMPILER_GCC)
11 namespace base { class DiscardableMemory; }
12
13 namespace BASE_HASH_NAMESPACE {
14 template <>
15 struct hash<const base::DiscardableMemory*> {
16 size_t operator()(const base::DiscardableMemory* ptr) const {
17 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
18 }
19 };
20 } // namespace BASE_HASH_NAMESPACE
21 #endif // COMPILER
22
23 namespace content {
24
25 class CONTENT_EXPORT RenderProcessDiscardableMemoryProvider
26 : public base::DiscardableMemoryProvider,
27 public RenderProcessVisibilityObserver {
28 public:
29 RenderProcessDiscardableMemoryProvider();
30 virtual ~RenderProcessDiscardableMemoryProvider();
31
32 private:
33 struct AllocatedMemory {
34 void* memory;
35 bool locked;
36 size_t size;
37 };
38
39 // RenderProcessVisibilityObserver implementation.
40 virtual void RenderProcessVisibilityChanged(bool visible) OVERRIDE;
41
42 // base::DiscardableMemoryProvider implementation.
43 virtual bool Register(
44 const base::DiscardableMemory* discardable, size_t size) OVERRIDE;
45 virtual void Unregister(const base::DiscardableMemory* discardable) OVERRIDE;
46 virtual base::LockDiscardableMemoryStatus Lock(
47 const base::DiscardableMemory* discardable) OVERRIDE;
48 virtual void Unlock(const base::DiscardableMemory* discardable) OVERRIDE;
49 virtual void* Memory(
50 const base::DiscardableMemory* discardable) const OVERRIDE;
51 virtual bool PurgeForTestingSupported() const OVERRIDE;
52 virtual void PurgeForTesting() OVERRIDE;
53
54 void Purge();
55 void EnforcePolicy();
56
57 typedef
58 base::hash_map<const base::DiscardableMemory*, AllocatedMemory>
59 AllocationMap;
60
61 AllocationMap allocations_;
62 bool visible_;
63
64 DISALLOW_COPY_AND_ASSIGN(RenderProcessDiscardableMemoryProvider);
65 };
66
67 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698