Adds getCameraFacing() API for CCA

This CL adds getCameraFacing() API for CCA to get camera facing.

Bug: None
Test: Manually
Change-Id: Ic400ed3012416f6d22f61fb553f9a74e7a1c24dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1624425
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Sheng-hao Tsao <shenghao@chromium.org>
Reviewed-by: Ricky Liang <jcliang@chromium.org>
Commit-Queue: Wei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663003}
diff --git a/chrome/browser/resources/chromeos/camera/BUILD.gn b/chrome/browser/resources/chromeos/camera/BUILD.gn
index d3c156b..57e3d08 100644
--- a/chrome/browser/resources/chromeos/camera/BUILD.gn
+++ b/chrome/browser/resources/chromeos/camera/BUILD.gn
@@ -200,6 +200,7 @@
 copy("chrome_camera_app_mojo_generated") {
   sources = [
     "$root_gen_dir/media/capture/mojom/image_capture.mojom-lite.js",
+    "$root_gen_dir/media/capture/video/chromeos/mojo/camera_common.mojom-lite.js",
     "$root_gen_dir/media/capture/video/chromeos/mojo/camera_metadata.mojom-lite.js",
     "$root_gen_dir/media/capture/video/chromeos/mojo/camera_metadata_tags.mojom-lite.js",
     "$root_gen_dir/media/capture/video/chromeos/mojo/cros_image_capture.mojom-lite.js",
diff --git a/chrome/browser/resources/chromeos/camera/src/js/mojo/imagecapture.js b/chrome/browser/resources/chromeos/camera/src/js/mojo/imagecapture.js
index bc1d826..d8ce9e1 100644
--- a/chrome/browser/resources/chromeos/camera/src/js/mojo/imagecapture.js
+++ b/chrome/browser/resources/chromeos/camera/src/js/mojo/imagecapture.js
@@ -129,9 +129,10 @@
   return Promise
       .all([
         this.capture_.getPhotoCapabilities(),
-        this.mojoCapture_.getStaticMetadata(this.deviceId_),
+        this.mojoCapture_.getCameraInfo(this.deviceId_),
       ])
-      .then(([capabilities, {staticMetadata}]) => {
+      .then(([capabilities, {cameraInfo}]) => {
+        const staticMetadata = cameraInfo.staticCameraCharacteristics;
         let supportedEffects = [cros.mojom.Effect.NO_EFFECT];
         if (cca.mojo.getMetadataData_(staticMetadata, portraitModeTag).length >
             0) {
@@ -188,7 +189,8 @@
   const numElementPerEntry = 4;
 
   const mojoCapture = cros.mojom.CrosImageCapture.getProxy();
-  return mojoCapture.getStaticMetadata(deviceId).then(({staticMetadata}) => {
+  return mojoCapture.getCameraInfo(deviceId).then(({cameraInfo}) => {
+    const staticMetadata = cameraInfo.staticCameraCharacteristics;
     const streamConfigs = cca.mojo.getMetadataData_(
         staticMetadata,
         cros.mojom.CameraMetadataTag
@@ -235,7 +237,8 @@
   const numElementPerEntry = 4;
 
   var mojoCapture = cros.mojom.CrosImageCapture.getProxy();
-  return mojoCapture.getStaticMetadata(deviceId).then(({staticMetadata}) => {
+  return mojoCapture.getCameraInfo(deviceId).then(({cameraInfo}) => {
+    const staticMetadata = cameraInfo.staticCameraCharacteristics;
     const minFrameDurationConfigs = cca.mojo.getMetadataData_(
         staticMetadata,
         cros.mojom.CameraMetadataTag
@@ -264,3 +267,16 @@
     return supportedConfigs;
   });
 };
+
+/**
+ * Gets camera facing for given device.
+ * @param {string} deviceId The renderer-facing device Id of the target camera
+ *   which could be retrieved from MediaDeviceInfo.deviceId.
+ * @return {Promise<cros.mojom.CameraFacing>} Promise of device facing.
+ */
+cca.mojo.getCameraFacing = function(deviceId) {
+  var mojoCapture = cros.mojom.CrosImageCapture.getProxy();
+  return mojoCapture.getCameraInfo(deviceId).then(({cameraInfo}) => {
+    return cameraInfo.facing;
+  });
+};
diff --git a/chrome/browser/resources/chromeos/camera/src/views/main.html b/chrome/browser/resources/chromeos/camera/src/views/main.html
index 6ed0bc3..232dd7b 100644
--- a/chrome/browser/resources/chromeos/camera/src/views/main.html
+++ b/chrome/browser/resources/chromeos/camera/src/views/main.html
@@ -25,6 +25,7 @@
     <script src="../js/mojo/mojo_bindings_lite.js"></script>
     <script src="../js/mojo/camera_metadata_tags.mojom-lite.js"></script>
     <script src="../js/mojo/camera_metadata.mojom-lite.js"></script>
+    <script src="../js/mojo/camera_common.mojom-lite.js"></script>
     <script src="../js/mojo/image_capture.mojom-lite.js"></script>
     <script src="../js/mojo/cros_image_capture.mojom-lite.js"></script>
     <script src="../js/mojo/imagecapture.js"></script>
diff --git a/media/capture/video/chromeos/camera_device_delegate.cc b/media/capture/video/chromeos/camera_device_delegate.cc
index d982804..d352f7f 100644
--- a/media/capture/video/chromeos/camera_device_delegate.cc
+++ b/media/capture/video/chromeos/camera_device_delegate.cc
@@ -429,12 +429,12 @@
         FROM_HERE, "Failed to get camera info");
     return;
   }
+
+  reprocess_manager_->UpdateCameraInfo(device_descriptor_.device_id,
+                                       camera_info);
   SortCameraMetadata(&camera_info->static_camera_characteristics);
   static_metadata_ = std::move(camera_info->static_camera_characteristics);
 
-  reprocess_manager_->UpdateStaticMetadata(device_descriptor_.device_id,
-                                           static_metadata_);
-
   const cros::mojom::CameraMetadataEntryPtr* sensor_orientation =
       GetMetadataEntry(
           static_metadata_,
diff --git a/media/capture/video/chromeos/cros_image_capture_impl.cc b/media/capture/video/chromeos/cros_image_capture_impl.cc
index 04ac8f3..8dba5ff 100644
--- a/media/capture/video/chromeos/cros_image_capture_impl.cc
+++ b/media/capture/video/chromeos/cros_image_capture_impl.cc
@@ -23,12 +23,11 @@
   bindings_.AddBinding(this, std::move(request));
 }
 
-void CrosImageCaptureImpl::GetStaticMetadata(
-    const std::string& device_id,
-    GetStaticMetadataCallback callback) {
-  reprocess_manager_->GetStaticMetadata(
+void CrosImageCaptureImpl::GetCameraInfo(const std::string& device_id,
+                                         GetCameraInfoCallback callback) {
+  reprocess_manager_->GetCameraInfo(
       device_id, media::BindToCurrentLoop(base::BindOnce(
-                     &CrosImageCaptureImpl::OnGotStaticMetadata,
+                     &CrosImageCaptureImpl::OnGotCameraInfo,
                      base::Unretained(this), std::move(callback))));
 }
 
@@ -40,10 +39,10 @@
       device_id, effect, media::BindToCurrentLoop(std::move(callback)));
 }
 
-void CrosImageCaptureImpl::OnGotStaticMetadata(
-    GetStaticMetadataCallback callback,
-    cros::mojom::CameraMetadataPtr static_metadata) {
-  std::move(callback).Run(std::move(static_metadata));
+void CrosImageCaptureImpl::OnGotCameraInfo(
+    GetCameraInfoCallback callback,
+    cros::mojom::CameraInfoPtr camera_info) {
+  std::move(callback).Run(std::move(camera_info));
 }
 
 }  // namespace media
diff --git a/media/capture/video/chromeos/cros_image_capture_impl.h b/media/capture/video/chromeos/cros_image_capture_impl.h
index 93785b5..a7a81b1 100644
--- a/media/capture/video/chromeos/cros_image_capture_impl.h
+++ b/media/capture/video/chromeos/cros_image_capture_impl.h
@@ -7,7 +7,7 @@
 
 #include <string>
 
-#include "media/capture/video/chromeos/mojo/camera_metadata.mojom.h"
+#include "media/capture/video/chromeos/mojo/camera_common.mojom.h"
 #include "media/capture/video/chromeos/mojo/cros_image_capture.mojom.h"
 #include "media/capture/video/chromeos/reprocess_manager.h"
 #include "mojo/public/cpp/bindings/binding_set.h"
@@ -23,15 +23,15 @@
 
   // cros::mojom::CrosImageCapture implementations.
 
-  void GetStaticMetadata(const std::string& device_id,
-                         GetStaticMetadataCallback callback) override;
+  void GetCameraInfo(const std::string& device_id,
+                     GetCameraInfoCallback callback) override;
   void SetReprocessOption(const std::string& device_id,
                           cros::mojom::Effect effect,
                           SetReprocessOptionCallback callback) override;
 
  private:
-  void OnGotStaticMetadata(GetStaticMetadataCallback callback,
-                           cros::mojom::CameraMetadataPtr static_metadata);
+  void OnGotCameraInfo(GetCameraInfoCallback callback,
+                       cros::mojom::CameraInfoPtr camera_info);
 
   ReprocessManager* reprocess_manager_;  // weak
 
diff --git a/media/capture/video/chromeos/mojo/cros_image_capture.mojom b/media/capture/video/chromeos/mojo/cros_image_capture.mojom
index 7106b44..e2adaf2 100644
--- a/media/capture/video/chromeos/mojo/cros_image_capture.mojom
+++ b/media/capture/video/chromeos/mojo/cros_image_capture.mojom
@@ -5,7 +5,7 @@
 module cros.mojom;
 
 import "media/capture/mojom/image_capture.mojom";
-import "media/capture/video/chromeos/mojo/camera_metadata.mojom";
+import "media/capture/video/chromeos/mojo/camera_common.mojom";
 
 // Effect that recognized by Chrome OS.
 enum Effect {
@@ -19,10 +19,10 @@
 // translated to the actual video device id to be used in CrosImageCapture
 // implementation.
 interface CrosImageCapture {
-  // Gets camera static metadata |static_metadata| which includes camera
-  // characteristics information. The |source_id| might need
-  // translation to be actual video device id.
-  GetStaticMetadata(string source_id) => (CameraMetadata static_metadata);
+  // Gets camera information |camera_info| which includes camera facing,
+  // characteristics, orientation, etc. The |source_id| might need translation
+  // to be actual video device id.
+  GetCameraInfo(string source_id) => (CameraInfo camera_info);
 
   // Sets reprocess option to bind with the coming take photo request. When this
   // method is called, the reprocess option will be queued. All reprocess
diff --git a/media/capture/video/chromeos/renderer_facing_cros_image_capture.cc b/media/capture/video/chromeos/renderer_facing_cros_image_capture.cc
index cda2019..6d09adf 100644
--- a/media/capture/video/chromeos/renderer_facing_cros_image_capture.cc
+++ b/media/capture/video/chromeos/renderer_facing_cros_image_capture.cc
@@ -23,11 +23,11 @@
 
 RendererFacingCrosImageCapture::~RendererFacingCrosImageCapture() = default;
 
-void RendererFacingCrosImageCapture::GetStaticMetadataWithRealId(
-    GetStaticMetadataCallback callback,
+void RendererFacingCrosImageCapture::GetCameraInfoWithRealId(
+    GetCameraInfoCallback callback,
     const base::Optional<std::string>& device_id) {
   DCHECK(device_id.has_value());
-  cros_image_capture_->GetStaticMetadata(*device_id, std::move(callback));
+  cros_image_capture_->GetCameraInfo(*device_id, std::move(callback));
 }
 
 void RendererFacingCrosImageCapture::SetReprocessOptionWithRealId(
@@ -39,14 +39,13 @@
                                           std::move(callback));
 }
 
-void RendererFacingCrosImageCapture::GetStaticMetadata(
+void RendererFacingCrosImageCapture::GetCameraInfo(
     const std::string& source_id,
-    GetStaticMetadataCallback callback) {
+    GetCameraInfoCallback callback) {
   mapping_callback_.Run(
-      source_id,
-      media::BindToCurrentLoop(base::BindOnce(
-          &RendererFacingCrosImageCapture::GetStaticMetadataWithRealId,
-          weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
+      source_id, media::BindToCurrentLoop(base::BindOnce(
+                     &RendererFacingCrosImageCapture::GetCameraInfoWithRealId,
+                     weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
 }
 
 void RendererFacingCrosImageCapture::SetReprocessOption(
diff --git a/media/capture/video/chromeos/renderer_facing_cros_image_capture.h b/media/capture/video/chromeos/renderer_facing_cros_image_capture.h
index a9fc405..ad6fa0b 100644
--- a/media/capture/video/chromeos/renderer_facing_cros_image_capture.h
+++ b/media/capture/video/chromeos/renderer_facing_cros_image_capture.h
@@ -33,9 +33,8 @@
                                  DeviceIdMappingCallback mapping_callback);
   ~RendererFacingCrosImageCapture() override;
 
-  void GetStaticMetadataWithRealId(
-      GetStaticMetadataCallback callback,
-      const base::Optional<std::string>& device_id);
+  void GetCameraInfoWithRealId(GetCameraInfoCallback callback,
+                               const base::Optional<std::string>& device_id);
 
   void SetReprocessOptionWithRealId(
       cros::mojom::Effect effect,
@@ -43,8 +42,8 @@
       const base::Optional<std::string>& device_id);
 
   // cros::mojom::CrosImageCapture implementations.
-  void GetStaticMetadata(const std::string& source_id,
-                         GetStaticMetadataCallback callback) override;
+  void GetCameraInfo(const std::string& source_id,
+                     GetCameraInfoCallback callback) override;
   void SetReprocessOption(const std::string& source_id,
                           cros::mojom::Effect effect,
                           SetReprocessOptionCallback callback) override;
diff --git a/media/capture/video/chromeos/reprocess_manager.cc b/media/capture/video/chromeos/reprocess_manager.cc
index c246b37..ed5e466 100644
--- a/media/capture/video/chromeos/reprocess_manager.cc
+++ b/media/capture/video/chromeos/reprocess_manager.cc
@@ -44,7 +44,7 @@
   return kReprocessSuccess;
 }
 
-ReprocessManager::ReprocessManager(UpdateStaticMetadataCallback callback)
+ReprocessManager::ReprocessManager(UpdateCameraInfoCallback callback)
     : sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
           {base::TaskPriority::USER_VISIBLE})),
       impl(new ReprocessManager::ReprocessManagerImpl(std::move(callback))) {}
@@ -86,28 +86,28 @@
           base::Unretained(impl.get()), device_id));
 }
 
-void ReprocessManager::GetStaticMetadata(const std::string& device_id,
-                                         GetStaticMetadataCallback callback) {
+void ReprocessManager::GetCameraInfo(const std::string& device_id,
+                                     GetCameraInfoCallback callback) {
   sequenced_task_runner_->PostTask(
       FROM_HERE,
-      base::BindOnce(&ReprocessManager::ReprocessManagerImpl::GetStaticMetadata,
+      base::BindOnce(&ReprocessManager::ReprocessManagerImpl::GetCameraInfo,
                      base::Unretained(impl.get()), device_id,
                      std::move(callback)));
 }
 
-void ReprocessManager::UpdateStaticMetadata(
+void ReprocessManager::UpdateCameraInfo(
     const std::string& device_id,
-    const cros::mojom::CameraMetadataPtr& metadata) {
+    const cros::mojom::CameraInfoPtr& camera_info) {
   sequenced_task_runner_->PostTask(
       FROM_HERE,
-      base::BindOnce(
-          &ReprocessManager::ReprocessManagerImpl::UpdateStaticMetadata,
-          base::Unretained(impl.get()), device_id, metadata.Clone()));
+      base::BindOnce(&ReprocessManager::ReprocessManagerImpl::UpdateCameraInfo,
+                     base::Unretained(impl.get()), device_id,
+                     camera_info.Clone()));
 }
 
 ReprocessManager::ReprocessManagerImpl::ReprocessManagerImpl(
-    UpdateStaticMetadataCallback callback)
-    : update_static_metadata_callback_(std::move(callback)) {}
+    UpdateCameraInfoCallback callback)
+    : update_camera_info_callback_(std::move(callback)) {}
 
 ReprocessManager::ReprocessManagerImpl::~ReprocessManagerImpl() = default;
 
@@ -162,27 +162,25 @@
   reprocess_task_queue_map_[device_id].swap(empty_queue);
 }
 
-void ReprocessManager::ReprocessManagerImpl::GetStaticMetadata(
+void ReprocessManager::ReprocessManagerImpl::GetCameraInfo(
     const std::string& device_id,
-    GetStaticMetadataCallback callback) {
-  if (static_metadata_map_[device_id]) {
-    std::move(callback).Run(static_metadata_map_[device_id].Clone());
+    GetCameraInfoCallback callback) {
+  if (camera_info_map_[device_id]) {
+    std::move(callback).Run(camera_info_map_[device_id].Clone());
   } else {
-    get_static_metadata_callback_queue_map_[device_id].push(
-        std::move(callback));
-    update_static_metadata_callback_.Run(device_id);
+    get_camera_info_callback_queue_map_[device_id].push(std::move(callback));
+    update_camera_info_callback_.Run(device_id);
   }
 }
 
-void ReprocessManager::ReprocessManagerImpl::UpdateStaticMetadata(
+void ReprocessManager::ReprocessManagerImpl::UpdateCameraInfo(
     const std::string& device_id,
-    cros::mojom::CameraMetadataPtr metadata) {
-  static_metadata_map_[device_id] = std::move(metadata);
+    cros::mojom::CameraInfoPtr camera_info) {
+  camera_info_map_[device_id] = std::move(camera_info);
 
-  auto& callback_queue = get_static_metadata_callback_queue_map_[device_id];
+  auto& callback_queue = get_camera_info_callback_queue_map_[device_id];
   while (!callback_queue.empty()) {
-    std::move(callback_queue.front())
-        .Run(static_metadata_map_[device_id].Clone());
+    std::move(callback_queue.front()).Run(camera_info_map_[device_id].Clone());
     callback_queue.pop();
   }
 }
diff --git a/media/capture/video/chromeos/reprocess_manager.h b/media/capture/video/chromeos/reprocess_manager.h
index 5dc2617..2f36247 100644
--- a/media/capture/video/chromeos/reprocess_manager.h
+++ b/media/capture/video/chromeos/reprocess_manager.h
@@ -16,6 +16,7 @@
 #include "media/capture/capture_export.h"
 #include "media/capture/mojom/image_capture.mojom.h"
 #include "media/capture/video/chromeos/mojo/camera3.mojom.h"
+#include "media/capture/video/chromeos/mojo/camera_common.mojom.h"
 #include "media/capture/video/chromeos/mojo/cros_image_capture.mojom.h"
 #include "mojo/public/cpp/bindings/binding.h"
 
@@ -46,14 +47,14 @@
 // sequentialize to a single sequence.
 class CAPTURE_EXPORT ReprocessManager {
  public:
-  using GetStaticMetadataCallback =
-      base::OnceCallback<void(cros::mojom::CameraMetadataPtr static_metadata)>;
-  using UpdateStaticMetadataCallback =
+  using GetCameraInfoCallback =
+      base::OnceCallback<void(cros::mojom::CameraInfoPtr camera_info)>;
+  using UpdateCameraInfoCallback =
       base::RepeatingCallback<void(const std::string& device_id)>;
 
   class ReprocessManagerImpl {
    public:
-    ReprocessManagerImpl(UpdateStaticMetadataCallback callback);
+    ReprocessManagerImpl(UpdateCameraInfoCallback callback);
     ~ReprocessManagerImpl();
 
     void SetReprocessOption(
@@ -69,23 +70,22 @@
 
     void FlushReprocessOptions(const std::string& device_id);
 
-    void GetStaticMetadata(const std::string& device_id,
-                           GetStaticMetadataCallback callback);
+    void GetCameraInfo(const std::string& device_id,
+                       GetCameraInfoCallback callback);
 
-    void UpdateStaticMetadata(const std::string& device_id,
-                              cros::mojom::CameraMetadataPtr metadata);
+    void UpdateCameraInfo(const std::string& device_id,
+                          cros::mojom::CameraInfoPtr camera_info);
 
    private:
     base::flat_map<std::string, base::queue<ReprocessTask>>
         reprocess_task_queue_map_;
 
-    base::flat_map<std::string, cros::mojom::CameraMetadataPtr>
-        static_metadata_map_;
+    base::flat_map<std::string, cros::mojom::CameraInfoPtr> camera_info_map_;
 
-    base::flat_map<std::string, base::queue<GetStaticMetadataCallback>>
-        get_static_metadata_callback_queue_map_;
+    base::flat_map<std::string, base::queue<GetCameraInfoCallback>>
+        get_camera_info_callback_queue_map_;
 
-    UpdateStaticMetadataCallback update_static_metadata_callback_;
+    UpdateCameraInfoCallback update_camera_info_callback_;
 
     DISALLOW_COPY_AND_ASSIGN(ReprocessManagerImpl);
   };
@@ -93,7 +93,7 @@
   static int GetReprocessReturnCode(
       cros::mojom::Effect effect,
       const cros::mojom::CameraMetadataPtr* metadata);
-  ReprocessManager(UpdateStaticMetadataCallback callback);
+  ReprocessManager(UpdateCameraInfoCallback callback);
   ~ReprocessManager();
 
   // Sets the reprocess option for given device id and effect. Each reprocess
@@ -114,13 +114,13 @@
   // Clears all remaining ReprocessTasks in the queue for given device id.
   void FlushReprocessOptions(const std::string& device_id);
 
-  // Gets camera static metadata for current active device.
-  void GetStaticMetadata(const std::string& device_id,
-                         GetStaticMetadataCallback callback);
+  // Gets camera information for current active device.
+  void GetCameraInfo(const std::string& device_id,
+                     GetCameraInfoCallback callback);
 
-  // Updates camera static metadata for given device.
-  void UpdateStaticMetadata(const std::string& device_id,
-                            const cros::mojom::CameraMetadataPtr& metadata);
+  // Updates camera information for given device.
+  void UpdateCameraInfo(const std::string& device_id,
+                        const cros::mojom::CameraInfoPtr& camera_info);
 
  private:
   scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
diff --git a/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc b/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc
index 577105ade..e3777da 100644
--- a/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc
+++ b/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc
@@ -113,8 +113,7 @@
     const std::string& device_id,
     int32_t result,
     cros::mojom::CameraInfoPtr camera_info) {
-  reprocess_manager_->UpdateStaticMetadata(
-      device_id, std::move(camera_info->static_camera_characteristics));
+  reprocess_manager_->UpdateCameraInfo(device_id, std::move(camera_info));
 }
 
 void VideoCaptureDeviceFactoryChromeOS::BindCrosImageCaptureRequest(