Move function to util files (media/mojo)

When building using jumbo, files gets merged and functions
with the same name may end up in the same scope and conflict.

This commits moves such functions to shared util files,
instead of having duplicates.

Bug: 867350
Change-Id: I9986d6d653ef71acbf9583e18aa85a8e34f6e6f0
Reviewed-on: https://chromium-review.googlesource.com/1149781
Reviewed-by: Chrome Cunningham (In Paris) <chcunningham@chromium.org>
Commit-Queue: Oscar Johansson <oscarj@opera.com>
Cr-Commit-Position: refs/heads/master@{#577850}
diff --git a/media/mojo/common/BUILD.gn b/media/mojo/common/BUILD.gn
index 23dfe6c..32d2931 100644
--- a/media/mojo/common/BUILD.gn
+++ b/media/mojo/common/BUILD.gn
@@ -10,6 +10,8 @@
     "mojo_data_pipe_read_write.h",
     "mojo_decoder_buffer_converter.cc",
     "mojo_decoder_buffer_converter.h",
+    "mojo_pipe_read_write_util.cc",
+    "mojo_pipe_read_write_util.h",
   ]
 
   deps = [
diff --git a/media/mojo/common/mojo_data_pipe_read_write.cc b/media/mojo/common/mojo_data_pipe_read_write.cc
index 311e167..87e5cb2 100644
--- a/media/mojo/common/mojo_data_pipe_read_write.cc
+++ b/media/mojo/common/mojo_data_pipe_read_write.cc
@@ -8,17 +8,12 @@
 
 #include "base/logging.h"
 #include "base/memory/ptr_util.h"
+#include "media/mojo/common/mojo_pipe_read_write_util.h"
+
+using media::mojo_pipe_read_write_util::IsPipeReadWriteError;
 
 namespace media {
 
-namespace {
-
-bool IsPipeReadWriteError(MojoResult result) {
-  return result != MOJO_RESULT_OK && result != MOJO_RESULT_SHOULD_WAIT;
-}
-
-}  // namespace
-
 // MojoDataPipeReader
 
 MojoDataPipeReader::MojoDataPipeReader(
diff --git a/media/mojo/common/mojo_decoder_buffer_converter.cc b/media/mojo/common/mojo_decoder_buffer_converter.cc
index fb267eb..9ba228f 100644
--- a/media/mojo/common/mojo_decoder_buffer_converter.cc
+++ b/media/mojo/common/mojo_decoder_buffer_converter.cc
@@ -14,17 +14,12 @@
 #include "media/base/cdm_context.h"
 #include "media/base/decoder_buffer.h"
 #include "media/mojo/common/media_type_converters.h"
+#include "media/mojo/common/mojo_pipe_read_write_util.h"
+
+using media::mojo_pipe_read_write_util::IsPipeReadWriteError;
 
 namespace media {
 
-namespace {
-
-bool IsPipeReadWriteError(MojoResult result) {
-  return result != MOJO_RESULT_OK && result != MOJO_RESULT_SHOULD_WAIT;
-}
-
-}  // namespace
-
 uint32_t GetDefaultDecoderBufferConverterCapacity(DemuxerStream::Type type) {
   uint32_t capacity = 0;
 
diff --git a/media/mojo/common/mojo_pipe_read_write_util.cc b/media/mojo/common/mojo_pipe_read_write_util.cc
new file mode 100644
index 0000000..85b6fe9
--- /dev/null
+++ b/media/mojo/common/mojo_pipe_read_write_util.cc
@@ -0,0 +1,17 @@
+// Copyright 2018 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 "media/mojo/common/mojo_pipe_read_write_util.h"
+
+#include "mojo/public/c/system/types.h"
+
+namespace media {
+namespace mojo_pipe_read_write_util {
+
+bool IsPipeReadWriteError(MojoResult result) {
+  return result != MOJO_RESULT_OK && result != MOJO_RESULT_SHOULD_WAIT;
+}
+
+}  // namespace mojo_pipe_read_write_util
+}  // namespace media
diff --git a/media/mojo/common/mojo_pipe_read_write_util.h b/media/mojo/common/mojo_pipe_read_write_util.h
new file mode 100644
index 0000000..4d4f8726
--- /dev/null
+++ b/media/mojo/common/mojo_pipe_read_write_util.h
@@ -0,0 +1,18 @@
+// Copyright 2018 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 MEDIA_MOJO_COMMON_MOJO_PIPE_READ_WRITE_UTIL_H_
+#define MEDIA_MOJO_COMMON_MOJO_PIPE_READ_WRITE_UTIL_H_
+
+#include "mojo/public/c/system/types.h"
+
+namespace media {
+namespace mojo_pipe_read_write_util {
+
+bool IsPipeReadWriteError(MojoResult result);
+
+}  // namespace mojo_pipe_read_write_util
+}  // namespace media
+
+#endif  // MEDIA_MOJO_COMMON_MOJO_PIPE_READ_WRITE_UTIL_H_
diff --git a/media/mojo/services/BUILD.gn b/media/mojo/services/BUILD.gn
index f1bf5e3..d1fec92 100644
--- a/media/mojo/services/BUILD.gn
+++ b/media/mojo/services/BUILD.gn
@@ -110,6 +110,8 @@
     sources += [
       "android_mojo_media_client.cc",
       "android_mojo_media_client.h",
+      "android_mojo_util.cc",
+      "android_mojo_util.h",
       "mojo_media_drm_storage.cc",
       "mojo_media_drm_storage.h",
     ]
diff --git a/media/mojo/services/android_mojo_media_client.cc b/media/mojo/services/android_mojo_media_client.cc
index 0de0a5f..5b54734 100644
--- a/media/mojo/services/android_mojo_media_client.cc
+++ b/media/mojo/services/android_mojo_media_client.cc
@@ -14,34 +14,14 @@
 #include "media/filters/android/media_codec_audio_decoder.h"
 #include "media/mojo/interfaces/media_drm_storage.mojom.h"
 #include "media/mojo/interfaces/provision_fetcher.mojom.h"
-#include "media/mojo/services/mojo_media_drm_storage.h"
-#include "media/mojo/services/mojo_provision_fetcher.h"
+#include "media/mojo/services/android_mojo_util.h"
 #include "services/service_manager/public/cpp/connect.h"
 
+using media::android_mojo_util::CreateProvisionFetcher;
+using media::android_mojo_util::CreateMediaDrmStorage;
+
 namespace media {
 
-namespace {
-
-std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher(
-    service_manager::mojom::InterfaceProvider* host_interfaces) {
-  DCHECK(host_interfaces);
-  mojom::ProvisionFetcherPtr provision_fetcher_ptr;
-  service_manager::GetInterface(host_interfaces, &provision_fetcher_ptr);
-  return std::make_unique<MojoProvisionFetcher>(
-      std::move(provision_fetcher_ptr));
-}
-
-std::unique_ptr<MediaDrmStorage> CreateMediaDrmStorage(
-    service_manager::mojom::InterfaceProvider* host_interfaces) {
-  DCHECK(host_interfaces);
-  mojom::MediaDrmStoragePtr media_drm_storage_ptr;
-  service_manager::GetInterface(host_interfaces, &media_drm_storage_ptr);
-  return std::make_unique<MojoMediaDrmStorage>(
-      std::move(media_drm_storage_ptr));
-}
-
-}  // namespace
-
 AndroidMojoMediaClient::AndroidMojoMediaClient() {}
 
 AndroidMojoMediaClient::~AndroidMojoMediaClient() {}
diff --git a/media/mojo/services/android_mojo_util.cc b/media/mojo/services/android_mojo_util.cc
new file mode 100644
index 0000000..ee2b722
--- /dev/null
+++ b/media/mojo/services/android_mojo_util.cc
@@ -0,0 +1,32 @@
+// Copyright 2018 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 "media/mojo/services/android_mojo_util.h"
+
+#include "media/mojo/services/mojo_media_drm_storage.h"
+#include "services/service_manager/public/cpp/connect.h"
+
+namespace media {
+namespace android_mojo_util {
+
+std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher(
+    service_manager::mojom::InterfaceProvider* host_interfaces) {
+  DCHECK(host_interfaces);
+  mojom::ProvisionFetcherPtr provision_fetcher_ptr;
+  service_manager::GetInterface(host_interfaces, &provision_fetcher_ptr);
+  return std::make_unique<MojoProvisionFetcher>(
+      std::move(provision_fetcher_ptr));
+}
+
+std::unique_ptr<MediaDrmStorage> CreateMediaDrmStorage(
+    service_manager::mojom::InterfaceProvider* host_interfaces) {
+  DCHECK(host_interfaces);
+  mojom::MediaDrmStoragePtr media_drm_storage_ptr;
+  service_manager::GetInterface(host_interfaces, &media_drm_storage_ptr);
+  return std::make_unique<MojoMediaDrmStorage>(
+      std::move(media_drm_storage_ptr));
+}
+
+}  // namespace android_mojo_util
+}  // namespace media
diff --git a/media/mojo/services/android_mojo_util.h b/media/mojo/services/android_mojo_util.h
new file mode 100644
index 0000000..62f1783
--- /dev/null
+++ b/media/mojo/services/android_mojo_util.h
@@ -0,0 +1,33 @@
+// Copyright 2018 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 MEDIA_MOJO_SERVICES_ANDROID_MOJO_UTIL_H_
+#define MEDIA_MOJO_SERVICES_ANDROID_MOJO_UTIL_H_
+
+#include <memory>
+
+#include "media/mojo/services/mojo_media_drm_storage.h"
+#include "media/mojo/services/mojo_provision_fetcher.h"
+
+namespace service_manager {
+namespace mojom {
+
+class InterfaceProvider;
+
+}  // namespace mojom
+}  // namespace service_manager
+
+namespace media {
+namespace android_mojo_util {
+
+std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher(
+    service_manager::mojom::InterfaceProvider* host_interfaces);
+
+std::unique_ptr<MediaDrmStorage> CreateMediaDrmStorage(
+    service_manager::mojom::InterfaceProvider* host_interfaces);
+
+}  // namespace android_mojo_util
+}  // namespace media
+
+#endif  // MEDIA_MOJO_SERVICES_ANDROID_MOJO_UTIL_H_
diff --git a/media/mojo/services/gpu_mojo_media_client.cc b/media/mojo/services/gpu_mojo_media_client.cc
index ffc817c3..8a3c1367 100644
--- a/media/mojo/services/gpu_mojo_media_client.cc
+++ b/media/mojo/services/gpu_mojo_media_client.cc
@@ -38,32 +38,16 @@
 #include "media/gpu/windows/d3d11_video_decoder.h"
 #endif  // defined(OS_WIN)
 
+#if defined(OS_ANDROID)
+#include "media/mojo/services/android_mojo_util.h"
+using media::android_mojo_util::CreateProvisionFetcher;
+using media::android_mojo_util::CreateMediaDrmStorage;
+#endif  // defined(OS_ANDROID)
+
 namespace media {
 
 namespace {
 
-// TODO(xhwang): Remove the duplicate code between GpuMojoMediaClient and
-// AndroidMojoMediaClient.
-
-#if defined(OS_ANDROID)
-std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher(
-    service_manager::mojom::InterfaceProvider* interface_provider) {
-  mojom::ProvisionFetcherPtr provision_fetcher_ptr;
-  service_manager::GetInterface(interface_provider, &provision_fetcher_ptr);
-  return std::make_unique<MojoProvisionFetcher>(
-      std::move(provision_fetcher_ptr));
-}
-
-std::unique_ptr<MediaDrmStorage> CreateMediaDrmStorage(
-    service_manager::mojom::InterfaceProvider* host_interfaces) {
-  DCHECK(host_interfaces);
-  mojom::MediaDrmStoragePtr media_drm_storage_ptr;
-  service_manager::GetInterface(host_interfaces, &media_drm_storage_ptr);
-  return std::make_unique<MojoMediaDrmStorage>(
-      std::move(media_drm_storage_ptr));
-}
-#endif  // defined(OS_ANDROID)
-
 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
 gpu::CommandBufferStub* GetCommandBufferStub(
     base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager,