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

Unified Diff: content/browser/device_sensors/data_fetcher_shared_memory_base.cc

Issue 2037513002: Convert device_sensors to use mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@conversion--mime-registry
Patch Set: Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
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..dd38267c43a76d0f528489be2327eeb7a3c1f428 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->Clone();
}
bool DataFetcherSharedMemoryBase::InitAndStartPollingThreadIfNecessary() {
@@ -222,34 +216,25 @@ 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);
- if (it != shared_memory_map_.end())
- return it->second;
+ auto it = shared_memory_mapping_map_.find(consumer_type);
+ if (it != shared_memory_mapping_map_.end())
+ return it->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::SharedBuffer buffer(buffer_size);
+ mojo::ScopedSharedBufferMapping mapping = buffer.handle->Map(buffer_size);
+ if (!mapping)
+ return nullptr;
+ void* mem = mapping.get();
+ memset(mem, 0, buffer_size);
+ shared_memory_map_[consumer_type] = std::move(buffer.handle);
+ shared_memory_mapping_map_[consumer_type] = std::move(mapping);
+ return mem;
}
base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const {

Powered by Google App Engine
This is Rietveld 408576698