Index: dbus/file_descriptor.cc |
diff --git a/dbus/file_descriptor.cc b/dbus/file_descriptor.cc |
index e607fc01356d8ca284f0ea1732150a0a43a3bf69..c67a9e1900bab2f3f737d2ecba4cab358d43eec2 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 |