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

Unified Diff: device/generic_sensor/platform_sensor_provider_base.cc

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Test compilation fix + comment from Ken Created 4 years, 2 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: device/generic_sensor/platform_sensor_provider_base.cc
diff --git a/device/generic_sensor/platform_sensor_provider_base.cc b/device/generic_sensor/platform_sensor_provider_base.cc
index 4447cea93390f47f19655eaafcec4aae56e58c51..6dd94dbea5ec819a89d80e849461397219163d3a 100644
--- a/device/generic_sensor/platform_sensor_provider_base.cc
+++ b/device/generic_sensor/platform_sensor_provider_base.cc
@@ -13,9 +13,9 @@ namespace device {
namespace {
+const uint64_t kReadingBufferSize = sizeof(SensorReadingSharedBuffer);
const uint64_t kSharedBufferSizeInBytes =
- mojom::SensorInitParams::kReadBufferSize *
- static_cast<uint64_t>(mojom::SensorType::LAST);
+ kReadingBufferSize * static_cast<uint64_t>(mojom::SensorType::LAST);
} // namespace
@@ -24,8 +24,6 @@ PlatformSensorProviderBase::~PlatformSensorProviderBase() = default;
void PlatformSensorProviderBase::CreateSensor(
mojom::SensorType type,
- uint64_t size,
- uint64_t offset,
const CreateSensorCallback& callback) {
DCHECK(CalledOnValidThread());
@@ -34,8 +32,8 @@ void PlatformSensorProviderBase::CreateSensor(
return;
}
- mojo::ScopedSharedBufferMapping mapping =
- shared_buffer_handle_->MapAtOffset(size, offset);
+ mojo::ScopedSharedBufferMapping mapping = shared_buffer_handle_->MapAtOffset(
+ kReadingBufferSize, SensorReadingSharedBuffer::GetOffset(type));
if (!mapping) {
callback.Run(nullptr);
return;
@@ -44,11 +42,13 @@ void PlatformSensorProviderBase::CreateSensor(
auto it = requests_map_.find(type);
if (it != requests_map_.end()) {
it->second.push_back(callback);
- } else {
+ } else { // This is the first CreateSensor call.
+ memset(mapping.get(), 0, kReadingBufferSize);
+
requests_map_[type] = CallbackQueue({callback});
CreateSensorInternal(
- type, std::move(mapping), size,
+ type, std::move(mapping),
base::Bind(&PlatformSensorProviderBase::NotifySensorCreated,
base::Unretained(this), type));
}
« no previous file with comments | « device/generic_sensor/platform_sensor_provider_base.h ('k') | device/generic_sensor/platform_sensor_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698