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) {
import("//build/config/android/rules.gni") # For generate_jni().
}
source_set("generic_sensor") {
component("generic_sensor") {
output_name = "generic_sensor"
sources = [
"platform_sensor.cc",
"platform_sensor.h",
......@@ -29,8 +30,13 @@ source_set("generic_sensor") {
"sensor_provider_impl.h",
]
defines = [ "DEVICE_GENERIC_SENSOR_IMPLEMENTATION" ]
deps = [
"//base",
]
public_deps = [
"//device/generic_sensor/public/cpp",
"//device/generic_sensor/public/interfaces",
]
......@@ -49,6 +55,8 @@ source_set("generic_sensor") {
sources -= [ "platform_sensor_provider_default.cc" ]
deps += [ "//device/sensors/public/cpp" ]
libs = [ "IOKit.framework" ]
}
}
......@@ -85,6 +93,5 @@ static_library("testing") {
public_deps = [
":generic_sensor",
"//base",
"//device/generic_sensor/public/interfaces",
]
}
......@@ -7,6 +7,8 @@
#include <jni.h>
#include "device/generic_sensor/generic_sensor_export.h"
namespace device {
namespace android {
......@@ -14,7 +16,7 @@ namespace android {
// See https://www.chromium.org/developers/design-documents/android-jni
//
// 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 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 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.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/interfaces/sensor.mojom.h"
#include "mojo/public/cpp/system/buffer.h"
......@@ -23,7 +24,8 @@ class PlatformSensorConfiguration;
// Base class for the sensors provided by the platform. Concrete instances of
// 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:
// The interface that must be implemented by PlatformSensor clients.
class Client {
......
......@@ -5,13 +5,15 @@
#ifndef 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"
namespace device {
// This a singleton class returning the actual sensor provider
// implementation for the current platform.
class PlatformSensorProvider : public PlatformSensorProviderBase {
class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProvider
: public PlatformSensorProviderBase {
public:
// Returns the PlatformSensorProvider singleton.
// Note: returns 'nullptr' if there is no available implementation for
......
......@@ -8,13 +8,15 @@
#include "base/macros.h"
#include "base/threading/non_thread_safe.h"
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/platform_sensor.h"
namespace device {
// Base class that defines factory methods for PlatformSensor creation.
// Its implementations must be accessed via GetInstance() method.
class PlatformSensorProviderBase : public base::NonThreadSafe {
class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderBase
: public base::NonThreadSafe {
public:
using CreateSensorCallback =
base::Callback<void(scoped_refptr<PlatformSensor>)>;
......
......@@ -4,10 +4,14 @@
source_set("cpp") {
sources = [
"platform_sensor_configuration.cc",
"platform_sensor_configuration.h",
"sensor_reading.cc",
"sensor_reading.h",
]
defines = [ "DEVICE_GENERIC_SENSOR_IMPLEMENTATION" ]
deps = [
"//base",
"//device/base/synchronization",
......
......@@ -6,10 +6,11 @@
#define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_CONFIGURATION_H_
#include "base/logging.h"
#include "device/generic_sensor/generic_sensor_export.h"
namespace device {
class PlatformSensorConfiguration {
class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorConfiguration {
public:
PlatformSensorConfiguration();
explicit PlatformSensorConfiguration(double frequency);
......
......@@ -6,6 +6,7 @@
#define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_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"
namespace device {
......@@ -39,7 +40,7 @@ class SensorReadingField {
};
// This structure represents sensor reading data: timestamp and 3 values.
struct SensorReading {
struct DEVICE_GENERIC_SENSOR_EXPORT SensorReading {
SensorReading();
~SensorReading();
SensorReading(const SensorReading& other);
......
......@@ -5,6 +5,9 @@
import("//mojo/public/tools/bindings/mojom.gni")
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 = [
"sensor.mojom",
"sensor_provider.mojom",
......
......@@ -7,7 +7,6 @@ public_headers =
[ "//device/generic_sensor/public/cpp/platform_sensor_configuration.h" ]
traits_headers = [ "//device/generic_sensor/public/cpp/sensor_struct_traits.h" ]
sources = [
"//device/generic_sensor/public/cpp/platform_sensor_configuration.cc",
"//device/generic_sensor/public/cpp/sensor_struct_traits.cc",
]
type_mappings =
......
......@@ -6,6 +6,7 @@
#define DEVICE_GENERIC_SENSOR_SENSOR_PROVIDER_IMPL_H_
#include "base/macros.h"
#include "device/generic_sensor/generic_sensor_export.h"
#include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h"
namespace device {
......@@ -16,7 +17,8 @@ class PlatformSensor;
// Implementation of SensorProvider mojo interface.
// Uses PlatformSensorProvider singleton to create platform specific instances
// of PlatformSensor which are used by SensorImpl.
class SensorProviderImpl final : public mojom::SensorProvider {
class DEVICE_GENERIC_SENSOR_EXPORT SensorProviderImpl final
: public mojom::SensorProvider {
public:
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