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

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, 5 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..6a746fafe0987581ebc68baabd212986208c3b08 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,11 @@ 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);
- if (it == shared_memory_map_.end())
- return base::SharedMemory::NULLHandle();
-
- base::SharedMemoryHandle renderer_handle;
- it->second->ShareToProcess(process, &renderer_handle);
- return renderer_handle;
+mojo::ScopedSharedBufferHandle
+DataFetcherSharedMemoryBase::GetSharedMemoryHandle(ConsumerType consumer_type) {
+ auto it = shared_memory_map_.find(consumer_type);
+ DCHECK(it != shared_memory_map_.end());
+ return it->second.first->Clone();
}
bool DataFetcherSharedMemoryBase::InitAndStartPollingThreadIfNecessary() {
@@ -222,34 +214,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 {

Powered by Google App Engine
This is Rietveld 408576698