Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(835)

Unified Diff: ipc/ipc_message_attachment_set.cc

Issue 1188923003: Stub in more IPC attachment brokering functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase properly. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_message_attachment_set.h ('k') | ipc/ipc_message_generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_message_attachment_set.cc
diff --git a/ipc/ipc_message_attachment_set.cc b/ipc/ipc_message_attachment_set.cc
index cb74a5aaf07193c8d57367923a52557d40999ab4..ed653f3466a3595aaa1e889e5f7c433ef184a8be 100644
--- a/ipc/ipc_message_attachment_set.cc
+++ b/ipc/ipc_message_attachment_set.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
+#include "ipc/brokerable_attachment.h"
#include "ipc/ipc_message_attachment.h"
#if defined(OS_POSIX)
@@ -18,6 +19,21 @@
namespace IPC {
+namespace {
+
+unsigned count_attachments_of_type(
+ const std::vector<scoped_refptr<MessageAttachment>>& attachments,
+ MessageAttachment::Type type) {
+ unsigned count = 0;
+ for (const scoped_refptr<MessageAttachment>& attachment : attachments) {
+ if (attachment->GetType() == type)
+ ++count;
+ }
+ return count;
+}
+
+} // namespace
+
MessageAttachmentSet::MessageAttachmentSet()
: consumed_descriptor_highwater_(0) {
}
@@ -39,17 +55,18 @@ MessageAttachmentSet::~MessageAttachmentSet() {
}
unsigned MessageAttachmentSet::num_descriptors() const {
- return std::count_if(attachments_.begin(), attachments_.end(),
- [](scoped_refptr<MessageAttachment> i) {
- return i->GetType() == MessageAttachment::TYPE_PLATFORM_FILE;
- });
+ return count_attachments_of_type(attachments_,
+ MessageAttachment::TYPE_PLATFORM_FILE);
}
unsigned MessageAttachmentSet::num_mojo_handles() const {
- return std::count_if(attachments_.begin(), attachments_.end(),
- [](scoped_refptr<MessageAttachment> i) {
- return i->GetType() == MessageAttachment::TYPE_MOJO_HANDLE;
- });
+ return count_attachments_of_type(attachments_,
+ MessageAttachment::TYPE_MOJO_HANDLE);
+}
+
+unsigned MessageAttachmentSet::num_brokerable_attachments() const {
+ return count_attachments_of_type(
+ attachments_, MessageAttachment::TYPE_BROKERABLE_ATTACHMENT);
}
unsigned MessageAttachmentSet::size() const {
@@ -114,6 +131,18 @@ void MessageAttachmentSet::CommitAll() {
consumed_descriptor_highwater_ = 0;
}
+std::vector<const BrokerableAttachment*>
+MessageAttachmentSet::PeekBrokerableAttachments() const {
+ std::vector<const BrokerableAttachment*> output;
+ for (const scoped_refptr<MessageAttachment>& attachment : attachments_) {
+ if (attachment->GetType() ==
+ MessageAttachment::TYPE_BROKERABLE_ATTACHMENT) {
+ output.push_back(static_cast<BrokerableAttachment*>(attachment.get()));
+ }
+ }
+ return output;
+}
+
#if defined(OS_POSIX)
void MessageAttachmentSet::PeekDescriptors(base::PlatformFile* buffer) const {
« no previous file with comments | « ipc/ipc_message_attachment_set.h ('k') | ipc/ipc_message_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698