Chromium Code Reviews| 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 // Retrieves value as an int without affecting ownership. | |
|
satorux1
2012/05/10 07:16:56
the comment looks identical to the one in .h, if s
Sam Leffler
2012/05/10 15:59:32
Done.
| |
| 17 int FileDescriptor::value() const { | |
| 18 CHECK(valid_); | |
|
satorux1
2012/05/09 22:12:09
We usually use DCHECK(). IIRC, CHECK is used only
satorux1
2012/05/10 07:16:56
I think I was wrong. If valid_ is false, this is s
Sam Leffler
2012/05/10 15:59:32
Correct, this preserves the previous behaviour tha
| |
| 19 return value_; | |
| 20 } | |
| 21 | |
| 22 // Takes the value and ownership. | |
|
satorux1
2012/05/10 07:16:56
the comment looks identical to the one in .h, if s
Sam Leffler
2012/05/10 15:59:32
Done.
| |
| 23 int FileDescriptor::TakeValue() { | |
| 24 CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers | |
|
satorux1
2012/05/09 22:12:09
ditto.
| |
| 25 owner_ = false; | |
| 26 return value_; | |
| 27 } | |
| 28 | |
| 29 // Checks if |value_| is suitable for sending/receiving. We disallow | |
| 30 // directories to avoid potential sandbox escapes. Note this call must | |
| 31 // be made on the File thread. | |
|
satorux1
2012/05/10 07:16:56
move this comment to .h file? The users of this fu
Sam Leffler
2012/05/10 15:59:32
Done.
| |
| 32 void FileDescriptor::CheckValidity() { | |
| 33 base::PlatformFileInfo info; | |
| 34 bool ok = base::GetPlatformFileInfo(value_, &info); | |
| 35 valid_ = (ok && !info.is_directory); | |
| 36 } | |
| 37 | |
| 15 } // namespace dbus | 38 } // namespace dbus |
| OLD | NEW |