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

Unified Diff: device/generic_sensor/platform_sensor_provider_base.cc

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Pass task runner to PlatformSensor constructor 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..fd43614d4816896155af189f2a845322c82b6ef2 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, GetSharedBufferOffset(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));
}
@@ -109,4 +109,11 @@ void PlatformSensorProviderBase::NotifySensorCreated(
requests_map_.erase(type);
}
+uint64_t PlatformSensorProviderBase::GetSharedBufferOffset(
Ken Rockot(use gerrit already) 2016/10/10 16:02:08 nit: This doesn't need to be a member function at
Mikhail 2016/10/10 18:29:20 Thanks for hint! I've moved it here from sensor_im
+ mojom::SensorType type) {
+ return (static_cast<uint64_t>(mojom::SensorType::LAST) -
+ static_cast<uint64_t>(type)) *
+ kReadingBufferSize;
+}
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698