OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/threading/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
12 #include "dbus/file_descriptor.h" | 12 #include "dbus/file_descriptor.h" |
13 | 13 |
14 using std::swap; | 14 using std::swap; |
15 | 15 |
16 namespace dbus { | 16 namespace dbus { |
17 | 17 |
18 void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()( | 18 void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()( |
19 FileDescriptor* fd) { | 19 FileDescriptor* fd) { |
20 base::WorkerPool::PostTask( | 20 base::WorkerPool::PostTask( |
21 FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false); | 21 FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false); |
22 } | 22 } |
23 | 23 |
24 FileDescriptor::FileDescriptor(RValue other) | 24 FileDescriptor::FileDescriptor(FileDescriptor&& other) : FileDescriptor() { |
25 : value_(-1), owner_(false), valid_(false) { | 25 Swap(&other); |
26 Swap(other.object); | |
27 } | 26 } |
28 | 27 |
29 FileDescriptor::~FileDescriptor() { | 28 FileDescriptor::~FileDescriptor() { |
30 if (owner_) | 29 if (owner_) |
31 base::File auto_closer(value_); | 30 base::File auto_closer(value_); |
32 } | 31 } |
33 | 32 |
34 FileDescriptor& FileDescriptor::operator=(RValue other) { | 33 FileDescriptor& FileDescriptor::operator=(FileDescriptor&& other) { |
35 Swap(other.object); | 34 Swap(&other); |
36 return *this; | 35 return *this; |
37 } | 36 } |
38 | 37 |
39 int FileDescriptor::value() const { | 38 int FileDescriptor::value() const { |
40 CHECK(valid_); | 39 CHECK(valid_); |
41 return value_; | 40 return value_; |
42 } | 41 } |
43 | 42 |
44 int FileDescriptor::TakeValue() { | 43 int FileDescriptor::TakeValue() { |
45 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers | 44 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers |
(...skipping 14 matching lines...) Expand all Loading... |
60 valid_ = (ok && !info.is_directory); | 59 valid_ = (ok && !info.is_directory); |
61 } | 60 } |
62 | 61 |
63 void FileDescriptor::Swap(FileDescriptor* other) { | 62 void FileDescriptor::Swap(FileDescriptor* other) { |
64 swap(value_, other->value_); | 63 swap(value_, other->value_); |
65 swap(owner_, other->owner_); | 64 swap(owner_, other->owner_); |
66 swap(valid_, other->valid_); | 65 swap(valid_, other->valid_); |
67 } | 66 } |
68 | 67 |
69 } // namespace dbus | 68 } // namespace dbus |
OLD | NEW |