Index: components/discardable_memory/service/discardable_shared_memory_manager.h |
diff --git a/components/discardable_memory/service/discardable_shared_memory_manager.h b/components/discardable_memory/service/discardable_shared_memory_manager.h |
index 7ccadf18a44b3b1c68a540e9f4647b0d3778bd44..cb42cfb1b04f0738320b4327c57df2f1f40e5baf 100644 |
--- a/components/discardable_memory/service/discardable_shared_memory_manager.h |
+++ b/components/discardable_memory/service/discardable_shared_memory_manager.h |
@@ -27,7 +27,7 @@ |
#include "base/threading/thread_task_runner_handle.h" |
#include "base/trace_event/memory_dump_provider.h" |
#include "components/discardable_memory/common/discardable_memory_export.h" |
-#include "components/discardable_memory/common/discardable_shared_memory_id.h" |
+#include "components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom.h" |
namespace discardable_memory { |
@@ -44,9 +44,15 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager |
DiscardableSharedMemoryManager(); |
~DiscardableSharedMemoryManager() override; |
+ // Create a sigleton instance. |
+ static DiscardableSharedMemoryManager* CreateInstance(); |
+ |
// Returns a singleton instance. |
static DiscardableSharedMemoryManager* current(); |
reveman
2016/11/23 17:07:44
Please rename this to GetInstance() now that we ha
Peng
2016/11/24 15:04:37
Done.
|
+ // Bind the current manager to a mojo interface request. |
+ static void Bind(mojom::DiscardableSharedMemoryManagerRequest request); |
reveman
2016/11/23 17:07:44
Please make this a member function instead of stat
Peng
2016/11/24 15:04:37
Done.
|
+ |
// Overridden from base::DiscardableMemoryAllocator: |
std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
size_t size) override; |
@@ -55,20 +61,17 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager |
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
base::trace_event::ProcessMemoryDump* pmd) override; |
- // TODO(penghuang): Get ride of the |process_handle| when we switch to mojo. |
// This allocates a discardable memory segment for |process_handle|. |
// A valid shared memory handle is returned on success. |
void AllocateLockedDiscardableSharedMemoryForClient( |
- base::ProcessHandle process_handle, |
int client_id, |
size_t size, |
- DiscardableSharedMemoryId id, |
+ int32_t id, |
base::SharedMemoryHandle* shared_memory_handle); |
// Call this to notify the manager that client process associated with |
// |client_id| has deleted discardable memory segment with |id|. |
- void ClientDeletedDiscardableSharedMemory(DiscardableSharedMemoryId id, |
- int client_id); |
+ void ClientDeletedDiscardableSharedMemory(int32_t id, int client_id); |
// Call this to notify the manager that client associated with |client_id| |
// has been removed. The manager will use this to release memory segments |
@@ -111,15 +114,12 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager |
// base::MemoryCoordinatorClient implementation: |
void OnMemoryStateChange(base::MemoryState state) override; |
- // TODO(penghuang): Get ride of the |process_handle| when we switch to mojo. |
void AllocateLockedDiscardableSharedMemory( |
- base::ProcessHandle process_handle, |
int client_id, |
size_t size, |
- DiscardableSharedMemoryId id, |
+ int32_t id, |
base::SharedMemoryHandle* shared_memory_handle); |
- void DeletedDiscardableSharedMemory(DiscardableSharedMemoryId id, |
- int client_id); |
+ void DeletedDiscardableSharedMemory(int32_t id, int client_id); |
void OnMemoryPressure( |
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
void ReduceMemoryUsageUntilWithinMemoryLimit(); |
@@ -131,9 +131,10 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager |
virtual base::Time Now() const; |
virtual void ScheduleEnforceMemoryPolicy(); |
+ int32_t last_client_id_; |
reveman
2016/11/23 17:07:44
nit (optional): it's more common in chromium to us
Peng
2016/11/24 15:04:37
Done.
|
+ |
base::Lock lock_; |
- typedef base::hash_map<DiscardableSharedMemoryId, |
- scoped_refptr<MemorySegment>> |
+ typedef base::hash_map<int32_t, scoped_refptr<MemorySegment>> |
dcheng
2016/11/25 00:07:08
Nit: prefer using A = B; to typedef B A;
Peng
2016/11/25 16:41:53
Done.
|
MemorySegmentMap; |
typedef base::hash_map<int, MemorySegmentMap> ClientMap; |
ClientMap clients_; |