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

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 trybot errors Created 4 years, 1 month 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/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/discardable_memory_allocator.h" 11 #include "base/memory/discardable_memory_allocator.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/shared_memory_handle.h" 13 #include "base/memory/shared_memory_handle.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/trace_event/memory_dump_provider.h" 15 #include "base/trace_event/memory_dump_provider.h"
16 #include "components/discardable_memory/common/discardable_memory_export.h" 16 #include "components/discardable_memory/common/discardable_memory_export.h"
17 #include "components/discardable_memory/common/discardable_shared_memory_heap.h" 17 #include "components/discardable_memory/common/discardable_shared_memory_heap.h"
18 #include "components/discardable_memory/common/discardable_shared_memory_id.h" 18 #include "components/discardable_memory/public/interfaces/discardable_shared_mem ory_manager.mojom.h"
19
20 namespace base {
21 class SingleThreadTaskRunner;
22 }
19 23
20 namespace discardable_memory { 24 namespace discardable_memory {
21 25
22 // Implementation of DiscardableMemoryAllocator that allocates 26 // Implementation of DiscardableMemoryAllocator that allocates
23 // discardable memory segments through the browser process. 27 // discardable memory segments through the browser process.
24 class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager 28 class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager
25 : public base::DiscardableMemoryAllocator, 29 : public base::DiscardableMemoryAllocator,
26 public base::trace_event::MemoryDumpProvider { 30 public base::trace_event::MemoryDumpProvider {
27 public: 31 public:
28 class Delegate { 32 ClientDiscardableSharedMemoryManager(
29 public: 33 mojom::DiscardableSharedMemoryManagerPtrInfo info,
30 virtual void AllocateLockedDiscardableSharedMemory( 34 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; 35 ~ClientDiscardableSharedMemoryManager() override;
43 36
44 // Overridden from base::DiscardableMemoryAllocator: 37 // Overridden from base::DiscardableMemoryAllocator:
45 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( 38 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
46 size_t size) override; 39 size_t size) override;
47 40
48 // Overridden from base::trace_event::MemoryDumpProvider: 41 // Overridden from base::trace_event::MemoryDumpProvider:
49 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 42 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
50 base::trace_event::ProcessMemoryDump* pmd) override; 43 base::trace_event::ProcessMemoryDump* pmd) override;
51 44
(...skipping 11 matching lines...) Expand all
63 56
64 struct Statistics { 57 struct Statistics {
65 size_t total_size; 58 size_t total_size;
66 size_t freelist_size; 59 size_t freelist_size;
67 }; 60 };
68 61
69 Statistics GetStatistics() const; 62 Statistics GetStatistics() const;
70 63
71 private: 64 private:
72 std::unique_ptr<base::DiscardableSharedMemory> 65 std::unique_ptr<base::DiscardableSharedMemory>
73 AllocateLockedDiscardableSharedMemory(size_t size, 66 AllocateLockedDiscardableSharedMemory(size_t size, int32_t id);
74 DiscardableSharedMemoryId id); 67 void AllocateOnIOThread(
reveman 2016/11/18 05:26:50 nit: s/AllocateOnIOThread/AllocateOnIO/ as it's co
Peng 2016/11/18 16:28:28 Done.
68 size_t size,
69 int32_t id,
70 std::unique_ptr<base::DiscardableSharedMemory>* memory,
71 base::WaitableEvent* event);
72 void OnAllocateCompletedOnIOThread(
reveman 2016/11/18 05:26:50 nit: too many "On" :) I don't think we need the On
Peng 2016/11/18 16:28:28 Done.
73 std::unique_ptr<base::DiscardableSharedMemory>* memory,
74 base::WaitableEvent* event,
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 std::unique_ptr<mojom::DiscardableSharedMemoryManagerPtr> manager_;
reveman 2016/11/18 05:26:50 Can we rename this variable to have it be less con
Peng 2016/11/18 16:28:28 Done.
83
78 mutable base::Lock lock_; 84 mutable base::Lock lock_;
79 DiscardableSharedMemoryHeap heap_; 85 std::unique_ptr<DiscardableSharedMemoryHeap> heap_;
reveman 2016/11/18 05:26:50 why std::unique_ptr instead of allocated as part o
Peng 2016/11/18 16:28:28 The destructor of |heap_| may call DeletedDiscarda
reveman 2016/11/18 21:55:25 Got it. Can you add a comment where you reset this
80 Delegate* const delegate_;
81 86
82 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableSharedMemoryManager); 87 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableSharedMemoryManager);
83 }; 88 };
84 89
85 } // namespace discardable_memory 90 } // namespace discardable_memory
86 91
87 #endif // COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY _MANAGER_H_ 92 #endif // COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY _MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698