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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/worker_pool.h" | 9 #include "base/threading/worker_pool.h" |
10 #include "dbus/file_descriptor.h" | 10 #include "dbus/file_descriptor.h" |
11 | 11 |
12 namespace dbus { | 12 namespace dbus { |
13 | 13 |
14 void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()( | 14 void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()( |
15 FileDescriptor* fd) { | 15 FileDescriptor* fd) { |
16 base::WorkerPool::PostTask( | 16 base::WorkerPool::PostTask( |
17 FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false); | 17 FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false); |
18 } | 18 } |
19 | 19 |
20 FileDescriptor::FileDescriptor(RValue other) | |
21 : value_(other.object->value_), | |
22 owner_(other.object->owner_), | |
23 valid_(other.object->valid_) { | |
24 other.object->value_ = -1; | |
25 other.object->valid_ = false; | |
26 other.object->owner_ = false; | |
27 } | |
28 | |
20 FileDescriptor::~FileDescriptor() { | 29 FileDescriptor::~FileDescriptor() { |
21 if (owner_) | 30 if (owner_) |
22 base::File auto_closer(value_); | 31 base::File auto_closer(value_); |
23 } | 32 } |
24 | 33 |
34 FileDescriptor& FileDescriptor::operator=(RValue other) { | |
35 value_ = other.object->value_; | |
Alex Vakulenko
2015/06/10 18:55:47
I think here you should do just std::swap() on eac
Reilly Grant (use Gerrit)
2015/06/10 19:21:10
Done.
| |
36 owner_ = other.object->owner_; | |
37 valid_ = other.object->valid_; | |
38 other.object->value_ = -1; | |
39 other.object->valid_ = false; | |
40 other.object->owner_ = false; | |
41 return *this; | |
42 } | |
43 | |
25 int FileDescriptor::value() const { | 44 int FileDescriptor::value() const { |
26 CHECK(valid_); | 45 CHECK(valid_); |
27 return value_; | 46 return value_; |
28 } | 47 } |
29 | 48 |
30 int FileDescriptor::TakeValue() { | 49 int FileDescriptor::TakeValue() { |
31 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers | 50 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers |
32 owner_ = false; | 51 owner_ = false; |
33 return value_; | 52 return value_; |
34 } | 53 } |
35 | 54 |
36 void FileDescriptor::CheckValidity() { | 55 void FileDescriptor::CheckValidity() { |
37 base::File file(value_); | 56 base::File file(value_); |
38 base::File::Info info; | 57 base::File::Info info; |
39 bool ok = file.GetInfo(&info); | 58 bool ok = file.GetInfo(&info); |
40 file.TakePlatformFile(); // Prevent |value_| from being closed by |file|. | 59 file.TakePlatformFile(); // Prevent |value_| from being closed by |file|. |
41 valid_ = (ok && !info.is_directory); | 60 valid_ = (ok && !info.is_directory); |
42 } | 61 } |
43 | 62 |
44 } // namespace dbus | 63 } // namespace dbus |
OLD | NEW |