| 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 #ifndef DBUS_FILE_DESCRIPTOR_H_ | 5 #ifndef DBUS_FILE_DESCRIPTOR_H_ |
| 6 #define DBUS_FILE_DESCRIPTOR_H_ | 6 #define DBUS_FILE_DESCRIPTOR_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/move.h" | 10 #include "base/move.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // the descriptor in fd will be closed if the PopUint32 fails. But | 27 // the descriptor in fd will be closed if the PopUint32 fails. But |
| 28 // writer.AppendFileDescriptor(dbus::FileDescriptor(1)); | 28 // writer.AppendFileDescriptor(dbus::FileDescriptor(1)); |
| 29 // will not automatically close "1" because it is not owned. | 29 // will not automatically close "1" because it is not owned. |
| 30 // | 30 // |
| 31 // Descriptors must be validated before marshalling in a D-Bus message | 31 // Descriptors must be validated before marshalling in a D-Bus message |
| 32 // or using them after unmarshalling. We disallow descriptors to a | 32 // or using them after unmarshalling. We disallow descriptors to a |
| 33 // directory to reduce the security risks. Splitting out validation | 33 // directory to reduce the security risks. Splitting out validation |
| 34 // also allows the caller to do this work on the File thread to conform | 34 // also allows the caller to do this work on the File thread to conform |
| 35 // with i/o restrictions. | 35 // with i/o restrictions. |
| 36 class CHROME_DBUS_EXPORT FileDescriptor { | 36 class CHROME_DBUS_EXPORT FileDescriptor { |
| 37 MOVE_ONLY_TYPE_FOR_CPP_03(FileDescriptor, RValue); | 37 MOVE_ONLY_TYPE_FOR_CPP_03(FileDescriptor); |
| 38 | 38 |
| 39 public: | 39 public: |
| 40 // This provides a simple way to pass around file descriptors since they must | 40 // This provides a simple way to pass around file descriptors since they must |
| 41 // be closed on a thread that is allowed to perform I/O. | 41 // be closed on a thread that is allowed to perform I/O. |
| 42 struct Deleter { | 42 struct Deleter { |
| 43 void CHROME_DBUS_EXPORT operator()(FileDescriptor* fd); | 43 void CHROME_DBUS_EXPORT operator()(FileDescriptor* fd); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // Permits initialization without a value for passing to | 46 // Permits initialization without a value for passing to |
| 47 // dbus::MessageReader::PopFileDescriptor to fill in and from int values. | 47 // dbus::MessageReader::PopFileDescriptor to fill in and from int values. |
| 48 FileDescriptor() : value_(-1), owner_(false), valid_(false) {} | 48 FileDescriptor() : value_(-1), owner_(false), valid_(false) {} |
| 49 explicit FileDescriptor(int value) : value_(value), owner_(false), | 49 explicit FileDescriptor(int value) : value_(value), owner_(false), |
| 50 valid_(false) {} | 50 valid_(false) {} |
| 51 | 51 |
| 52 // Move constructor for C++03 move emulation of this type. | 52 FileDescriptor(FileDescriptor&& other); |
| 53 FileDescriptor(RValue other); | |
| 54 | 53 |
| 55 virtual ~FileDescriptor(); | 54 virtual ~FileDescriptor(); |
| 56 | 55 |
| 57 // Move operator= for C++03 move emulation of this type. | 56 FileDescriptor& operator=(FileDescriptor&& other); |
| 58 FileDescriptor& operator=(RValue other); | |
| 59 | 57 |
| 60 // Retrieves value as an int without affecting ownership. | 58 // Retrieves value as an int without affecting ownership. |
| 61 int value() const; | 59 int value() const; |
| 62 | 60 |
| 63 // Retrieves whether or not the descriptor is ok to send/receive. | 61 // Retrieves whether or not the descriptor is ok to send/receive. |
| 64 int is_valid() const { return valid_; } | 62 int is_valid() const { return valid_; } |
| 65 | 63 |
| 66 // Sets the value and assign ownership. | 64 // Sets the value and assign ownership. |
| 67 void PutValue(int value) { | 65 void PutValue(int value) { |
| 68 value_ = value; | 66 value_ = value; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 bool owner_; | 83 bool owner_; |
| 86 bool valid_; | 84 bool valid_; |
| 87 }; | 85 }; |
| 88 | 86 |
| 89 using ScopedFileDescriptor = | 87 using ScopedFileDescriptor = |
| 90 scoped_ptr<FileDescriptor, FileDescriptor::Deleter>; | 88 scoped_ptr<FileDescriptor, FileDescriptor::Deleter>; |
| 91 | 89 |
| 92 } // namespace dbus | 90 } // namespace dbus |
| 93 | 91 |
| 94 #endif // DBUS_FILE_DESCRIPTOR_H_ | 92 #endif // DBUS_FILE_DESCRIPTOR_H_ |
| OLD | NEW |