Skip to content

Commit

Permalink
dbus: Remove dbus::FileDescriptor
Browse files Browse the repository at this point in the history
BUG=621841
TEST=dbus_unittests
TBR=steel@chromium.org for device/bluetooth/dbus

Review-Url: https://codereview.chromium.org/2337893002
Cr-Commit-Position: refs/heads/master@{#418481}
  • Loading branch information
hashimoto authored and Commit bot committed Sep 14, 2016
1 parent 40f77bb commit dc693af
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 219 deletions.
1 change: 0 additions & 1 deletion chromeos/dbus/fake_permission_broker_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
#include "dbus/file_descriptor.h"

namespace chromeos {

Expand Down
2 changes: 0 additions & 2 deletions chromeos/dbus/mock_permission_broker_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "chromeos/dbus/mock_permission_broker_client.h"

#include "dbus/file_descriptor.h"

namespace chromeos {

MockPermissionBrokerClient::MockPermissionBrokerClient() {
Expand Down
1 change: 0 additions & 1 deletion chromeos/network/firewall_hole_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "base/run_loop.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/mock_permission_broker_client.h"
#include "dbus/file_descriptor.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down
2 changes: 0 additions & 2 deletions dbus/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ component("dbus") {
"dbus_statistics.h",
"exported_object.cc",
"exported_object.h",
"file_descriptor.cc",
"file_descriptor.h",
"message.cc",
"message.h",
"object_manager.cc",
Expand Down
68 changes: 0 additions & 68 deletions dbus/file_descriptor.cc

This file was deleted.

92 changes: 0 additions & 92 deletions dbus/file_descriptor.h

This file was deleted.

28 changes: 2 additions & 26 deletions dbus/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ std::string Message::ToStringInternal(const std::string& indent,
case UNIX_FD: {
CHECK(IsDBusTypeUnixFdSupported());

FileDescriptor file_descriptor;
base::ScopedFD file_descriptor;
if (!reader->PopFileDescriptor(&file_descriptor))
return kBrokenMessage;
output += indent + "fd#" +
base::IntToString(file_descriptor.value()) + "\n";
base::IntToString(file_descriptor.get()) + "\n";
break;
}
default:
Expand Down Expand Up @@ -719,17 +719,6 @@ void MessageWriter::AppendFileDescriptor(int value) {
AppendBasic(DBUS_TYPE_UNIX_FD, &value); // This duplicates the FD.
}

void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) {
CHECK(IsDBusTypeUnixFdSupported());

if (!value.is_valid()) {
// NB: sending a directory potentially enables sandbox escape
LOG(FATAL) << "Attempt to pass invalid file descriptor";
}
int fd = value.value();
AppendBasic(DBUS_TYPE_UNIX_FD, &fd);
}

//
// MessageReader implementation.
//
Expand Down Expand Up @@ -1033,17 +1022,4 @@ bool MessageReader::PopFileDescriptor(base::ScopedFD* value) {
return true;
}

bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
CHECK(IsDBusTypeUnixFdSupported());

int fd = -1;
const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd);
if (!success)
return false;

value->PutValue(fd);
// NB: the caller must check validity before using the value
return true;
}

} // namespace dbus
9 changes: 0 additions & 9 deletions dbus/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "dbus/dbus_export.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"

namespace google {
Expand Down Expand Up @@ -291,10 +290,6 @@ class CHROME_DBUS_EXPORT MessageWriter {
// The FD will be duplicated so you still have to close the original FD.
void AppendFileDescriptor(int value);

// DEPRECATED: Use the method with the same name above instead.
// TODO(hashimoto): Remove this. crbug.com/621841
void AppendFileDescriptor(const FileDescriptor& value);

// Opens an array. The array contents can be added to the array with
// |sub_writer|. The client code must close the array with
// CloseContainer(), once all contents are added.
Expand Down Expand Up @@ -408,10 +403,6 @@ class CHROME_DBUS_EXPORT MessageReader {
bool PopObjectPath(ObjectPath* value);
bool PopFileDescriptor(base::ScopedFD* value);

// DEPRECATED: Use the method with the same name above.
// TODO(hashimoto): Remove this. crbug.com/621841
bool PopFileDescriptor(FileDescriptor* value);

// Sets up the given message reader to read an array at the current
// iterator position.
// Returns true and advances the iterator on success.
Expand Down
21 changes: 6 additions & 15 deletions dbus/message_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,35 +124,26 @@ TEST(MessageTest, AppendAndPopFileDescriptor) {
MessageWriter writer(message.get());

// Append stdout.
FileDescriptor temp(1);
// Descriptor should not be valid until checked.
ASSERT_FALSE(temp.is_valid());
// NB: thread IO requirements not relevant for unit tests.
temp.CheckValidity();
ASSERT_TRUE(temp.is_valid());
writer.AppendFileDescriptor(temp);
const int fd_in = 1;
writer.AppendFileDescriptor(fd_in);

FileDescriptor fd_value;
base::ScopedFD fd_out;

MessageReader reader(message.get());
ASSERT_TRUE(reader.HasMoreData());
ASSERT_EQ(Message::UNIX_FD, reader.GetDataType());
ASSERT_EQ("h", reader.GetDataSignature());
ASSERT_TRUE(reader.PopFileDescriptor(&fd_value));
ASSERT_TRUE(reader.PopFileDescriptor(&fd_out));
ASSERT_FALSE(reader.HasMoreData());
// Descriptor is not valid until explicitly checked.
ASSERT_FALSE(fd_value.is_valid());
fd_value.CheckValidity();
ASSERT_TRUE(fd_value.is_valid());

// Stdout should be returned but we cannot check the descriptor
// value because stdout will be dup'd. Instead check st_rdev
// which should be identical.
struct stat sb_stdout;
int status_stdout = HANDLE_EINTR(fstat(1, &sb_stdout));
int status_stdout = HANDLE_EINTR(fstat(fd_in, &sb_stdout));
ASSERT_GE(status_stdout, 0);
struct stat sb_fd;
int status_fd = HANDLE_EINTR(fstat(fd_value.value(), &sb_fd));
int status_fd = HANDLE_EINTR(fstat(fd_out.get(), &sb_fd));
ASSERT_GE(status_fd, 0);
EXPECT_EQ(sb_stdout.st_rdev, sb_fd.st_rdev);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "base/callback.h"
#include "base/macros.h"
#include "dbus/bus.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_export.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "dbus/file_descriptor.h"
#include "device/bluetooth/dbus/bluetooth_media_client.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
Expand Down

0 comments on commit dc693af

Please sign in to comment.