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.
6 #include "base/files/file.h"
7 #include "base/location.h"
8 #include "base/logging.h"
9 #include "base/threading/worker_pool.h"
10 #include "dbus/file_descriptor.h"
14 void CHROME_DBUS_EXPORT
FileDescriptor::Deleter::operator()(
16 base::WorkerPool::PostTask(
17 FROM_HERE
, base::Bind(&base::DeletePointer
<FileDescriptor
>, fd
), false);
20 FileDescriptor::~FileDescriptor() {
22 base::File
auto_closer(value_
);
25 int FileDescriptor::value() const {
30 int FileDescriptor::TakeValue() {
31 CHECK(valid_
); // NB: check first so owner_ is unchanged if this triggers
36 void FileDescriptor::CheckValidity() {
37 base::File
file(value_
);
38 base::File::Info info
;
39 bool ok
= file
.GetInfo(&info
);
40 file
.TakePlatformFile(); // Prevent |value_| from being closed by |file|.
41 valid_
= (ok
&& !info
.is_directory
);