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.

[email protected]
[email protected]
BUG=448190

Review URL: https://codereview.chromium.org/883093003

Cr-Commit-Position: refs/heads/master@{#314047}
diff --git a/ipc/ipc_platform_file_attachment_posix.cc b/ipc/ipc_platform_file_attachment_posix.cc
new file mode 100644
index 0000000..b704750c1
--- /dev/null
+++ b/ipc/ipc_platform_file_attachment_posix.cc
@@ -0,0 +1,37 @@
+// 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.
+
+#include "ipc/ipc_platform_file_attachment_posix.h"
+
+namespace IPC {
+namespace internal {
+
+PlatformFileAttachment::PlatformFileAttachment(base::PlatformFile file)
+    : file_(file) {
+}
+
+PlatformFileAttachment::PlatformFileAttachment(base::ScopedFD file)
+    : file_(file.get()), owning_(file.Pass()) {
+}
+
+PlatformFileAttachment::~PlatformFileAttachment() {
+}
+
+MessageAttachment::Type PlatformFileAttachment::GetType() const {
+  return TYPE_PLATFORM_FILE;
+}
+
+base::PlatformFile PlatformFileAttachment::TakePlatformFile() {
+  ignore_result(owning_.release());
+  return file_;
+}
+
+base::PlatformFile GetPlatformFile(
+    scoped_refptr<MessageAttachment> attachment) {
+  DCHECK_EQ(attachment->GetType(), MessageAttachment::TYPE_PLATFORM_FILE);
+  return static_cast<PlatformFileAttachment*>(attachment.get())->file();
+}
+
+}  // namespace internal
+}  // namespace IPC