| 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/logging.h" |
| 5 #include "base/platform_file.h" | 6 #include "base/platform_file.h" |
| 6 #include "dbus/file_descriptor.h" | 7 #include "dbus/file_descriptor.h" |
| 7 | 8 |
| 8 namespace dbus { | 9 namespace dbus { |
| 9 | 10 |
| 10 FileDescriptor::~FileDescriptor() { | 11 FileDescriptor::~FileDescriptor() { |
| 11 if (owner_) | 12 if (owner_) |
| 12 base::ClosePlatformFile(value_); | 13 base::ClosePlatformFile(value_); |
| 13 } | 14 } |
| 14 | 15 |
| 16 int FileDescriptor::value() const { |
| 17 CHECK(valid_); |
| 18 return value_; |
| 19 } |
| 20 |
| 21 int FileDescriptor::TakeValue() { |
| 22 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers |
| 23 owner_ = false; |
| 24 return value_; |
| 25 } |
| 26 |
| 27 void FileDescriptor::CheckValidity() { |
| 28 base::PlatformFileInfo info; |
| 29 bool ok = base::GetPlatformFileInfo(value_, &info); |
| 30 valid_ = (ok && !info.is_directory); |
| 31 } |
| 32 |
| 15 } // namespace dbus | 33 } // namespace dbus |
| OLD | NEW |