diff options
author | morrita <morrita@chromium.org> | 2015-01-30 21:45:42 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-31 05:47:43 +0000 |
commit | 1aa788c1f3c5f356b4e06110b5780a1de99c4cd7 (patch) | |
tree | acbbb590d3c776180f6a0d1204f44ceda33058c0 /ipc/ipc_message.cc | |
parent | f61604541419bac129d2cd88b3d42039f6014161 (diff) | |
download | chromium_src-1aa788c1f3c5f356b4e06110b5780a1de99c4cd7.zip chromium_src-1aa788c1f3c5f356b4e06110b5780a1de99c4cd7.tar.gz chromium_src-1aa788c1f3c5f356b4e06110b5780a1de99c4cd7.tar.bz2 |
IPC::Message Refactoring: Move POSIX specific bits to PlatformFileAttachment
This change:
* Gets rid of MessageAttachmentSet::owning_descriptors_ by moving
the responsibility to PlatformFileAttachment, where owning_
member variable is used to track the lifetime
* Replaces MessageAttachmetnSet::Add*File() and TakePlatformFile()
with platform agnostic AddAttachment() and GetAttachmentAt()
* Repalces Message::ReadFile(), Write*File() with ReadAttachment()
and WriteAttachmente(), which are also platform agnostic.
This also adds MessageAttachment::TakePlatformFile() virtual function,
which will be implemented by upcoming MojoHandleAttachment as well.
This is another preparation for introducing MojoHandleAttachment,
but it also simplifies Message and MessageAttachmentSet.
R=agl@chromium.org
TBR=mtomasz@chromium.org
BUG=448190
Review URL: https://codereview.chromium.org/883093003
Cr-Commit-Position: refs/heads/master@{#314047}
Diffstat (limited to 'ipc/ipc_message.cc')
-rw-r--r-- | ipc/ipc_message.cc | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/ipc/ipc_message.cc b/ipc/ipc_message.cc index 3f36dcf..c5a5a83 100644 --- a/ipc/ipc_message.cc +++ b/ipc/ipc_message.cc @@ -7,10 +7,12 @@ #include "base/atomic_sequence_num.h" #include "base/logging.h" #include "build/build_config.h" +#include "ipc/ipc_message_attachment.h" #include "ipc/ipc_message_attachment_set.h" #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" +#include "ipc/ipc_platform_file_attachment_posix.h" #endif namespace { @@ -127,22 +129,16 @@ void Message::set_received_time(int64 time) const { } #endif -#if defined(OS_POSIX) -bool Message::WriteFile(base::ScopedFD descriptor) { - // We write the index of the descriptor so that we don't have to - // keep the current descriptor as extra decoding state when deserialising. - WriteInt(attachment_set()->size()); - return attachment_set()->AddToOwn(descriptor.Pass()); -} - -bool Message::WriteBorrowingFile(const base::PlatformFile& descriptor) { +bool Message::WriteAttachment(scoped_refptr<MessageAttachment> attachment) { // We write the index of the descriptor so that we don't have to // keep the current descriptor as extra decoding state when deserialising. WriteInt(attachment_set()->size()); - return attachment_set()->AddToBorrow(descriptor); + return attachment_set()->AddAttachment(attachment); } -bool Message::ReadFile(PickleIterator* iter, base::ScopedFD* descriptor) const { +bool Message::ReadAttachment( + PickleIterator* iter, + scoped_refptr<MessageAttachment>* attachment) const { int descriptor_index; if (!iter->ReadInt(&descriptor_index)) return false; @@ -151,18 +147,12 @@ bool Message::ReadFile(PickleIterator* iter, base::ScopedFD* descriptor) const { if (!attachment_set) return false; - base::PlatformFile file = attachment_set->TakeDescriptorAt(descriptor_index); - if (file < 0) - return false; - - descriptor->reset(file); - return true; + *attachment = attachment_set->GetAttachmentAt(descriptor_index); + return nullptr != attachment->get(); } -bool Message::HasFileDescriptors() const { +bool Message::HasAttachments() const { return attachment_set_.get() && !attachment_set_->empty(); } -#endif - } // namespace IPC |