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