| 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 BrokerableAttachment; |
| 21 class MessageAttachment; | 22 class MessageAttachment; |
| 22 | 23 |
| 23 // ----------------------------------------------------------------------------- | 24 // ----------------------------------------------------------------------------- |
| 24 // A MessageAttachmentSet is an ordered set of MessageAttachment objects. These | 25 // A MessageAttachmentSet is an ordered set of MessageAttachment objects. These |
| 25 // are associated with IPC messages so that attachments, each of which is either | 26 // are associated with IPC messages so that attachments, each of which is either |
| 26 // a platform file or a mojo handle, can be transmitted over the underlying UNIX | 27 // a platform file or a mojo handle, can be transmitted over the underlying UNIX |
| 27 // domain socket (for ChannelPosix) or Mojo MessagePipe (for ChannelMojo). | 28 // domain socket (for ChannelPosix) or Mojo MessagePipe (for ChannelMojo). |
| 28 // ----------------------------------------------------------------------------- | 29 // ----------------------------------------------------------------------------- |
| 29 class IPC_EXPORT MessageAttachmentSet | 30 class IPC_EXPORT MessageAttachmentSet |
| 30 : public base::RefCountedThreadSafe<MessageAttachmentSet> { | 31 : public base::RefCountedThreadSafe<MessageAttachmentSet> { |
| 31 public: | 32 public: |
| 32 MessageAttachmentSet(); | 33 MessageAttachmentSet(); |
| 33 | 34 |
| 34 // Return the number of attachments | 35 // Return the number of attachments |
| 35 unsigned size() const; | 36 unsigned size() const; |
| 36 // Return the number of file descriptors | 37 // Return the number of file descriptors |
| 37 unsigned num_descriptors() const; | 38 unsigned num_descriptors() const; |
| 38 // Return the number of mojo handles in the attachment set | 39 // Return the number of mojo handles in the attachment set |
| 39 unsigned num_mojo_handles() const; | 40 unsigned num_mojo_handles() const; |
| 41 // Return the number of brokerable attachments in the attachment set. |
| 42 unsigned num_brokerable_attachments() const; |
| 40 | 43 |
| 41 // Return true if no unconsumed descriptors remain | 44 // Return true if no unconsumed descriptors remain |
| 42 bool empty() const { return 0 == size(); } | 45 bool empty() const { return 0 == size(); } |
| 43 | 46 |
| 44 bool AddAttachment(scoped_refptr<MessageAttachment> attachment); | 47 bool AddAttachment(scoped_refptr<MessageAttachment> attachment); |
| 45 | 48 |
| 46 // Take the nth attachment from the beginning of the set, Code using this | 49 // Take the nth attachment from the beginning of the set, Code using this |
| 47 // /must/ access the attachments in order, and must do it at most once. | 50 // /must/ access the attachments in order, and must do it at most once. |
| 48 // | 51 // |
| 49 // This interface is designed for the deserialising code as it doesn't | 52 // This interface is designed for the deserialising code as it doesn't |
| 50 // support close flags. | 53 // support close flags. |
| 51 // returns: an attachment, or nullptr on error | 54 // returns: an attachment, or nullptr on error |
| 52 scoped_refptr<MessageAttachment> GetAttachmentAt(unsigned index); | 55 scoped_refptr<MessageAttachment> GetAttachmentAt(unsigned index); |
| 53 | 56 |
| 54 // This must be called after transmitting the descriptors returned by | 57 // This must be called after transmitting the descriptors returned by |
| 55 // PeekDescriptors. It marks all the descriptors as consumed and closes those | 58 // PeekDescriptors. It marks all the descriptors as consumed and closes those |
| 56 // which are auto-close. | 59 // which are auto-close. |
| 57 void CommitAll(); | 60 void CommitAll(); |
| 58 | 61 |
| 62 // Returns a vector of all brokerable attachments. |
| 63 std::vector<const BrokerableAttachment*> PeekBrokerableAttachments() const; |
| 64 |
| 59 #if defined(OS_POSIX) | 65 #if defined(OS_POSIX) |
| 60 // This is the maximum number of descriptors per message. We need to know this | 66 // This is the maximum number of descriptors per message. We need to know this |
| 61 // because the control message kernel interface has to be given a buffer which | 67 // because the control message kernel interface has to be given a buffer which |
| 62 // is large enough to store all the descriptor numbers. Otherwise the kernel | 68 // is large enough to store all the descriptor numbers. Otherwise the kernel |
| 63 // tells us that it truncated the control data and the extra descriptors are | 69 // tells us that it truncated the control data and the extra descriptors are |
| 64 // lost. | 70 // lost. |
| 65 // | 71 // |
| 66 // In debugging mode, it's a fatal error to try and add more than this number | 72 // In debugging mode, it's a fatal error to try and add more than this number |
| 67 // of descriptors to a MessageAttachmentSet. | 73 // of descriptors to a MessageAttachmentSet. |
| 68 static const size_t kMaxDescriptorsPerMessage = 7; | 74 static const size_t kMaxDescriptorsPerMessage = 7; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // all the descriptors have been read (with GetNthDescriptor). Secondly, we | 115 // all the descriptors have been read (with GetNthDescriptor). Secondly, we |
| 110 // can check that they are read in order. | 116 // can check that they are read in order. |
| 111 mutable unsigned consumed_descriptor_highwater_; | 117 mutable unsigned consumed_descriptor_highwater_; |
| 112 | 118 |
| 113 DISALLOW_COPY_AND_ASSIGN(MessageAttachmentSet); | 119 DISALLOW_COPY_AND_ASSIGN(MessageAttachmentSet); |
| 114 }; | 120 }; |
| 115 | 121 |
| 116 } // namespace IPC | 122 } // namespace IPC |
| 117 | 123 |
| 118 #endif // IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ | 124 #endif // IPC_IPC_MESSAGE_ATTACHMENT_SET_H_ |
| OLD | NEW |