summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/device_sensors/device_light_message_filter.cc43
-rw-r--r--content/browser/device_sensors/device_light_message_filter.h12
-rw-r--r--content/browser/device_sensors/device_motion_message_filter.cc45
-rw-r--r--content/browser/device_sensors/device_motion_message_filter.h12
-rw-r--r--content/browser/device_sensors/device_orientation_absolute_message_filter.cc42
-rw-r--r--content/browser/device_sensors/device_orientation_absolute_message_filter.h13
-rw-r--r--content/browser/device_sensors/device_orientation_message_filter.cc47
-rw-r--r--content/browser/device_sensors/device_orientation_message_filter.h12
-rw-r--r--content/browser/device_sensors/device_sensor_message_filter.cc44
-rw-r--r--content/browser/device_sensors/device_sensor_message_filter.h40
-rw-r--r--content/content_browser.gypi2
11 files changed, 131 insertions, 181 deletions
diff --git a/content/browser/device_sensors/device_light_message_filter.cc b/content/browser/device_sensors/device_light_message_filter.cc
index 797b3ea..dda05a8 100644
--- a/content/browser/device_sensors/device_light_message_filter.cc
+++ b/content/browser/device_sensors/device_light_message_filter.cc
@@ -4,57 +4,28 @@
#include "content/browser/device_sensors/device_light_message_filter.h"
-#include "content/browser/device_sensors/device_inertial_sensor_service.h"
#include "content/common/device_sensors/device_light_messages.h"
namespace content {
DeviceLightMessageFilter::DeviceLightMessageFilter()
- : BrowserMessageFilter(DeviceLightMsgStart), is_started_(false) {
-}
+ : DeviceSensorMessageFilter(CONSUMER_TYPE_LIGHT, DeviceLightMsgStart) {}
-DeviceLightMessageFilter::~DeviceLightMessageFilter() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (is_started_) {
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_LIGHT);
- }
-}
+DeviceLightMessageFilter::~DeviceLightMessageFilter() {}
bool DeviceLightMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DeviceLightMessageFilter, message)
- IPC_MESSAGE_HANDLER(DeviceLightHostMsg_StartPolling,
- OnDeviceLightStartPolling)
- IPC_MESSAGE_HANDLER(DeviceLightHostMsg_StopPolling, OnDeviceLightStopPolling)
+ IPC_MESSAGE_HANDLER(DeviceLightHostMsg_StartPolling, OnStartPolling)
+ IPC_MESSAGE_HANDLER(DeviceLightHostMsg_StopPolling, OnStopPolling)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void DeviceLightMessageFilter::OnDeviceLightStartPolling() {
- DCHECK(!is_started_);
- if (is_started_)
- return;
- is_started_ = true;
- DeviceInertialSensorService::GetInstance()->AddConsumer(CONSUMER_TYPE_LIGHT);
- DidStartDeviceLightPolling();
-}
-
-void DeviceLightMessageFilter::OnDeviceLightStopPolling() {
- DCHECK(is_started_);
- if (!is_started_)
- return;
- is_started_ = false;
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_LIGHT);
-}
-
-void DeviceLightMessageFilter::DidStartDeviceLightPolling() {
- Send(new DeviceLightMsg_DidStartPolling(
- DeviceInertialSensorService::GetInstance()
- ->GetSharedMemoryHandleForProcess(CONSUMER_TYPE_LIGHT,
- PeerHandle())));
+void DeviceLightMessageFilter::DidStartPolling(
+ base::SharedMemoryHandle handle) {
+ Send(new DeviceLightMsg_DidStartPolling(handle));
}
} // namespace content
diff --git a/content/browser/device_sensors/device_light_message_filter.h b/content/browser/device_sensors/device_light_message_filter.h
index 5824693..bf302b7 100644
--- a/content/browser/device_sensors/device_light_message_filter.h
+++ b/content/browser/device_sensors/device_light_message_filter.h
@@ -5,12 +5,11 @@
#ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_LIGHT_MESSAGE_FILTER_H_
#define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_LIGHT_MESSAGE_FILTER_H_
-#include "base/macros.h"
-#include "content/public/browser/browser_message_filter.h"
+#include "content/browser/device_sensors/device_sensor_message_filter.h"
namespace content {
-class DeviceLightMessageFilter : public BrowserMessageFilter {
+class DeviceLightMessageFilter : public DeviceSensorMessageFilter {
public:
DeviceLightMessageFilter();
@@ -20,11 +19,8 @@ class DeviceLightMessageFilter : public BrowserMessageFilter {
private:
~DeviceLightMessageFilter() override;
- void OnDeviceLightStartPolling();
- void OnDeviceLightStopPolling();
- void DidStartDeviceLightPolling();
-
- bool is_started_;
+ // DeviceSensorMessageFilter implementation.
+ void DidStartPolling(base::SharedMemoryHandle handle) override;
DISALLOW_COPY_AND_ASSIGN(DeviceLightMessageFilter);
};
diff --git a/content/browser/device_sensors/device_motion_message_filter.cc b/content/browser/device_sensors/device_motion_message_filter.cc
index f874ea4..58a2b51 100644
--- a/content/browser/device_sensors/device_motion_message_filter.cc
+++ b/content/browser/device_sensors/device_motion_message_filter.cc
@@ -4,59 +4,28 @@
#include "content/browser/device_sensors/device_motion_message_filter.h"
-#include "content/browser/device_sensors/device_inertial_sensor_service.h"
#include "content/common/device_sensors/device_motion_messages.h"
namespace content {
DeviceMotionMessageFilter::DeviceMotionMessageFilter()
- : BrowserMessageFilter(DeviceMotionMsgStart),
- is_started_(false) {
-}
+ : DeviceSensorMessageFilter(CONSUMER_TYPE_MOTION, DeviceMotionMsgStart) {}
-DeviceMotionMessageFilter::~DeviceMotionMessageFilter() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (is_started_)
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_MOTION);
-}
+DeviceMotionMessageFilter::~DeviceMotionMessageFilter() {}
bool DeviceMotionMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DeviceMotionMessageFilter, message)
- IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling,
- OnDeviceMotionStartPolling)
- IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling,
- OnDeviceMotionStopPolling)
+ IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StartPolling, OnStartPolling)
+ IPC_MESSAGE_HANDLER(DeviceMotionHostMsg_StopPolling, OnStopPolling)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void DeviceMotionMessageFilter::OnDeviceMotionStartPolling() {
- DCHECK(!is_started_);
- if (is_started_)
- return;
- is_started_ = true;
- DeviceInertialSensorService::GetInstance()->AddConsumer(
- CONSUMER_TYPE_MOTION);
- DidStartDeviceMotionPolling();
-}
-
-void DeviceMotionMessageFilter::OnDeviceMotionStopPolling() {
- DCHECK(is_started_);
- if (!is_started_)
- return;
- is_started_ = false;
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_MOTION);
-}
-
-void DeviceMotionMessageFilter::DidStartDeviceMotionPolling() {
- Send(new DeviceMotionMsg_DidStartPolling(
- DeviceInertialSensorService::GetInstance()->
- GetSharedMemoryHandleForProcess(
- CONSUMER_TYPE_MOTION, PeerHandle())));
+void DeviceMotionMessageFilter::DidStartPolling(
+ base::SharedMemoryHandle handle) {
+ Send(new DeviceMotionMsg_DidStartPolling(handle));
}
} // namespace content
diff --git a/content/browser/device_sensors/device_motion_message_filter.h b/content/browser/device_sensors/device_motion_message_filter.h
index 36eb42a..3b0587d 100644
--- a/content/browser/device_sensors/device_motion_message_filter.h
+++ b/content/browser/device_sensors/device_motion_message_filter.h
@@ -5,12 +5,11 @@
#ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_MOTION_MESSAGE_FILTER_H_
#define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_MOTION_MESSAGE_FILTER_H_
-#include "base/macros.h"
-#include "content/public/browser/browser_message_filter.h"
+#include "content/browser/device_sensors/device_sensor_message_filter.h"
namespace content {
-class DeviceMotionMessageFilter : public BrowserMessageFilter {
+class DeviceMotionMessageFilter : public DeviceSensorMessageFilter {
public:
DeviceMotionMessageFilter();
@@ -20,11 +19,8 @@ class DeviceMotionMessageFilter : public BrowserMessageFilter {
private:
~DeviceMotionMessageFilter() override;
- void OnDeviceMotionStartPolling();
- void OnDeviceMotionStopPolling();
- void DidStartDeviceMotionPolling();
-
- bool is_started_;
+ // DeviceSensorMessageFilter implementation.
+ void DidStartPolling(base::SharedMemoryHandle handle) override;
DISALLOW_COPY_AND_ASSIGN(DeviceMotionMessageFilter);
};
diff --git a/content/browser/device_sensors/device_orientation_absolute_message_filter.cc b/content/browser/device_sensors/device_orientation_absolute_message_filter.cc
index 572952c..3aa6042 100644
--- a/content/browser/device_sensors/device_orientation_absolute_message_filter.cc
+++ b/content/browser/device_sensors/device_orientation_absolute_message_filter.cc
@@ -4,24 +4,16 @@
#include "content/browser/device_sensors/device_orientation_absolute_message_filter.h"
-#include "content/browser/device_sensors/device_inertial_sensor_service.h"
#include "content/common/device_sensors/device_orientation_messages.h"
namespace content {
DeviceOrientationAbsoluteMessageFilter::DeviceOrientationAbsoluteMessageFilter()
- : BrowserMessageFilter(DeviceOrientationMsgStart),
- is_started_(false) {
-}
+ : DeviceSensorMessageFilter(CONSUMER_TYPE_ORIENTATION_ABSOLUTE,
+ DeviceOrientationMsgStart) {}
DeviceOrientationAbsoluteMessageFilter::
- ~DeviceOrientationAbsoluteMessageFilter() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (is_started_) {
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_ORIENTATION_ABSOLUTE);
- }
-}
+ ~DeviceOrientationAbsoluteMessageFilter() {}
bool DeviceOrientationAbsoluteMessageFilter::OnMessageReceived(
const IPC::Message& message) {
@@ -36,31 +28,9 @@ bool DeviceOrientationAbsoluteMessageFilter::OnMessageReceived(
return handled;
}
-void DeviceOrientationAbsoluteMessageFilter::OnStartPolling() {
- DCHECK(!is_started_);
- if (is_started_)
- return;
- is_started_ = true;
- DeviceInertialSensorService::GetInstance()->AddConsumer(
- CONSUMER_TYPE_ORIENTATION_ABSOLUTE);
- DidStartPolling();
-}
-
-void DeviceOrientationAbsoluteMessageFilter::OnStopPolling() {
- DCHECK(is_started_);
- if (!is_started_)
- return;
- is_started_ = false;
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_ORIENTATION_ABSOLUTE);
-}
-
-void DeviceOrientationAbsoluteMessageFilter::DidStartPolling() {
- Send(new DeviceOrientationAbsoluteMsg_DidStartPolling(
- DeviceInertialSensorService::GetInstance()->
- GetSharedMemoryHandleForProcess(
- CONSUMER_TYPE_ORIENTATION_ABSOLUTE,
- PeerHandle())));
+void DeviceOrientationAbsoluteMessageFilter::DidStartPolling(
+ base::SharedMemoryHandle handle) {
+ Send(new DeviceOrientationAbsoluteMsg_DidStartPolling(handle));
}
} // namespace content
diff --git a/content/browser/device_sensors/device_orientation_absolute_message_filter.h b/content/browser/device_sensors/device_orientation_absolute_message_filter.h
index 5ed5ac5..5e64bf8f 100644
--- a/content/browser/device_sensors/device_orientation_absolute_message_filter.h
+++ b/content/browser/device_sensors/device_orientation_absolute_message_filter.h
@@ -5,12 +5,12 @@
#ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_ORIENTATION_ABSOLUTE_MESSAGE_FILTER_H_
#define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_ORIENTATION_ABSOLUTE_MESSAGE_FILTER_H_
-#include "base/macros.h"
-#include "content/public/browser/browser_message_filter.h"
+#include "content/browser/device_sensors/device_sensor_message_filter.h"
namespace content {
-class DeviceOrientationAbsoluteMessageFilter : public BrowserMessageFilter {
+class DeviceOrientationAbsoluteMessageFilter
+ : public DeviceSensorMessageFilter {
public:
DeviceOrientationAbsoluteMessageFilter();
@@ -20,11 +20,8 @@ class DeviceOrientationAbsoluteMessageFilter : public BrowserMessageFilter {
private:
~DeviceOrientationAbsoluteMessageFilter() override;
- void OnStartPolling();
- void OnStopPolling();
- void DidStartPolling();
-
- bool is_started_;
+ // DeviceSensorMessageFilter implementation.
+ void DidStartPolling(base::SharedMemoryHandle handle) override;
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationAbsoluteMessageFilter);
};
diff --git a/content/browser/device_sensors/device_orientation_message_filter.cc b/content/browser/device_sensors/device_orientation_message_filter.cc
index 63a9d62..9b0aeb8 100644
--- a/content/browser/device_sensors/device_orientation_message_filter.cc
+++ b/content/browser/device_sensors/device_orientation_message_filter.cc
@@ -4,61 +4,30 @@
#include "content/browser/device_sensors/device_orientation_message_filter.h"
-#include "content/browser/device_sensors/device_inertial_sensor_service.h"
#include "content/common/device_sensors/device_orientation_messages.h"
namespace content {
DeviceOrientationMessageFilter::DeviceOrientationMessageFilter()
- : BrowserMessageFilter(DeviceOrientationMsgStart),
- is_started_(false) {
-}
+ : DeviceSensorMessageFilter(CONSUMER_TYPE_ORIENTATION,
+ DeviceOrientationMsgStart) {}
-DeviceOrientationMessageFilter::~DeviceOrientationMessageFilter() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (is_started_)
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_ORIENTATION);
-}
+DeviceOrientationMessageFilter::~DeviceOrientationMessageFilter() {}
bool DeviceOrientationMessageFilter::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DeviceOrientationMessageFilter, message)
- IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartPolling,
- OnDeviceOrientationStartPolling)
- IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopPolling,
- OnDeviceOrientationStopPolling)
+ IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartPolling, OnStartPolling)
+ IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopPolling, OnStopPolling)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void DeviceOrientationMessageFilter::OnDeviceOrientationStartPolling() {
- DCHECK(!is_started_);
- if (is_started_)
- return;
- is_started_ = true;
- DeviceInertialSensorService::GetInstance()->AddConsumer(
- CONSUMER_TYPE_ORIENTATION);
- DidStartDeviceOrientationPolling();
-}
-
-void DeviceOrientationMessageFilter::OnDeviceOrientationStopPolling() {
- DCHECK(is_started_);
- if (!is_started_)
- return;
- is_started_ = false;
- DeviceInertialSensorService::GetInstance()->RemoveConsumer(
- CONSUMER_TYPE_ORIENTATION);
-}
-
-void DeviceOrientationMessageFilter::DidStartDeviceOrientationPolling() {
- Send(new DeviceOrientationMsg_DidStartPolling(
- DeviceInertialSensorService::GetInstance()->
- GetSharedMemoryHandleForProcess(
- CONSUMER_TYPE_ORIENTATION,
- PeerHandle())));
+void DeviceOrientationMessageFilter::DidStartPolling(
+ base::SharedMemoryHandle handle) {
+ Send(new DeviceOrientationMsg_DidStartPolling(handle));
}
} // namespace content
diff --git a/content/browser/device_sensors/device_orientation_message_filter.h b/content/browser/device_sensors/device_orientation_message_filter.h
index fb375d9..21e4453 100644
--- a/content/browser/device_sensors/device_orientation_message_filter.h
+++ b/content/browser/device_sensors/device_orientation_message_filter.h
@@ -5,12 +5,11 @@
#ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_ORIENTATION_MESSAGE_FILTER_H_
#define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_ORIENTATION_MESSAGE_FILTER_H_
-#include "base/macros.h"
-#include "content/public/browser/browser_message_filter.h"
+#include "content/browser/device_sensors/device_sensor_message_filter.h"
namespace content {
-class DeviceOrientationMessageFilter : public BrowserMessageFilter {
+class DeviceOrientationMessageFilter : public DeviceSensorMessageFilter {
public:
DeviceOrientationMessageFilter();
@@ -20,11 +19,8 @@ class DeviceOrientationMessageFilter : public BrowserMessageFilter {
private:
~DeviceOrientationMessageFilter() override;
- void OnDeviceOrientationStartPolling();
- void OnDeviceOrientationStopPolling();
- void DidStartDeviceOrientationPolling();
-
- bool is_started_;
+ // DeviceSensorMessageFilter implementation.
+ void DidStartPolling(base::SharedMemoryHandle handle) override;
DISALLOW_COPY_AND_ASSIGN(DeviceOrientationMessageFilter);
};
diff --git a/content/browser/device_sensors/device_sensor_message_filter.cc b/content/browser/device_sensors/device_sensor_message_filter.cc
new file mode 100644
index 0000000..cb9e9e5
--- /dev/null
+++ b/content/browser/device_sensors/device_sensor_message_filter.cc
@@ -0,0 +1,44 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/device_sensors/device_sensor_message_filter.h"
+
+#include "content/browser/device_sensors/device_inertial_sensor_service.h"
+
+namespace content {
+
+DeviceSensorMessageFilter::DeviceSensorMessageFilter(
+ ConsumerType consumer_type, uint32_t message_class_to_filter)
+ : BrowserMessageFilter(message_class_to_filter),
+ consumer_type_(consumer_type),
+ is_started_(false) {
+}
+
+DeviceSensorMessageFilter::~DeviceSensorMessageFilter() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (is_started_)
+ DeviceInertialSensorService::GetInstance()->RemoveConsumer(consumer_type_);
+}
+
+void DeviceSensorMessageFilter::OnStartPolling() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(!is_started_);
+ if (is_started_)
+ return;
+ is_started_ = true;
+ DeviceInertialSensorService::GetInstance()->AddConsumer(consumer_type_);
+ DidStartPolling(DeviceInertialSensorService::GetInstance()->
+ GetSharedMemoryHandleForProcess(consumer_type_, PeerHandle()));
+}
+
+void DeviceSensorMessageFilter::OnStopPolling() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(is_started_);
+ if (!is_started_)
+ return;
+ is_started_ = false;
+ DeviceInertialSensorService::GetInstance()->RemoveConsumer(consumer_type_);
+}
+
+} // namespace content
diff --git a/content/browser/device_sensors/device_sensor_message_filter.h b/content/browser/device_sensors/device_sensor_message_filter.h
new file mode 100644
index 0000000..13d0b0a
--- /dev/null
+++ b/content/browser/device_sensors/device_sensor_message_filter.h
@@ -0,0 +1,40 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_MESSAGE_FILTER_H_
+#define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_MESSAGE_FILTER_H_
+
+#include "base/macros.h"
+#include "base/memory/shared_memory.h"
+#include "content/browser/device_sensors/device_sensors_consts.h"
+#include "content/public/browser/browser_message_filter.h"
+
+namespace content {
+
+// A base class for device sensor related message filters.
+class DeviceSensorMessageFilter : public BrowserMessageFilter {
+ public:
+ DeviceSensorMessageFilter(ConsumerType consumer_type,
+ uint32_t message_class_to_filter);
+
+ protected:
+ // All methods below to be called on the IO thread.
+ ~DeviceSensorMessageFilter() override;
+
+ virtual void OnStartPolling();
+ virtual void OnStopPolling();
+ // To be overriden by the subclass in order to send the appropriate message
+ // to the renderer with a handle to shared memory.
+ virtual void DidStartPolling(base::SharedMemoryHandle handle) = 0;
+
+ private:
+ ConsumerType consumer_type_;
+ bool is_started_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceSensorMessageFilter);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_MESSAGE_FILTER_H_
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index bc66319..b359e05a8 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -568,6 +568,8 @@
'browser/device_sensors/device_orientation_absolute_message_filter.h',
'browser/device_sensors/device_orientation_message_filter.cc',
'browser/device_sensors/device_orientation_message_filter.h',
+ 'browser/device_sensors/device_sensor_message_filter.cc',
+ 'browser/device_sensors/device_sensor_message_filter.h',
'browser/device_sensors/device_sensors_consts.h',
'browser/device_sensors/sensor_manager_android.cc',
'browser/device_sensors/sensor_manager_android.h',