Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ | 5 #ifndef IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ |
| 6 #define IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ | 6 #define IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "ipc/ipc_export.h" | 13 #include "ipc/ipc_export.h" |
| 14 | 14 |
| 15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
| 16 #include "base/files/file.h" | 16 #include "base/files/file.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace IPC { | 19 namespace IPC { |
| 20 | 20 |
| 21 class MessageAttachment; | |
| 22 | |
| 21 // ----------------------------------------------------------------------------- | 23 // ----------------------------------------------------------------------------- |
| 22 // A MessageAttachmentSet is an ordered set of POSIX file descriptors. These are | 24 // A MessageAttachmentSet is an ordered set of POSIX file descriptors. These are |
| 23 // associated with IPC messages so that descriptors can be transmitted over a | 25 // associated with IPC messages so that descriptors can be transmitted over a |
| 24 // UNIX domain socket. | 26 // UNIX domain socket. |
| 25 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
| 26 class IPC_EXPORT MessageAttachmentSet | 28 class IPC_EXPORT MessageAttachmentSet |
| 27 : public base::RefCountedThreadSafe<MessageAttachmentSet> { | 29 : public base::RefCountedThreadSafe<MessageAttachmentSet> { |
| 28 public: | 30 public: |
| 29 MessageAttachmentSet(); | 31 MessageAttachmentSet(); |
| 30 | 32 |
| 31 // Return the number of descriptors | 33 // Return the number of attachmentes |
|
agl
2015/01/15 03:00:53
attachments
Hajime Morrita
2015/01/23 00:29:05
Done.
| |
| 32 unsigned size() const; | 34 unsigned size() const; |
| 35 // Return the number of file descriptors | |
| 36 unsigned file_size() const; | |
|
agl
2015/01/15 03:00:53
file_size seems like a poor name for this.
num_fd
Hajime Morrita
2015/01/23 00:29:05
Makes sense. Renamed to num_descriptors().
| |
| 33 // Return true if no unconsumed descriptors remain | 37 // Return true if no unconsumed descriptors remain |
| 34 bool empty() const { return 0 == size(); } | 38 bool empty() const { return 0 == size(); } |
| 35 | 39 |
| 40 void AddAttachment(scoped_refptr<MessageAttachment> attachment); | |
| 41 scoped_refptr<MessageAttachment> TakeAttachmentAt(unsigned index); | |
|
agl
2015/01/15 03:00:53
It's called TakeAttachmentAt, but it returns a ref
Hajime Morrita
2015/01/23 00:29:05
Uh, the name was leftover of my failed experiment.
| |
| 42 | |
| 36 #if defined(OS_POSIX) | 43 #if defined(OS_POSIX) |
| 37 // This is the maximum number of descriptors per message. We need to know this | 44 // This is the maximum number of descriptors per message. We need to know this |
| 38 // because the control message kernel interface has to be given a buffer which | 45 // because the control message kernel interface has to be given a buffer which |
| 39 // is large enough to store all the descriptor numbers. Otherwise the kernel | 46 // is large enough to store all the descriptor numbers. Otherwise the kernel |
| 40 // tells us that it truncated the control data and the extra descriptors are | 47 // tells us that it truncated the control data and the extra descriptors are |
| 41 // lost. | 48 // lost. |
| 42 // | 49 // |
| 43 // In debugging mode, it's a fatal error to try and add more than this number | 50 // In debugging mode, it's a fatal error to try and add more than this number |
| 44 // of descriptors to a MessageAttachmentSet. | 51 // of descriptors to a MessageAttachmentSet. |
| 45 static const size_t kMaxDescriptorsPerMessage = 7; | 52 static const size_t kMaxDescriptorsPerMessage = 7; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 105 |
| 99 #endif // OS_POSIX | 106 #endif // OS_POSIX |
| 100 | 107 |
| 101 // --------------------------------------------------------------------------- | 108 // --------------------------------------------------------------------------- |
| 102 | 109 |
| 103 private: | 110 private: |
| 104 friend class base::RefCountedThreadSafe<MessageAttachmentSet>; | 111 friend class base::RefCountedThreadSafe<MessageAttachmentSet>; |
| 105 | 112 |
| 106 ~MessageAttachmentSet(); | 113 ~MessageAttachmentSet(); |
| 107 | 114 |
| 115 // A vector of attachments of the message, which might be |PlatformFile| or | |
| 116 // |MessagePipe|. | |
| 117 std::vector<scoped_refptr<MessageAttachment>> attachments_; | |
| 118 | |
| 108 #if defined(OS_POSIX) | 119 #if defined(OS_POSIX) |
| 109 // A vector of descriptors and close flags. If this message is sent, then | 120 // A vector of owning descriptors If this message is sent, then file |
|
agl
2015/01/15 03:00:53
. after "descriptors"
Hajime Morrita
2015/01/23 00:29:05
Done.
| |
| 110 // these descriptors are sent as control data. After sending, any descriptors | 121 // descriptors are sent as control data. After sending, any owning descriptors |
| 111 // with a true flag are closed. If this message has been received, then these | 122 // are closed. If this message has been received, then all received |
|
agl
2015/01/15 03:00:53
no comma before "then" (existing issue).
Hajime Morrita
2015/01/23 00:29:05
Done.
| |
| 112 // are the descriptors which were received and all close flags are true. | 123 // descriptors are owned by this message. |
| 113 std::vector<base::PlatformFile> descriptors_; | |
| 114 ScopedVector<base::ScopedFD> owned_descriptors_; | 124 ScopedVector<base::ScopedFD> owned_descriptors_; |
| 115 #endif | 125 #endif |
| 116 | 126 |
| 117 // This contains the index of the next descriptor which should be consumed. | 127 // This contains the index of the next descriptor which should be consumed. |
| 118 // It's used in a couple of ways. Firstly, at destruction we can check that | 128 // It's used in a couple of ways. Firstly, at destruction we can check that |
| 119 // all the descriptors have been read (with GetNthDescriptor). Secondly, we | 129 // all the descriptors have been read (with GetNthDescriptor). Secondly, we |
| 120 // can check that they are read in order. | 130 // can check that they are read in order. |
| 121 mutable unsigned consumed_descriptor_highwater_; | 131 mutable unsigned consumed_descriptor_highwater_; |
| 122 | 132 |
| 123 DISALLOW_COPY_AND_ASSIGN(MessageAttachmentSet); | 133 DISALLOW_COPY_AND_ASSIGN(MessageAttachmentSet); |
| 124 }; | 134 }; |
| 125 | 135 |
| 126 } // namespace IPC | 136 } // namespace IPC |
| 127 | 137 |
| 128 #endif // IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ | 138 #endif // IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ |
| OLD | NEW |