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 base::File::Info info
;
53 bool ok
= file
.GetInfo(&info
);
54 file
.TakePlatformFile(); // Prevent |value_| from being closed by |file|.
55 valid_
= (ok
&& !info
.is_directory
);
58 void FileDescriptor::Swap(FileDescriptor
* other
) {
59 swap(value_
, other
->value_
);
60 swap(owner_
, other
->owner_
);
61 swap(valid_
, other
->valid_
);