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/files/file.h" | 6 #include "base/files/file.h" |
| 7 #include "base/location.h" |
6 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/worker_pool.h" |
7 #include "dbus/file_descriptor.h" | 10 #include "dbus/file_descriptor.h" |
8 | 11 |
9 namespace dbus { | 12 namespace dbus { |
10 | 13 |
| 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); |
| 18 } |
| 19 |
11 FileDescriptor::~FileDescriptor() { | 20 FileDescriptor::~FileDescriptor() { |
12 if (owner_) | 21 if (owner_) |
13 base::File auto_closer(value_); | 22 base::File auto_closer(value_); |
14 } | 23 } |
15 | 24 |
16 int FileDescriptor::value() const { | 25 int FileDescriptor::value() const { |
17 CHECK(valid_); | 26 CHECK(valid_); |
18 return value_; | 27 return value_; |
19 } | 28 } |
20 | 29 |
21 int FileDescriptor::TakeValue() { | 30 int FileDescriptor::TakeValue() { |
22 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers | 31 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers |
23 owner_ = false; | 32 owner_ = false; |
24 return value_; | 33 return value_; |
25 } | 34 } |
26 | 35 |
27 void FileDescriptor::CheckValidity() { | 36 void FileDescriptor::CheckValidity() { |
28 base::File file(value_); | 37 base::File file(value_); |
29 base::File::Info info; | 38 base::File::Info info; |
30 bool ok = file.GetInfo(&info); | 39 bool ok = file.GetInfo(&info); |
31 file.TakePlatformFile(); // Prevent |value_| from being closed by |file|. | 40 file.TakePlatformFile(); // Prevent |value_| from being closed by |file|. |
32 valid_ = (ok && !info.is_directory); | 41 valid_ = (ok && !info.is_directory); |
33 } | 42 } |
34 | 43 |
35 } // namespace dbus | 44 } // namespace dbus |
OLD | NEW |