Add mips support to install-debian.wheezy.sysroot.py
[chromium-blink-merge.git] / dbus / file_descriptor.cc
blobe607fc01356d8ca284f0ea1732150a0a43a3bf69
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.
5 #include "base/bind.h"
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"
12 namespace dbus {
14 void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()(
15 FileDescriptor* fd) {
16 base::WorkerPool::PostTask(
17 FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false);
20 FileDescriptor::~FileDescriptor() {
21 if (owner_)
22 base::File auto_closer(value_);
25 int FileDescriptor::value() const {
26 CHECK(valid_);
27 return value_;
30 int FileDescriptor::TakeValue() {
31 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers
32 owner_ = false;
33 return value_;
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);
44 } // namespace dbus