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

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

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

Powered by Google App Engine
This is Rietveld 408576698