summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_platform_file_attachment_posix.h
diff options
context:
space:
mode:
authormorrita <morrita@chromium.org>2015-01-30 21:45:42 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-31 05:47:43 +0000
commit1aa788c1f3c5f356b4e06110b5780a1de99c4cd7 (patch)
treeacbbb590d3c776180f6a0d1204f44ceda33058c0 /ipc/ipc_platform_file_attachment_posix.h
parentf61604541419bac129d2cd88b3d42039f6014161 (diff)
downloadchromium_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_platform_file_attachment_posix.h')
-rw-r--r--ipc/ipc_platform_file_attachment_posix.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/ipc/ipc_platform_file_attachment_posix.h b/ipc/ipc_platform_file_attachment_posix.h
new file mode 100644
index 0000000..d1eff60
--- /dev/null
+++ b/ipc/ipc_platform_file_attachment_posix.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_
+#define IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_
+
+#include "ipc/ipc_export.h"
+#include "ipc/ipc_message_attachment.h"
+
+namespace IPC {
+namespace internal {
+
+// A platform file that is sent over |Channel| as a part of |Message|.
+// PlatformFileAttachment optionally owns the file and |owning_| is set in that
+// case. Also, |file_| is not cleared even after the ownership is taken.
+// Some old clients require this strange behavior.
+class IPC_EXPORT PlatformFileAttachment : public MessageAttachment {
+ public:
+ // Non-owning constructor
+ explicit PlatformFileAttachment(base::PlatformFile file);
+ // Owning constructor
+ explicit PlatformFileAttachment(base::ScopedFD file);
+
+ Type GetType() const override;
+ base::PlatformFile TakePlatformFile() override;
+
+ base::PlatformFile file() const { return file_; }
+ bool Owns() const { return owning_.is_valid(); }
+
+ private:
+ ~PlatformFileAttachment() override;
+
+ base::PlatformFile file_;
+ base::ScopedFD owning_;
+};
+
+base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment);
+
+} // namespace internal
+} // namespace IPC
+
+#endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_