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
3 // found in the LICENSE file.
8 #include "base/files/file.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "base/threading/worker_pool.h"
12 #include "dbus/file_descriptor.h"
18 void CHROME_DBUS_EXPORT
FileDescriptor::Deleter::operator()(
20 base::WorkerPool::PostTask(
21 FROM_HERE
, base::Bind(&base::DeletePointer
<FileDescriptor
>, fd
), false);
24 FileDescriptor::FileDescriptor(RValue other
)
25 : value_(-1), owner_(false), valid_(false) {
29 FileDescriptor::~FileDescriptor() {
31 base::File
auto_closer(value_
);
34 FileDescriptor
& FileDescriptor::operator=(RValue other
) {
39 int FileDescriptor::value() const {
44 int FileDescriptor::TakeValue() {
45 CHECK(valid_
); // NB: check first so owner_ is unchanged if this triggers
50 void FileDescriptor::CheckValidity() {
51 base::File
file(value_
);
52 if (!file
.IsValid()) {
57 base::File::Info info
;
58 bool ok
= file
.GetInfo(&info
);
59 file
.TakePlatformFile(); // Prevent |value_| from being closed by |file|.
60 valid_
= (ok
&& !info
.is_directory
);
63 void FileDescriptor::Swap(FileDescriptor
* other
) {
64 swap(value_
, other
->value_
);
65 swap(owner_
, other
->owner_
);
66 swap(valid_
, other
->valid_
);