Commit 990c4fe8 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

bluetooth: Add mojom and stub impl for BluetoothSystem

Bluetooth System is the High level interface targeted towards UI level
components like Ash and chrome://settings that:
 _ Show the BT Radio state and allow users to change it.
 - Show a list of nearby, connected and paired BT Devices.
 - Start and stop BT scans.
 - Connect to and pair with BT devices.

Bug: 870192

Change-Id: Ifb6afaffc2d05e0718dcda70c0a0a23cffb68c1e
Reviewed-on: https://chromium-review.googlesource.com/1161716
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588458}
parent 43b45aee
......@@ -27,6 +27,7 @@ source_set("lib") {
deps = [
"//base",
"//services/device/bluetooth",
"//services/device/fingerprint",
"//services/device/generic_sensor",
"//services/device/geolocation",
......@@ -109,6 +110,7 @@ source_set("tests") {
"//mojo/public/cpp/bindings",
"//net",
"//net:test_support",
"//services/device/bluetooth:tests",
"//services/device/generic_sensor",
"//services/device/geolocation",
"//services/device/geolocation:test_support",
......
# Copyright 2018 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.
import("//build/config/features.gni")
source_set("bluetooth") {
visibility = [
"//services/device:lib",
"//services/device/bluetooth:tests",
]
sources = [
"bluetooth_system.cc",
"bluetooth_system.h",
"bluetooth_system_factory.cc",
"bluetooth_system_factory.h",
]
public_deps = [
"//services/device/public/mojom",
]
deps = [
"//base",
]
}
source_set("tests") {
testonly = true
sources = [
"bluetooth_system_unittest.cc",
]
deps = [
":bluetooth",
"//net",
"//services/device:test_support",
"//testing/gtest",
]
}
// Copyright 2018 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 "services/device/bluetooth/bluetooth_system.h"
#include <memory>
#include <utility>
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace device {
void BluetoothSystem::Create(mojom::BluetoothSystemRequest request,
mojom::BluetoothSystemClientPtr client) {
mojo::MakeStrongBinding(std::make_unique<BluetoothSystem>(std::move(client)),
std::move(request));
}
BluetoothSystem::BluetoothSystem(mojom::BluetoothSystemClientPtr client) {
client_ptr_ = std::move(client);
}
BluetoothSystem::~BluetoothSystem() = default;
} // namespace device
// Copyright 2018 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 SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_H_
#define SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_H_
#include "base/macros.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace device {
class BluetoothSystem : public mojom::BluetoothSystem {
public:
static void Create(mojom::BluetoothSystemRequest request,
mojom::BluetoothSystemClientPtr client);
explicit BluetoothSystem(mojom::BluetoothSystemClientPtr client);
~BluetoothSystem() override;
private:
mojom::BluetoothSystemClientPtr client_ptr_;
DISALLOW_COPY_AND_ASSIGN(BluetoothSystem);
};
} // namespace device
#endif // SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_H_
// Copyright 2018 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 "services/device/bluetooth/bluetooth_system_factory.h"
#include <memory>
#include <utility>
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/device/bluetooth/bluetooth_system.h"
namespace device {
void BluetoothSystemFactory::CreateFactory(
mojom::BluetoothSystemFactoryRequest request) {
mojo::MakeStrongBinding(std::make_unique<BluetoothSystemFactory>(),
std::move(request));
}
BluetoothSystemFactory::BluetoothSystemFactory() = default;
BluetoothSystemFactory::~BluetoothSystemFactory() = default;
void BluetoothSystemFactory::Create(
mojom::BluetoothSystemRequest system_request,
mojom::BluetoothSystemClientPtr system_client) {
BluetoothSystem::Create(std::move(system_request), std::move(system_client));
}
} // namespace device
// Copyright 2018 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 SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_FACTORY_H_
#define SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_FACTORY_H_
#include "base/macros.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
namespace device {
class BluetoothSystemFactory : public mojom::BluetoothSystemFactory {
public:
static void CreateFactory(mojom::BluetoothSystemFactoryRequest request);
BluetoothSystemFactory();
~BluetoothSystemFactory() override;
// mojom::BluetoothSystemFactory
void Create(mojom::BluetoothSystemRequest system_request,
mojom::BluetoothSystemClientPtr system_client) override;
private:
DISALLOW_COPY_AND_ASSIGN(BluetoothSystemFactory);
};
} // namespace device
#endif // SERVICES_DEVICE_BLUETOOTH_BLUETOOTH_SYSTEM_FACTORY_H_
// Copyright 2018 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 "services/device/bluetooth/bluetooth_system.h"
#include <utility>
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/device/device_service_test_base.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
#include "services/device/public/mojom/constants.mojom.h"
namespace device {
class BluetoothSystemTest : public DeviceServiceTestBase,
public mojom::BluetoothSystemClient {
public:
BluetoothSystemTest() = default;
~BluetoothSystemTest() override = default;
void SetUp() override {
DeviceServiceTestBase::SetUp();
connector()->BindInterface(mojom::kServiceName, &system_factory_);
}
protected:
mojom::BluetoothSystemFactoryPtr system_factory_;
private:
DISALLOW_COPY_AND_ASSIGN(BluetoothSystemTest);
};
TEST_F(BluetoothSystemTest, FactoryCreate) {
mojom::BluetoothSystemPtr system_ptr;
mojo::Binding<mojom::BluetoothSystemClient> client_binding(this);
mojom::BluetoothSystemClientPtr client_ptr;
client_binding.Bind(mojo::MakeRequest(&client_ptr));
EXPECT_FALSE(system_ptr.is_bound());
system_factory_->Create(mojo::MakeRequest(&system_ptr),
std::move(client_ptr));
base::RunLoop run_loop;
system_ptr.FlushAsyncForTesting(run_loop.QuitClosure());
run_loop.Run();
EXPECT_TRUE(system_ptr.is_bound());
}
} // namespace device
......@@ -12,6 +12,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/device/bluetooth/bluetooth_system_factory.h"
#include "services/device/fingerprint/fingerprint.h"
#include "services/device/generic_sensor/sensor_provider_impl.h"
#include "services/device/geolocation/geolocation_config.h"
......@@ -113,6 +114,9 @@ DeviceService::~DeviceService() {
}
void DeviceService::OnStart() {
registry_.AddInterface<mojom::BluetoothSystemFactory>(
base::BindRepeating(&DeviceService::BindBluetoothSystemFactoryRequest,
base::Unretained(this)));
registry_.AddInterface<mojom::Fingerprint>(base::Bind(
&DeviceService::BindFingerprintRequest, base::Unretained(this)));
registry_.AddInterface<mojom::GeolocationConfig>(base::BindRepeating(
......@@ -178,6 +182,11 @@ void DeviceService::OnBindInterface(
registry_.BindInterface(interface_name, std::move(interface_pipe));
}
void DeviceService::BindBluetoothSystemFactoryRequest(
mojom::BluetoothSystemFactoryRequest request) {
BluetoothSystemFactory::CreateFactory(std::move(request));
}
#if !defined(OS_ANDROID)
void DeviceService::BindBatteryMonitorRequest(
mojom::BatteryMonitorRequest request) {
......
......@@ -15,6 +15,7 @@
#include "services/device/geolocation/geolocation_provider_impl.h"
#include "services/device/geolocation/public_ip_address_geolocation_provider.h"
#include "services/device/public/mojom/battery_monitor.mojom.h"
#include "services/device/public/mojom/bluetooth_system.mojom.h"
#include "services/device/public/mojom/fingerprint.mojom.h"
#include "services/device/public/mojom/geolocation.mojom.h"
#include "services/device/public/mojom/geolocation_config.mojom.h"
......@@ -113,6 +114,8 @@ class DeviceService : public service_manager::Service {
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
void BindBluetoothSystemFactoryRequest(
mojom::BluetoothSystemFactoryRequest request);
void BindFingerprintRequest(mojom::FingerprintRequest request);
void BindGeolocationConfigRequest(mojom::GeolocationConfigRequest request);
void BindGeolocationContextRequest(mojom::GeolocationContextRequest request);
......
......@@ -8,6 +8,7 @@
"service_manager:connector": {
"provides": {
"device:battery_monitor": [ "device.mojom.BatteryMonitor" ],
"device:bluetooth_system": [ "device.mojom.BluetoothSystemFactory" ],
"device:fingerprint": [ "device.mojom.Fingerprint" ],
"device:generic_sensor": [ "device.mojom.SensorProvider" ],
"device:geolocation": [ "device.mojom.GeolocationContext" ],
......
......@@ -9,6 +9,7 @@ mojom("mojom") {
sources = [
"battery_monitor.mojom",
"battery_status.mojom",
"bluetooth_system.mojom",
"fingerprint.mojom",
"geolocation.mojom",
"geolocation_config.mojom",
......
// Copyright 2018 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.
module device.mojom;
// Factory to get an instance of the BluetoothSystem interface.
interface BluetoothSystemFactory {
Create(BluetoothSystem& system, BluetoothSystemClient system_client);
};
// High level interface targeted towards UI level components that:
// - Show the BT Radio state and allow users to change it.
// - Show a list of nearby, connected and paired BT Devices.
// - Start and stop BT scans.
// - Connect to and pair with BT devices.
//
// This interface is implemented only on Chrome OS and lives in the Device
// Service.
interface BluetoothSystem {
};
// Interface used by clients of BluetoothSystem to get notified of events
// like Bluetooth State changes.
interface BluetoothSystemClient {
};
......@@ -10,6 +10,7 @@
},
"requires": {
"device": [
"device:bluetooth_system",
"device:battery_monitor",
"device:generic_sensor",
"device:geolocation_config",
......
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