Commit f64c34ea authored by hashimoto's avatar hashimoto Committed by Commit bot

dbus: No dbus::FileDescriptor in BluetoothProfileServiceProvider

Replace dbus::FileDescriptor with base::ScopedFD.

BUG=621841

Review-Url: https://codereview.chromium.org/2310883003
Cr-Commit-Position: refs/heads/master@{#417219}
parent d46c2081
...@@ -112,7 +112,7 @@ void BluetoothAdapterProfileBlueZ::Released() { ...@@ -112,7 +112,7 @@ void BluetoothAdapterProfileBlueZ::Released() {
void BluetoothAdapterProfileBlueZ::NewConnection( void BluetoothAdapterProfileBlueZ::NewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, const bluez::BluetoothProfileServiceProvider::Delegate::Options& options,
const ConfirmationCallback& callback) { const ConfirmationCallback& callback) {
dbus::ObjectPath delegate_path = device_path; dbus::ObjectPath delegate_path = device_path;
......
...@@ -80,7 +80,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileBlueZ ...@@ -80,7 +80,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileBlueZ
void Released() override; void Released() override;
void NewConnection( void NewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, const bluez::BluetoothProfileServiceProvider::Delegate::Options& options,
const ConfirmationCallback& callback) override; const ConfirmationCallback& callback) override;
void RequestDisconnection(const dbus::ObjectPath& device_path, void RequestDisconnection(const dbus::ObjectPath& device_path,
......
...@@ -97,13 +97,12 @@ class BluetoothAdapterProfileBlueZTest : public testing::Test { ...@@ -97,13 +97,12 @@ class BluetoothAdapterProfileBlueZTest : public testing::Test {
void NewConnection( void NewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& const bluez::BluetoothProfileServiceProvider::Delegate::Options&
options, options,
const ConfirmationCallback& callback) override { const ConfirmationCallback& callback) override {
++connections_; ++connections_;
fd->CheckValidity(); fd.reset();
close(fd->TakeValue());
callback.Run(SUCCESS); callback.Run(SUCCESS);
if (device_path_.value() != "") if (device_path_.value() != "")
ASSERT_EQ(device_path_, device_path); ASSERT_EQ(device_path_, device_path);
......
...@@ -74,7 +74,7 @@ class FakeBluetoothProfileServiceProviderDelegate ...@@ -74,7 +74,7 @@ class FakeBluetoothProfileServiceProviderDelegate
void NewConnection( void NewConnection(
const dbus::ObjectPath&, const dbus::ObjectPath&,
std::unique_ptr<dbus::FileDescriptor>, base::ScopedFD,
const bluez::BluetoothProfileServiceProvider::Delegate::Options&, const bluez::BluetoothProfileServiceProvider::Delegate::Options&,
const ConfirmationCallback&) override {} const ConfirmationCallback&) override {}
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "dbus/bus.h" #include "dbus/bus.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
...@@ -353,7 +352,7 @@ void BluetoothSocketBlueZ::Released() { ...@@ -353,7 +352,7 @@ void BluetoothSocketBlueZ::Released() {
void BluetoothSocketBlueZ::NewConnection( void BluetoothSocketBlueZ::NewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, const bluez::BluetoothProfileServiceProvider::Delegate::Options& options,
const ConfirmationCallback& callback) { const ConfirmationCallback& callback) {
DCHECK(ui_task_runner()->RunsTasksOnCurrentThread()); DCHECK(ui_task_runner()->RunsTasksOnCurrentThread());
...@@ -448,16 +447,14 @@ void BluetoothSocketBlueZ::AcceptConnectionRequest() { ...@@ -448,16 +447,14 @@ void BluetoothSocketBlueZ::AcceptConnectionRequest() {
void BluetoothSocketBlueZ::DoNewConnection( void BluetoothSocketBlueZ::DoNewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, const bluez::BluetoothProfileServiceProvider::Delegate::Options& options,
const ConfirmationCallback& callback) { const ConfirmationCallback& callback) {
DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread()); DCHECK(socket_thread()->task_runner()->RunsTasksOnCurrentThread());
base::ThreadRestrictions::AssertIOAllowed(); base::ThreadRestrictions::AssertIOAllowed();
fd->CheckValidity();
VLOG(1) << uuid_.canonical_value() << ": Validity check complete."; if (!fd.is_valid()) {
if (!fd->is_valid()) { LOG(WARNING) << uuid_.canonical_value() << " :" << fd.get()
LOG(WARNING) << uuid_.canonical_value() << " :" << fd->value()
<< ": Invalid file descriptor received from Bluetooth Daemon."; << ": Invalid file descriptor received from Bluetooth Daemon.";
ui_task_runner()->PostTask(FROM_HERE, base::Bind(callback, REJECTED)); ui_task_runner()->PostTask(FROM_HERE, base::Bind(callback, REJECTED));
return; return;
...@@ -474,17 +471,13 @@ void BluetoothSocketBlueZ::DoNewConnection( ...@@ -474,17 +471,13 @@ void BluetoothSocketBlueZ::DoNewConnection(
// Note: We don't have a meaningful |IPEndPoint|, but that is ok since the // Note: We don't have a meaningful |IPEndPoint|, but that is ok since the
// TCPSocket implementation does not actually require one. // TCPSocket implementation does not actually require one.
int net_result = int net_result =
tcp_socket()->AdoptConnectedSocket(fd->value(), net::IPEndPoint()); tcp_socket()->AdoptConnectedSocket(fd.release(), net::IPEndPoint());
if (net_result != net::OK) { if (net_result != net::OK) {
LOG(WARNING) << uuid_.canonical_value() << ": Error adopting socket: " LOG(WARNING) << uuid_.canonical_value() << ": Error adopting socket: "
<< std::string(net::ErrorToString(net_result)); << std::string(net::ErrorToString(net_result));
ui_task_runner()->PostTask(FROM_HERE, base::Bind(callback, REJECTED)); ui_task_runner()->PostTask(FROM_HERE, base::Bind(callback, REJECTED));
return; return;
} }
VLOG(2) << uuid_.canonical_value()
<< ": Taking descriptor, confirming success.";
fd->TakeValue();
ui_task_runner()->PostTask(FROM_HERE, base::Bind(callback, SUCCESS)); ui_task_runner()->PostTask(FROM_HERE, base::Bind(callback, SUCCESS));
} }
......
...@@ -20,10 +20,6 @@ ...@@ -20,10 +20,6 @@
#include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h"
#include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h"
namespace dbus {
class FileDescriptor;
} // namespace dbus
namespace bluez { namespace bluez {
class BluetoothDeviceBlueZ; class BluetoothDeviceBlueZ;
...@@ -114,7 +110,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ ...@@ -114,7 +110,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ
void Released() override; void Released() override;
void NewConnection( void NewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, const bluez::BluetoothProfileServiceProvider::Delegate::Options& options,
const ConfirmationCallback& callback) override; const ConfirmationCallback& callback) override;
void RequestDisconnection(const dbus::ObjectPath& device_path, void RequestDisconnection(const dbus::ObjectPath& device_path,
...@@ -128,7 +124,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ ...@@ -128,7 +124,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ
// connection and set up the underlying net::TCPSocket() for it. // connection and set up the underlying net::TCPSocket() for it.
void DoNewConnection( void DoNewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, const bluez::BluetoothProfileServiceProvider::Delegate::Options& options,
const ConfirmationCallback& callback); const ConfirmationCallback& callback);
...@@ -142,8 +138,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ ...@@ -142,8 +138,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ
// Method run on the socket thread with a valid file descriptor |fd|, once // Method run on the socket thread with a valid file descriptor |fd|, once
// complete calls |callback| on the UI thread with an appropriate argument // complete calls |callback| on the UI thread with an appropriate argument
// indicating success or failure. // indicating success or failure.
void DoConnect(std::unique_ptr<dbus::FileDescriptor> fd, void DoConnect(base::ScopedFD fd, const ConfirmationCallback& callback);
const ConfirmationCallback& callback);
// Method run to clean-up a listening socket. // Method run to clean-up a listening socket.
void DoCloseListening(); void DoCloseListening();
...@@ -185,7 +180,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ ...@@ -185,7 +180,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ
~ConnectionRequest(); ~ConnectionRequest();
dbus::ObjectPath device_path; dbus::ObjectPath device_path;
std::unique_ptr<dbus::FileDescriptor> fd; base::ScopedFD fd;
bluez::BluetoothProfileServiceProvider::Delegate::Options options; bluez::BluetoothProfileServiceProvider::Delegate::Options options;
ConfirmationCallback callback; ConfirmationCallback callback;
bool accepting; bool accepting;
......
...@@ -103,10 +103,9 @@ class BluetoothProfileServiceProviderImpl ...@@ -103,10 +103,9 @@ class BluetoothProfileServiceProviderImpl
dbus::MessageReader reader(method_call); dbus::MessageReader reader(method_call);
dbus::ObjectPath device_path; dbus::ObjectPath device_path;
std::unique_ptr<dbus::FileDescriptor> fd(new dbus::FileDescriptor()); base::ScopedFD fd;
dbus::MessageReader array_reader(NULL); dbus::MessageReader array_reader(NULL);
if (!reader.PopObjectPath(&device_path) || if (!reader.PopObjectPath(&device_path) || !reader.PopFileDescriptor(&fd) ||
!reader.PopFileDescriptor(fd.get()) ||
!reader.PopArray(&array_reader)) { !reader.PopArray(&array_reader)) {
LOG(WARNING) << "NewConnection called with incorrect paramters: " LOG(WARNING) << "NewConnection called with incorrect paramters: "
<< method_call->ToString(); << method_call->ToString();
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include <string> #include <string>
#include "base/callback.h" #include "base/callback.h"
#include "base/files/scoped_file.h"
#include "base/macros.h" #include "base/macros.h"
#include "dbus/bus.h" #include "dbus/bus.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_export.h" #include "device/bluetooth/bluetooth_export.h"
...@@ -75,15 +75,10 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothProfileServiceProvider { ...@@ -75,15 +75,10 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothProfileServiceProvider {
// A file descriptor for the connection socket is provided in |fd|, and // A file descriptor for the connection socket is provided in |fd|, and
// details about the specific implementation of the profile in |options|. // details about the specific implementation of the profile in |options|.
// //
// IMPORTANT: Ownership of the file descriptor object |fd| is passed to
// the delegate by this call. The delegate is responsible for checking the
// validity of |fd| on a thread where I/O is permitted before taking the
// value. If the value is not taken, the file descriptor is closed.
//
// Ownership of |options| is NOT passed so information out of it must be // Ownership of |options| is NOT passed so information out of it must be
// copied if required. // copied if required.
virtual void NewConnection(const dbus::ObjectPath& device_path, virtual void NewConnection(const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const Options& options, const Options& options,
const ConfirmationCallback& callback) = 0; const ConfirmationCallback& callback) = 0;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "dbus/file_descriptor.h"
#include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h" #include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
...@@ -512,7 +511,7 @@ void FakeBluetoothDeviceClient::ConnectProfile( ...@@ -512,7 +511,7 @@ void FakeBluetoothDeviceClient::ConnectProfile(
base::WorkerPool::GetTaskRunner(false) base::WorkerPool::GetTaskRunner(false)
->PostTask(FROM_HERE, base::Bind(&SimulatedProfileSocket, fds[0])); ->PostTask(FROM_HERE, base::Bind(&SimulatedProfileSocket, fds[0]));
std::unique_ptr<dbus::FileDescriptor> fd(new dbus::FileDescriptor(fds[1])); base::ScopedFD fd(fds[1]);
// Post the new connection to the service provider. // Post the new connection to the service provider.
BluetoothProfileServiceProvider::Delegate::Options options; BluetoothProfileServiceProvider::Delegate::Options options;
......
...@@ -40,7 +40,7 @@ void FakeBluetoothProfileServiceProvider::Released() { ...@@ -40,7 +40,7 @@ void FakeBluetoothProfileServiceProvider::Released() {
void FakeBluetoothProfileServiceProvider::NewConnection( void FakeBluetoothProfileServiceProvider::NewConnection(
const dbus::ObjectPath& device_path, const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const Delegate::Options& options, const Delegate::Options& options,
const Delegate::ConfirmationCallback& callback) { const Delegate::ConfirmationCallback& callback) {
VLOG(1) << object_path_.value() << ": NewConnection for " VLOG(1) << object_path_.value() << ": NewConnection for "
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_export.h" #include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h"
...@@ -34,7 +33,7 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothProfileServiceProvider ...@@ -34,7 +33,7 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothProfileServiceProvider
// construction. // construction.
void Released(); void Released();
void NewConnection(const dbus::ObjectPath& device_path, void NewConnection(const dbus::ObjectPath& device_path,
std::unique_ptr<dbus::FileDescriptor> fd, base::ScopedFD fd,
const Delegate::Options& options, const Delegate::Options& options,
const Delegate::ConfirmationCallback& callback); const Delegate::ConfirmationCallback& callback);
void RequestDisconnection(const dbus::ObjectPath& device_path, void RequestDisconnection(const dbus::ObjectPath& device_path,
......
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