Commit ed8fd058 authored by alexis.menard's avatar alexis.menard Committed by Commit bot

[sensors] Make generic_sensor a component

The motivation is to allow classes to be exported (for component builds) so that
a browser test can be written outside of device/ and on top
of content/ and the needed classes can be used to write a fake/mock
provider with fake/mock sensors (the test will come in follow up CL).
The motivation is to test end to end the feature in a cross platform
and non hardware dependent way and checking JavaScript behavior.

BUG=606766

Review-Url: https://chromiumcodereview.appspot.com/2431163004
Cr-Commit-Position: refs/heads/master@{#426567}
parent 05b40466
...@@ -8,7 +8,8 @@ if (is_android) { ...@@ -8,7 +8,8 @@ if (is_android) {
import("//build/config/android/rules.gni") # For generate_jni(). import("//build/config/android/rules.gni") # For generate_jni().
} }
source_set("generic_sensor") { component("generic_sensor") {
output_name = "generic_sensor"
sources = [ sources = [
"platform_sensor.cc", "platform_sensor.cc",
"platform_sensor.h", "platform_sensor.h",
...@@ -29,8 +30,13 @@ source_set("generic_sensor") { ...@@ -29,8 +30,13 @@ source_set("generic_sensor") {
"sensor_provider_impl.h", "sensor_provider_impl.h",
] ]
defines = [ "DEVICE_GENERIC_SENSOR_IMPLEMENTATION" ]
deps = [ deps = [
"//base", "//base",
]
public_deps = [
"//device/generic_sensor/public/cpp", "//device/generic_sensor/public/cpp",
"//device/generic_sensor/public/interfaces", "//device/generic_sensor/public/interfaces",
] ]
...@@ -49,6 +55,8 @@ source_set("generic_sensor") { ...@@ -49,6 +55,8 @@ source_set("generic_sensor") {
sources -= [ "platform_sensor_provider_default.cc" ] sources -= [ "platform_sensor_provider_default.cc" ]
deps += [ "//device/sensors/public/cpp" ] deps += [ "//device/sensors/public/cpp" ]
libs = [ "IOKit.framework" ]
} }
} }
...@@ -85,6 +93,5 @@ static_library("testing") { ...@@ -85,6 +93,5 @@ static_library("testing") {
public_deps = [ public_deps = [
":generic_sensor", ":generic_sensor",
"//base", "//base",
"//device/generic_sensor/public/interfaces",
] ]
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <jni.h> #include <jni.h>
#include "device/generic_sensor/generic_sensor_export.h"
namespace device { namespace device {
namespace android { namespace android {
...@@ -14,7 +16,7 @@ namespace android { ...@@ -14,7 +16,7 @@ namespace android {
// See https://www.chromium.org/developers/design-documents/android-jni // See https://www.chromium.org/developers/design-documents/android-jni
// //
// Must be called before classes in the Sensors module are used. // Must be called before classes in the Sensors module are used.
bool RegisterSensorsJni(JNIEnv* env); bool DEVICE_GENERIC_SENSOR_EXPORT RegisterSensorsJni(JNIEnv* env);
} // namespace android } // namespace android
} // namespace device } // namespace device
......
// 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 DEVICE_GENERIC_SENSOR_GENERIC_SENSOR_EXPORT_H_
#define DEVICE_GENERIC_SENSOR_GENERIC_SENSOR_EXPORT_H_
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#if defined(DEVICE_GENERIC_SENSOR_IMPLEMENTATION)
#define DEVICE_GENERIC_SENSOR_EXPORT __declspec(dllexport)
#else
#define DEVICE_GENERIC_SENSOR_EXPORT __declspec(dllimport)
#endif // defined(DEVICE_GENERIC_SENSOR_IMPLEMENTATION)
#else // defined(WIN32)
#if defined(DEVICE_GENERIC_SENSOR_IMPLEMENTATION)
#define DEVICE_GENERIC_SENSOR_EXPORT __attribute__((visibility("default")))
#else
#define DEVICE_GENERIC_SENSOR_EXPORT
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define DEVICE_GENERIC_SENSOR_EXPORT
#endif
#endif // DEVICE_GENERIC_SENSOR_GENERIC_SENSOR_EXPORT_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/public/cpp/sensor_reading.h" #include "device/generic_sensor/public/cpp/sensor_reading.h"
#include "device/generic_sensor/public/interfaces/sensor.mojom.h" #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
#include "mojo/public/cpp/system/buffer.h" #include "mojo/public/cpp/system/buffer.h"
...@@ -23,7 +24,8 @@ class PlatformSensorConfiguration; ...@@ -23,7 +24,8 @@ class PlatformSensorConfiguration;
// Base class for the sensors provided by the platform. Concrete instances of // Base class for the sensors provided by the platform. Concrete instances of
// this class are created by platform specific PlatformSensorProvider. // this class are created by platform specific PlatformSensorProvider.
class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> { class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensor
: public base::RefCountedThreadSafe<PlatformSensor> {
public: public:
// The interface that must be implemented by PlatformSensor clients. // The interface that must be implemented by PlatformSensor clients.
class Client { class Client {
......
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
#ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_ #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_
#define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_ #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_H_
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/platform_sensor_provider_base.h" #include "device/generic_sensor/platform_sensor_provider_base.h"
namespace device { namespace device {
// This a singleton class returning the actual sensor provider // This a singleton class returning the actual sensor provider
// implementation for the current platform. // implementation for the current platform.
class PlatformSensorProvider : public PlatformSensorProviderBase { class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProvider
: public PlatformSensorProviderBase {
public: public:
// Returns the PlatformSensorProvider singleton. // Returns the PlatformSensorProvider singleton.
// Note: returns 'nullptr' if there is no available implementation for // Note: returns 'nullptr' if there is no available implementation for
......
...@@ -8,13 +8,15 @@ ...@@ -8,13 +8,15 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/platform_sensor.h" #include "device/generic_sensor/platform_sensor.h"
namespace device { namespace device {
// Base class that defines factory methods for PlatformSensor creation. // Base class that defines factory methods for PlatformSensor creation.
// Its implementations must be accessed via GetInstance() method. // Its implementations must be accessed via GetInstance() method.
class PlatformSensorProviderBase : public base::NonThreadSafe { class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderBase
: public base::NonThreadSafe {
public: public:
using CreateSensorCallback = using CreateSensorCallback =
base::Callback<void(scoped_refptr<PlatformSensor>)>; base::Callback<void(scoped_refptr<PlatformSensor>)>;
......
...@@ -4,10 +4,14 @@ ...@@ -4,10 +4,14 @@
source_set("cpp") { source_set("cpp") {
sources = [ sources = [
"platform_sensor_configuration.cc",
"platform_sensor_configuration.h",
"sensor_reading.cc", "sensor_reading.cc",
"sensor_reading.h", "sensor_reading.h",
] ]
defines = [ "DEVICE_GENERIC_SENSOR_IMPLEMENTATION" ]
deps = [ deps = [
"//base", "//base",
"//device/base/synchronization", "//device/base/synchronization",
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
#define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_CONFIGURATION_H_ #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_CONFIGURATION_H_
#include "base/logging.h" #include "base/logging.h"
#include "device/generic_sensor/generic_sensor_export.h"
namespace device { namespace device {
class PlatformSensorConfiguration { class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorConfiguration {
public: public:
PlatformSensorConfiguration(); PlatformSensorConfiguration();
explicit PlatformSensorConfiguration(double frequency); explicit PlatformSensorConfiguration(double frequency);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ #define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
#include "device/base/synchronization/one_writer_seqlock.h" #include "device/base/synchronization/one_writer_seqlock.h"
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/public/interfaces/sensor.mojom.h" #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
namespace device { namespace device {
...@@ -39,7 +40,7 @@ class SensorReadingField { ...@@ -39,7 +40,7 @@ class SensorReadingField {
}; };
// This structure represents sensor reading data: timestamp and 3 values. // This structure represents sensor reading data: timestamp and 3 values.
struct SensorReading { struct DEVICE_GENERIC_SENSOR_EXPORT SensorReading {
SensorReading(); SensorReading();
~SensorReading(); ~SensorReading();
SensorReading(const SensorReading& other); SensorReading(const SensorReading& other);
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
import("//mojo/public/tools/bindings/mojom.gni") import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") { mojom("interfaces") {
export_class_attribute = "DEVICE_GENERIC_SENSOR_EXPORT"
export_define = "DEVICE_GENERIC_SENSOR_IMPLEMENTATION=1"
export_header = "device/generic_sensor/generic_sensor_export.h"
sources = [ sources = [
"sensor.mojom", "sensor.mojom",
"sensor_provider.mojom", "sensor_provider.mojom",
......
...@@ -7,7 +7,6 @@ public_headers = ...@@ -7,7 +7,6 @@ public_headers =
[ "//device/generic_sensor/public/cpp/platform_sensor_configuration.h" ] [ "//device/generic_sensor/public/cpp/platform_sensor_configuration.h" ]
traits_headers = [ "//device/generic_sensor/public/cpp/sensor_struct_traits.h" ] traits_headers = [ "//device/generic_sensor/public/cpp/sensor_struct_traits.h" ]
sources = [ sources = [
"//device/generic_sensor/public/cpp/platform_sensor_configuration.cc",
"//device/generic_sensor/public/cpp/sensor_struct_traits.cc", "//device/generic_sensor/public/cpp/sensor_struct_traits.cc",
] ]
type_mappings = type_mappings =
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define DEVICE_GENERIC_SENSOR_SENSOR_PROVIDER_IMPL_H_ #define DEVICE_GENERIC_SENSOR_SENSOR_PROVIDER_IMPL_H_
#include "base/macros.h" #include "base/macros.h"
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h"
namespace device { namespace device {
...@@ -16,7 +17,8 @@ class PlatformSensor; ...@@ -16,7 +17,8 @@ class PlatformSensor;
// Implementation of SensorProvider mojo interface. // Implementation of SensorProvider mojo interface.
// Uses PlatformSensorProvider singleton to create platform specific instances // Uses PlatformSensorProvider singleton to create platform specific instances
// of PlatformSensor which are used by SensorImpl. // of PlatformSensor which are used by SensorImpl.
class SensorProviderImpl final : public mojom::SensorProvider { class DEVICE_GENERIC_SENSOR_EXPORT SensorProviderImpl final
: public mojom::SensorProvider {
public: public:
static void Create(mojom::SensorProviderRequest request); static void Create(mojom::SensorProviderRequest request);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment