Index: content/browser/device_sensors/data_fetcher_shared_memory_base.cc |
diff --git a/content/browser/device_sensors/data_fetcher_shared_memory_base.cc b/content/browser/device_sensors/data_fetcher_shared_memory_base.cc |
index 053807680fd4f211a38492dbfd3e89b54f4da4d4..314331e48be1ae6c911b829370e5f689e94c5ab1 100644 |
--- a/content/browser/device_sensors/data_fetcher_shared_memory_base.cc |
+++ b/content/browser/device_sensors/data_fetcher_shared_memory_base.cc |
@@ -119,9 +119,6 @@ DataFetcherSharedMemoryBase::~DataFetcherSharedMemoryBase() { |
// make sure polling thread stops asap. |
if (polling_thread_) |
polling_thread_->Stop(); |
- |
- STLDeleteContainerPairSecondPointers(shared_memory_map_.begin(), |
- shared_memory_map_.end()); |
} |
bool DataFetcherSharedMemoryBase::StartFetchingDeviceData( |
@@ -183,16 +180,13 @@ void DataFetcherSharedMemoryBase::Shutdown() { |
StopFetchingDeviceData(CONSUMER_TYPE_LIGHT); |
} |
-base::SharedMemoryHandle |
-DataFetcherSharedMemoryBase::GetSharedMemoryHandleForProcess( |
- ConsumerType consumer_type, base::ProcessHandle process) { |
- SharedMemoryMap::const_iterator it = shared_memory_map_.find(consumer_type); |
+mojo::ScopedSharedBufferHandle |
+DataFetcherSharedMemoryBase::GetSharedMemoryHandle(ConsumerType consumer_type) { |
+ auto it = shared_memory_map_.find(consumer_type); |
if (it == shared_memory_map_.end()) |
- return base::SharedMemory::NULLHandle(); |
+ return mojo::ScopedSharedBufferHandle(); |
- base::SharedMemoryHandle renderer_handle; |
- it->second->ShareToProcess(process, &renderer_handle); |
- return renderer_handle; |
+ return it->second.first->Clone(); |
} |
bool DataFetcherSharedMemoryBase::InitAndStartPollingThreadIfNecessary() { |
@@ -222,34 +216,26 @@ base::TimeDelta DataFetcherSharedMemoryBase::GetInterval() const { |
return base::TimeDelta::FromMicroseconds(kInertialSensorIntervalMicroseconds); |
} |
-base::SharedMemory* DataFetcherSharedMemoryBase::GetSharedMemory( |
+void* DataFetcherSharedMemoryBase::GetSharedMemoryBuffer( |
ConsumerType consumer_type) { |
- SharedMemoryMap::const_iterator it = shared_memory_map_.find(consumer_type); |
+ auto it = shared_memory_map_.find(consumer_type); |
if (it != shared_memory_map_.end()) |
- return it->second; |
+ return it->second.second.get(); |
size_t buffer_size = GetConsumerSharedMemoryBufferSize(consumer_type); |
if (buffer_size == 0) |
return nullptr; |
- std::unique_ptr<base::SharedMemory> new_shared_mem(new base::SharedMemory); |
- if (new_shared_mem->CreateAndMapAnonymous(buffer_size)) { |
- if (void* mem = new_shared_mem->memory()) { |
- memset(mem, 0, buffer_size); |
- base::SharedMemory* shared_mem = new_shared_mem.release(); |
- shared_memory_map_[consumer_type] = shared_mem; |
- return shared_mem; |
- } |
- } |
- LOG(ERROR) << "Failed to initialize shared memory"; |
- return nullptr; |
-} |
- |
-void* DataFetcherSharedMemoryBase::GetSharedMemoryBuffer( |
- ConsumerType consumer_type) { |
- if (base::SharedMemory* shared_memory = GetSharedMemory(consumer_type)) |
- return shared_memory->memory(); |
- return nullptr; |
+ mojo::ScopedSharedBufferHandle buffer = |
+ mojo::SharedBufferHandle::Create(buffer_size); |
+ mojo::ScopedSharedBufferMapping mapping = buffer->Map(buffer_size); |
+ if (!mapping) |
+ return nullptr; |
+ void* mem = mapping.get(); |
+ memset(mem, 0, buffer_size); |
+ shared_memory_map_[consumer_type] = |
+ std::make_pair(std::move(buffer), std::move(mapping)); |
+ return mem; |
} |
base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |