summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorcmasone <cmasone@chromium.org>2015-04-27 14:41:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-27 21:41:41 +0000
commit610c3173c4dc2258c10c8b211ab9cbe21f2a1402 (patch)
tree54a6dd0a8f946d2d52efe25aa4f88e779e8750a4 /chromeos
parent019d4f33ee70596e34bcf78706c3da4d2d70d4f1 (diff)
downloadchromium_src-610c3173c4dc2258c10c8b211ab9cbe21f2a1402.zip
chromium_src-610c3173c4dc2258c10c8b211ab9cbe21f2a1402.tar.gz
chromium_src-610c3173c4dc2258c10c8b211ab9cbe21f2a1402.tar.bz2
Re-land Move ScopedFileDescriptor to dbus/file_descriptor.h
ScopedFileDescriptor was initially introduced to facilitate the management of a 'lifeline' FD used when asking permission_broker to open a port in the device's firewall on CrOS. It's actually a scoped wrapper around DBus::FileDescriptor, not a platform file descriptor. I would like to use it to facilitate some other similar functionality in which I create a pipe and pass one end over DBus, so it seems like a good idea to move ScopedFileDescriptor into the dbus library directly. This reverts commit ee9dc849ffa2df2820381c31d5ba8200774d287a. BUG=chromium:481340 TEST=FirewallHole unit tests still pass TBR=stevenjb, reillyg, keybuk Review URL: https://codereview.chromium.org/1108083003 Cr-Commit-Position: refs/heads/master@{#327141}
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/network/firewall_hole.cc21
-rw-r--r--chromeos/network/firewall_hole.h23
2 files changed, 13 insertions, 31 deletions
diff --git a/chromeos/network/firewall_hole.cc b/chromeos/network/firewall_hole.cc
index 425e423..3ad3463 100644
--- a/chromeos/network/firewall_hole.cc
+++ b/chromeos/network/firewall_hole.cc
@@ -50,7 +50,7 @@ const char* PortTypeToString(FirewallHole::PortType type) {
void PortReleased(FirewallHole::PortType type,
uint16_t port,
const std::string& interface,
- FirewallHole::ScopedFileDescriptor lifeline_fd,
+ dbus::ScopedFileDescriptor lifeline_fd,
bool success) {
if (!success) {
LOG(WARNING) << "Failed to release firewall hole for "
@@ -61,20 +61,13 @@ void PortReleased(FirewallHole::PortType type,
} // namespace
-void CHROMEOS_EXPORT FirewallHole::FileDescriptorDeleter::operator()(
- dbus::FileDescriptor* fd) {
- base::WorkerPool::PostTask(
- FROM_HERE, base::Bind(&base::DeletePointer<dbus::FileDescriptor>, fd),
- false);
-}
-
// static
void FirewallHole::Open(PortType type,
uint16_t port,
const std::string& interface,
const OpenCallback& callback) {
- ScopedFileDescriptor lifeline_local(new dbus::FileDescriptor());
- ScopedFileDescriptor lifeline_remote(new dbus::FileDescriptor());
+ dbus::ScopedFileDescriptor lifeline_local(new dbus::FileDescriptor());
+ dbus::ScopedFileDescriptor lifeline_remote(new dbus::FileDescriptor());
// This closure shares pointers with the one below. PostTaskAndReply
// guarantees that it will always be deleted first.
@@ -109,8 +102,8 @@ FirewallHole::~FirewallHole() {
void FirewallHole::RequestPortAccess(PortType type,
uint16_t port,
const std::string& interface,
- ScopedFileDescriptor lifeline_local,
- ScopedFileDescriptor lifeline_remote,
+ dbus::ScopedFileDescriptor lifeline_local,
+ dbus::ScopedFileDescriptor lifeline_remote,
const OpenCallback& callback) {
if (!lifeline_local->is_valid() || !lifeline_remote->is_valid()) {
callback.Run(nullptr);
@@ -140,7 +133,7 @@ void FirewallHole::RequestPortAccess(PortType type,
void FirewallHole::PortAccessGranted(PortType type,
uint16_t port,
const std::string& interface,
- ScopedFileDescriptor lifeline_fd,
+ dbus::ScopedFileDescriptor lifeline_fd,
const FirewallHole::OpenCallback& callback,
bool success) {
if (success) {
@@ -154,7 +147,7 @@ void FirewallHole::PortAccessGranted(PortType type,
FirewallHole::FirewallHole(PortType type,
uint16_t port,
const std::string& interface,
- ScopedFileDescriptor lifeline_fd)
+ dbus::ScopedFileDescriptor lifeline_fd)
: type_(type),
port_(port),
interface_(interface),
diff --git a/chromeos/network/firewall_hole.h b/chromeos/network/firewall_hole.h
index 2bd6788..e6d119d 100644
--- a/chromeos/network/firewall_hole.h
+++ b/chromeos/network/firewall_hole.h
@@ -11,10 +11,7 @@
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
-
-namespace dbus {
-class FileDescriptor;
-}
+#include "dbus/file_descriptor.h"
namespace chromeos {
@@ -29,14 +26,6 @@ class CHROMEOS_EXPORT FirewallHole {
typedef base::Callback<void(scoped_ptr<FirewallHole>)> OpenCallback;
- // This provides a simple way to pass around file descriptors since they must
- // be closed on a thread that is allowed to perform I/O.
- struct FileDescriptorDeleter {
- void CHROMEOS_EXPORT operator()(dbus::FileDescriptor* fd);
- };
- typedef scoped_ptr<dbus::FileDescriptor, FileDescriptorDeleter>
- ScopedFileDescriptor;
-
// Opens a port on the system firewall for the given network interface (or all
// interfaces if |interface| is ""). The hole will be closed when the object
// provided to the callback is destroyed.
@@ -51,28 +40,28 @@ class CHROMEOS_EXPORT FirewallHole {
static void RequestPortAccess(PortType type,
uint16_t port,
const std::string& interface,
- ScopedFileDescriptor lifeline_local,
- ScopedFileDescriptor lifeline_remote,
+ dbus::ScopedFileDescriptor lifeline_local,
+ dbus::ScopedFileDescriptor lifeline_remote,
const OpenCallback& callback);
static void PortAccessGranted(PortType type,
uint16_t port,
const std::string& interface,
- ScopedFileDescriptor lifeline_fd,
+ dbus::ScopedFileDescriptor lifeline_fd,
const FirewallHole::OpenCallback& callback,
bool success);
FirewallHole(PortType type,
uint16_t port,
const std::string& interface,
- ScopedFileDescriptor lifeline_fd);
+ dbus::ScopedFileDescriptor lifeline_fd);
const PortType type_;
const uint16_t port_;
const std::string interface_;
// A file descriptor used by firewalld to track the lifetime of this process.
- ScopedFileDescriptor lifeline_fd_;
+ dbus::ScopedFileDescriptor lifeline_fd_;
};
} // namespace chromeos