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 #include "ipc/ipc_message_attachment_set.h" | 5 #include "ipc/ipc_message_attachment_set.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/posix/eintr_wrapper.h" | 9 #include "base/posix/eintr_wrapper.h" |
10 #include "ipc/brokerable_attachment.h" | |
10 #include "ipc/ipc_message_attachment.h" | 11 #include "ipc/ipc_message_attachment.h" |
11 | 12 |
12 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
13 #include <sys/types.h> | 14 #include <sys/types.h> |
14 #include <sys/stat.h> | 15 #include <sys/stat.h> |
15 #include <unistd.h> | 16 #include <unistd.h> |
16 #include "ipc/ipc_platform_file_attachment_posix.h" | 17 #include "ipc/ipc_platform_file_attachment_posix.h" |
17 #endif // OS_POSIX | 18 #endif // OS_POSIX |
18 | 19 |
19 namespace IPC { | 20 namespace IPC { |
(...skipping 25 matching lines...) Expand all Loading... | |
45 }); | 46 }); |
46 } | 47 } |
47 | 48 |
48 unsigned MessageAttachmentSet::num_mojo_handles() const { | 49 unsigned MessageAttachmentSet::num_mojo_handles() const { |
49 return std::count_if(attachments_.begin(), attachments_.end(), | 50 return std::count_if(attachments_.begin(), attachments_.end(), |
50 [](scoped_refptr<MessageAttachment> i) { | 51 [](scoped_refptr<MessageAttachment> i) { |
51 return i->GetType() == MessageAttachment::TYPE_MOJO_HANDLE; | 52 return i->GetType() == MessageAttachment::TYPE_MOJO_HANDLE; |
52 }); | 53 }); |
53 } | 54 } |
54 | 55 |
56 unsigned MessageAttachmentSet::num_brokerable_attachments() const { | |
57 return std::count_if(attachments_.begin(), attachments_.end(), | |
Tom Sepez
2015/06/19 18:04:11
C++11 std library not yet allowed AFAIK (as much a
erikchen
2015/06/23 22:37:00
The latter problem could be fixed, but the former
| |
58 [](scoped_refptr<MessageAttachment> i) { | |
59 return i->GetType() == | |
60 MessageAttachment::TYPE_BROKERABLE_ATTACHMENT; | |
61 }); | |
62 } | |
63 | |
55 unsigned MessageAttachmentSet::size() const { | 64 unsigned MessageAttachmentSet::size() const { |
56 return static_cast<unsigned>(attachments_.size()); | 65 return static_cast<unsigned>(attachments_.size()); |
57 } | 66 } |
58 | 67 |
59 bool MessageAttachmentSet::AddAttachment( | 68 bool MessageAttachmentSet::AddAttachment( |
60 scoped_refptr<MessageAttachment> attachment) { | 69 scoped_refptr<MessageAttachment> attachment) { |
61 #if defined(OS_POSIX) | 70 #if defined(OS_POSIX) |
62 if (attachment->GetType() == MessageAttachment::TYPE_PLATFORM_FILE && | 71 if (attachment->GetType() == MessageAttachment::TYPE_PLATFORM_FILE && |
63 num_descriptors() == kMaxDescriptorsPerMessage) { | 72 num_descriptors() == kMaxDescriptorsPerMessage) { |
64 DLOG(WARNING) << "Cannot add file descriptor. MessageAttachmentSet full."; | 73 DLOG(WARNING) << "Cannot add file descriptor. MessageAttachmentSet full."; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 consumed_descriptor_highwater_ = index + 1; | 116 consumed_descriptor_highwater_ = index + 1; |
108 | 117 |
109 return attachments_[index]; | 118 return attachments_[index]; |
110 } | 119 } |
111 | 120 |
112 void MessageAttachmentSet::CommitAll() { | 121 void MessageAttachmentSet::CommitAll() { |
113 attachments_.clear(); | 122 attachments_.clear(); |
114 consumed_descriptor_highwater_ = 0; | 123 consumed_descriptor_highwater_ = 0; |
115 } | 124 } |
116 | 125 |
126 std::vector<scoped_refptr<BrokerableAttachment>> | |
127 MessageAttachmentSet::PeekBrokerableAttachments() const { | |
128 std::vector<scoped_refptr<BrokerableAttachment>> output; | |
129 for (const scoped_refptr<MessageAttachment>& attachment : attachments_) { | |
130 if (attachment->GetType() == | |
131 MessageAttachment::TYPE_BROKERABLE_ATTACHMENT) { | |
132 scoped_refptr<BrokerableAttachment> brokerable_attachment( | |
133 static_cast<BrokerableAttachment*>(attachment.get())); | |
134 output.push_back(brokerable_attachment); | |
135 } | |
136 } | |
137 return output; | |
138 } | |
139 | |
117 #if defined(OS_POSIX) | 140 #if defined(OS_POSIX) |
118 | 141 |
119 void MessageAttachmentSet::PeekDescriptors(base::PlatformFile* buffer) const { | 142 void MessageAttachmentSet::PeekDescriptors(base::PlatformFile* buffer) const { |
120 for (size_t i = 0; i != attachments_.size(); ++i) | 143 for (size_t i = 0; i != attachments_.size(); ++i) |
121 buffer[i] = internal::GetPlatformFile(attachments_[i]); | 144 buffer[i] = internal::GetPlatformFile(attachments_[i]); |
122 } | 145 } |
123 | 146 |
124 bool MessageAttachmentSet::ContainsDirectoryDescriptor() const { | 147 bool MessageAttachmentSet::ContainsDirectoryDescriptor() const { |
125 struct stat st; | 148 struct stat st; |
126 | 149 |
(...skipping 27 matching lines...) Expand all Loading... | |
154 for (unsigned i = 0; i < count; ++i) | 177 for (unsigned i = 0; i < count; ++i) |
155 AddAttachment( | 178 AddAttachment( |
156 new internal::PlatformFileAttachment(base::ScopedFD(buffer[i]))); | 179 new internal::PlatformFileAttachment(base::ScopedFD(buffer[i]))); |
157 } | 180 } |
158 | 181 |
159 #endif // OS_POSIX | 182 #endif // OS_POSIX |
160 | 183 |
161 } // namespace IPC | 184 } // namespace IPC |
162 | 185 |
163 | 186 |
OLD | NEW |