summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2015-06-10 23:19:11 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-11 06:19:40 +0000
commit8f22f63f0bb566682278d93b896dfc68fa731434 (patch)
tree3b7b34bbee518e4efdc2e080f1fab3e19d7d40f8 /dbus
parent8e7215b52f523e303c44cc7ddaab79b5ab0863ef (diff)
downloadchromium_src-8f22f63f0bb566682278d93b896dfc68fa731434.zip
chromium_src-8f22f63f0bb566682278d93b896dfc68fa731434.tar.gz
chromium_src-8f22f63f0bb566682278d93b896dfc68fa731434.tar.bz2
Make dbus::FileDescriptor a Pass()-movable type.
This will make it possible to return a dbus::FileDescriptor from a function and bind it to a callback without wrapping it in a dbus::ScopedFileDescriptor. This will allow us to fix the generated DBus bindings to support methods that have file descriptors as output parameters. BUG=496469 Review URL: https://codereview.chromium.org/1170283005 Cr-Commit-Position: refs/heads/master@{#333901}
Diffstat (limited to 'dbus')
-rw-r--r--dbus/file_descriptor.cc20
-rw-r--r--dbus/file_descriptor.h13
2 files changed, 31 insertions, 2 deletions
diff --git a/dbus/file_descriptor.cc b/dbus/file_descriptor.cc
index e607fc0..c67a9e1 100644
--- a/dbus/file_descriptor.cc
+++ b/dbus/file_descriptor.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <algorithm>
+
#include "base/bind.h"
#include "base/files/file.h"
#include "base/location.h"
@@ -9,6 +11,8 @@
#include "base/threading/worker_pool.h"
#include "dbus/file_descriptor.h"
+using std::swap;
+
namespace dbus {
void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()(
@@ -17,11 +21,21 @@ void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()(
FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false);
}
+FileDescriptor::FileDescriptor(RValue other)
+ : value_(-1), owner_(false), valid_(false) {
+ Swap(other.object);
+}
+
FileDescriptor::~FileDescriptor() {
if (owner_)
base::File auto_closer(value_);
}
+FileDescriptor& FileDescriptor::operator=(RValue other) {
+ Swap(other.object);
+ return *this;
+}
+
int FileDescriptor::value() const {
CHECK(valid_);
return value_;
@@ -41,4 +55,10 @@ void FileDescriptor::CheckValidity() {
valid_ = (ok && !info.is_directory);
}
+void FileDescriptor::Swap(FileDescriptor* other) {
+ swap(value_, other->value_);
+ swap(owner_, other->owner_);
+ swap(valid_, other->valid_);
+}
+
} // namespace dbus
diff --git a/dbus/file_descriptor.h b/dbus/file_descriptor.h
index a01ee6e..8a41097 100644
--- a/dbus/file_descriptor.h
+++ b/dbus/file_descriptor.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/move.h"
#include "dbus/dbus_export.h"
namespace dbus {
@@ -33,6 +34,8 @@ namespace dbus {
// also allows the caller to do this work on the File thread to conform
// with i/o restrictions.
class CHROME_DBUS_EXPORT FileDescriptor {
+ MOVE_ONLY_TYPE_FOR_CPP_03(FileDescriptor, RValue);
+
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.
@@ -46,8 +49,14 @@ class CHROME_DBUS_EXPORT FileDescriptor {
explicit FileDescriptor(int value) : value_(value), owner_(false),
valid_(false) {}
+ // Move constructor for C++03 move emulation of this type.
+ FileDescriptor(RValue other);
+
virtual ~FileDescriptor();
+ // Move operator= for C++03 move emulation of this type.
+ FileDescriptor& operator=(RValue other);
+
// Retrieves value as an int without affecting ownership.
int value() const;
@@ -70,11 +79,11 @@ class CHROME_DBUS_EXPORT FileDescriptor {
void CheckValidity();
private:
+ void Swap(FileDescriptor* other);
+
int value_;
bool owner_;
bool valid_;
-
- DISALLOW_COPY_AND_ASSIGN(FileDescriptor);
};
using ScopedFileDescriptor =