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

Side by Side Diff: components/discardable_memory/client/client_discardable_shared_memory_manager.h

Issue 2545523007: Revert of discardable_memory: Using mojo IPC to replace Chrome IPC (Closed)
Patch Set: Created 4 years 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 COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY_MA NAGER_H_ 5 #ifndef COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY_MA NAGER_H_
6 #define COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY_MA NAGER_H_ 6 #define COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY_MA NAGER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/callback_helpers.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/memory/discardable_memory_allocator.h" 11 #include "base/memory/discardable_memory_allocator.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/memory/shared_memory_handle.h" 13 #include "base/memory/shared_memory_handle.h"
15 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
16 #include "base/trace_event/memory_dump_provider.h" 15 #include "base/trace_event/memory_dump_provider.h"
17 #include "components/discardable_memory/common/discardable_memory_export.h" 16 #include "components/discardable_memory/common/discardable_memory_export.h"
18 #include "components/discardable_memory/common/discardable_shared_memory_heap.h" 17 #include "components/discardable_memory/common/discardable_shared_memory_heap.h"
19 #include "components/discardable_memory/public/interfaces/discardable_shared_mem ory_manager.mojom.h" 18 #include "components/discardable_memory/common/discardable_shared_memory_id.h"
20
21 namespace base {
22 class SingleThreadTaskRunner;
23 }
24 19
25 namespace discardable_memory { 20 namespace discardable_memory {
26 21
27 // Implementation of DiscardableMemoryAllocator that allocates 22 // Implementation of DiscardableMemoryAllocator that allocates
28 // discardable memory segments through the browser process. 23 // discardable memory segments through the browser process.
29 class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager 24 class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager
30 : public base::DiscardableMemoryAllocator, 25 : public base::DiscardableMemoryAllocator,
31 public base::trace_event::MemoryDumpProvider { 26 public base::trace_event::MemoryDumpProvider {
32 public: 27 public:
33 ClientDiscardableSharedMemoryManager( 28 class Delegate {
34 mojom::DiscardableSharedMemoryManagerPtr manager, 29 public:
35 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); 30 virtual void AllocateLockedDiscardableSharedMemory(
31 size_t size,
32 DiscardableSharedMemoryId id,
33 base::SharedMemoryHandle* handle) = 0;
34 virtual void DeletedDiscardableSharedMemory(
35 DiscardableSharedMemoryId id) = 0;
36
37 protected:
38 virtual ~Delegate() {}
39 };
40
41 explicit ClientDiscardableSharedMemoryManager(Delegate* delegate);
36 ~ClientDiscardableSharedMemoryManager() override; 42 ~ClientDiscardableSharedMemoryManager() override;
37 43
38 // Overridden from base::DiscardableMemoryAllocator: 44 // Overridden from base::DiscardableMemoryAllocator:
39 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( 45 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
40 size_t size) override; 46 size_t size) override;
41 47
42 // Overridden from base::trace_event::MemoryDumpProvider: 48 // Overridden from base::trace_event::MemoryDumpProvider:
43 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 49 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
44 base::trace_event::ProcessMemoryDump* pmd) override; 50 base::trace_event::ProcessMemoryDump* pmd) override;
45 51
(...skipping 11 matching lines...) Expand all
57 63
58 struct Statistics { 64 struct Statistics {
59 size_t total_size; 65 size_t total_size;
60 size_t freelist_size; 66 size_t freelist_size;
61 }; 67 };
62 68
63 Statistics GetStatistics() const; 69 Statistics GetStatistics() const;
64 70
65 private: 71 private:
66 std::unique_ptr<base::DiscardableSharedMemory> 72 std::unique_ptr<base::DiscardableSharedMemory>
67 AllocateLockedDiscardableSharedMemory(size_t size, int32_t id); 73 AllocateLockedDiscardableSharedMemory(size_t size,
68 void AllocateOnIO(size_t size, 74 DiscardableSharedMemoryId id);
69 int32_t id,
70 std::unique_ptr<base::DiscardableSharedMemory>* memory,
71 base::ScopedClosureRunner closure_runner);
72 void AllocateCompletedOnIO(
73 std::unique_ptr<base::DiscardableSharedMemory>* memory,
74 base::ScopedClosureRunner closure_runner,
75 mojo::ScopedSharedBufferHandle mojo_handle);
76
77 void DeletedDiscardableSharedMemory(int32_t id);
78 void MemoryUsageChanged(size_t new_bytes_allocated, 75 void MemoryUsageChanged(size_t new_bytes_allocated,
79 size_t new_bytes_free) const; 76 size_t new_bytes_free) const;
80 77
81 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
82 std::unique_ptr<mojom::DiscardableSharedMemoryManagerPtr> manager_mojo_;
83
84 mutable base::Lock lock_; 78 mutable base::Lock lock_;
85 std::unique_ptr<DiscardableSharedMemoryHeap> heap_; 79 DiscardableSharedMemoryHeap heap_;
80 Delegate* const delegate_;
86 81
87 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableSharedMemoryManager); 82 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableSharedMemoryManager);
88 }; 83 };
89 84
90 } // namespace discardable_memory 85 } // namespace discardable_memory
91 86
92 #endif // COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY _MANAGER_H_ 87 #endif // COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY _MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698