summaryrefslogtreecommitdiffstats
path: root/dbus
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 /dbus
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 'dbus')
-rw-r--r--dbus/file_descriptor.cc9
-rw-r--r--dbus/file_descriptor.h10
2 files changed, 19 insertions, 0 deletions
diff --git a/dbus/file_descriptor.cc b/dbus/file_descriptor.cc
index d2d6a31..e607fc0 100644
--- a/dbus/file_descriptor.cc
+++ b/dbus/file_descriptor.cc
@@ -2,12 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/files/file.h"
+#include "base/location.h"
#include "base/logging.h"
+#include "base/threading/worker_pool.h"
#include "dbus/file_descriptor.h"
namespace dbus {
+void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()(
+ FileDescriptor* fd) {
+ base::WorkerPool::PostTask(
+ FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false);
+}
+
FileDescriptor::~FileDescriptor() {
if (owner_)
base::File auto_closer(value_);
diff --git a/dbus/file_descriptor.h b/dbus/file_descriptor.h
index 19e0b1a..a01ee6e 100644
--- a/dbus/file_descriptor.h
+++ b/dbus/file_descriptor.h
@@ -6,6 +6,7 @@
#define DBUS_FILE_DESCRIPTOR_H_
#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "dbus/dbus_export.h"
namespace dbus {
@@ -33,6 +34,12 @@ namespace dbus {
// with i/o restrictions.
class CHROME_DBUS_EXPORT FileDescriptor {
public:
+ // 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 Deleter {
+ void CHROME_DBUS_EXPORT operator()(FileDescriptor* fd);
+ };
+
// Permits initialization without a value for passing to
// dbus::MessageReader::PopFileDescriptor to fill in and from int values.
FileDescriptor() : value_(-1), owner_(false), valid_(false) {}
@@ -70,6 +77,9 @@ class CHROME_DBUS_EXPORT FileDescriptor {
DISALLOW_COPY_AND_ASSIGN(FileDescriptor);
};
+using ScopedFileDescriptor =
+ scoped_ptr<FileDescriptor, FileDescriptor::Deleter>;
+
} // namespace dbus
#endif // DBUS_FILE_DESCRIPTOR_H_