EDK: Remove platform_handle_utils*.

Instead, give PlatformHandle and ScopedPlatformHandle Duplicate()
methods.

(It's a little odd, dependency-wise anyway, that
PlatformHandle::Duplicate() returns a ScopedPlatformHandle, but it makes
sense logically -- you may have a PlatformHandle, which you don't own,
but you'll own the result of Duplicate() -- and is obviously safer.)

R=vardhan@google.com

Review URL: https://codereview.chromium.org/1505983002 .
diff --git a/mojo/edk/embedder/BUILD.gn b/mojo/edk/embedder/BUILD.gn
index 8cbadec..086b6c7 100644
--- a/mojo/edk/embedder/BUILD.gn
+++ b/mojo/edk/embedder/BUILD.gn
@@ -56,8 +56,6 @@
     "platform_channel_pair.h",
     "platform_channel_utils.cc",
     "platform_channel_utils.h",
-    "platform_handle_utils.h",
-    "platform_handle_utils_posix.cc",
     "platform_shared_buffer.h",
     "platform_support.h",
     "simple_platform_shared_buffer.cc",
diff --git a/mojo/edk/embedder/platform_handle_utils.h b/mojo/edk/embedder/platform_handle_utils.h
deleted file mode 100644
index 8003e95..0000000
--- a/mojo/edk/embedder/platform_handle_utils.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 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 MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_UTILS_H_
-#define MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_UTILS_H_
-
-#include "mojo/edk/platform/platform_handle.h"
-#include "mojo/edk/platform/scoped_platform_handle.h"
-
-namespace mojo {
-namespace embedder {
-
-// Closes all the |PlatformHandle|s in the given container.
-template <typename PlatformHandleContainer>
-inline void CloseAllPlatformHandles(PlatformHandleContainer* platform_handles) {
-  for (typename PlatformHandleContainer::iterator it =
-           platform_handles->begin();
-       it != platform_handles->end(); ++it)
-    it->CloseIfNecessary();
-}
-
-// Duplicates the given |PlatformHandle| (which must be valid). (Returns an
-// invalid |ScopedPlatformHandle| on failure.)
-platform::ScopedPlatformHandle DuplicatePlatformHandle(
-    platform::PlatformHandle platform_handle);
-
-}  // namespace embedder
-}  // namespace mojo
-
-#endif  // MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_UTILS_H_
diff --git a/mojo/edk/embedder/platform_handle_utils_posix.cc b/mojo/edk/embedder/platform_handle_utils_posix.cc
deleted file mode 100644
index 07b138e..0000000
--- a/mojo/edk/embedder/platform_handle_utils_posix.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2014 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 "mojo/edk/embedder/platform_handle_utils.h"
-
-#include <unistd.h>
-
-#include "base/logging.h"
-
-using mojo::platform::PlatformHandle;
-using mojo::platform::ScopedPlatformHandle;
-
-namespace mojo {
-namespace embedder {
-
-ScopedPlatformHandle DuplicatePlatformHandle(PlatformHandle platform_handle) {
-  DCHECK(platform_handle.is_valid());
-  // Note that |dup()| returns -1 on error (which is exactly the value we use
-  // for invalid |PlatformHandle| FDs).
-  return ScopedPlatformHandle(PlatformHandle(dup(platform_handle.fd)));
-}
-
-}  // namespace embedder
-}  // namespace mojo
diff --git a/mojo/edk/embedder/simple_platform_shared_buffer.cc b/mojo/edk/embedder/simple_platform_shared_buffer.cc
index a3045c4..6ef856f 100644
--- a/mojo/edk/embedder/simple_platform_shared_buffer.cc
+++ b/mojo/edk/embedder/simple_platform_shared_buffer.cc
@@ -20,7 +20,6 @@
 #include "base/posix/eintr_wrapper.h"
 #include "base/threading/thread_restrictions.h"
 #include "build/build_config.h"
-#include "mojo/edk/embedder/platform_handle_utils.h"
 #include "mojo/edk/util/scoped_file.h"
 
 #if defined(OS_ANDROID)
@@ -124,7 +123,7 @@
 }
 
 ScopedPlatformHandle SimplePlatformSharedBuffer::DuplicatePlatformHandle() {
-  return mojo::embedder::DuplicatePlatformHandle(handle_.get());
+  return handle_.Duplicate();
 }
 
 ScopedPlatformHandle SimplePlatformSharedBuffer::PassPlatformHandle() {
diff --git a/mojo/edk/platform/platform_handle.cc b/mojo/edk/platform/platform_handle.cc
index 8a7c7be..c65600e 100644
--- a/mojo/edk/platform/platform_handle.cc
+++ b/mojo/edk/platform/platform_handle.cc
@@ -8,6 +8,8 @@
 #include <errno.h>
 #include <unistd.h>
 
+#include "mojo/edk/platform/scoped_platform_handle.h"
+
 namespace mojo {
 namespace platform {
 
@@ -26,5 +28,15 @@
   fd = -1;
 }
 
+ScopedPlatformHandle PlatformHandle::Duplicate() const {
+  // This is slightly redundant, but it's good to be safe (and avoid the system
+  // call and resulting EBADF).
+  if (!is_valid())
+    return ScopedPlatformHandle();
+  // Note that |dup()| returns -1 on error (which is exactly the value we use
+  // for invalid |PlatformHandle| FDs).
+  return ScopedPlatformHandle(PlatformHandle(dup(fd)));
+}
+
 }  // namespace embedder
 }  // namespace mojo
diff --git a/mojo/edk/platform/platform_handle.h b/mojo/edk/platform/platform_handle.h
index e959a8d..0b32a07 100644
--- a/mojo/edk/platform/platform_handle.h
+++ b/mojo/edk/platform/platform_handle.h
@@ -8,16 +8,26 @@
 namespace mojo {
 namespace platform {
 
-// A |PlatformHandle| is just a file descriptor on POSIX.
+class ScopedPlatformHandle;
+
+// A thin wrapper for an OS handle (just a file descriptor on POSIX) on any
+// given platform.
 struct PlatformHandle {
   PlatformHandle() : fd(-1) {}
   explicit PlatformHandle(int fd) : fd(fd) {}
 
+  // Closes this handle if it's valid (and sets it to be invalid).
   void CloseIfNecessary();
 
   bool is_valid() const { return fd != -1; }
 
+  // Creates a duplicate of this handle. On failure, or if this is an invalid
+  // handle, this returns an invalid handle.
+  ScopedPlatformHandle Duplicate() const;
+
   int fd;
+
+  // Copy and assignment allowed.
 };
 
 }  // namespace platform
diff --git a/mojo/edk/platform/scoped_platform_handle.h b/mojo/edk/platform/scoped_platform_handle.h
index 448a764..97e7a79 100644
--- a/mojo/edk/platform/scoped_platform_handle.h
+++ b/mojo/edk/platform/scoped_platform_handle.h
@@ -50,6 +50,9 @@
 
   bool is_valid() const { return handle_.is_valid(); }
 
+  // Forwards to |PlatformHandle::Duplicate()|.
+  ScopedPlatformHandle Duplicate() const { return handle_.Duplicate(); }
+
  private:
   PlatformHandle handle_;