Commit db7e975a authored by Jason Lin's avatar Jason Lin Committed by Chromium LUCI CQ

Reland "Connect VmCameraMicManager with camera service for PluginVM"

This is a reland of 31b56eca.

The original CL failed the chromeos-kevin-rel bot because it triggered
some race condition in the camera service. Now that camera service has
been fixed, and the chromeos-kevin-rel trybot is passing, this CL is
ready for a reland.

This CL is updated a bit from the original CL:
* We only connect to the camera service if
  media::ShouldUseCrosCameraService() returns true
* We check against both CameraClientType::UNKNOWN and ...::PLUGINVM
* Changes in user_session_initializer are removed because we have
  another CL (2586286) for it.

Original change's description:
> Connect VmCameraMicManager with camera service for PluginVM
>
> The camera notification/indicator is shown when PluginVM accesses camera
> now. Note that flags pluginvm-show-camera-permissions and
> vm-camera-mic-indicators-and-notifications need to be turned on.
>
> Bug: b/167491603
> Change-Id: Ib2e3f7bc85531313811d2525ecac394aadee6e17
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2557122
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Reviewed-by: Joel Hockey <joelhockey@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#832576}

Bug: b/167491603
Change-Id: Ibc01c2144bd8c7b5ba704abff9a8ccd1adec3d05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573936
Commit-Queue: Jason Lin <lxj@google.com>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836501}
parent 25e8be93
......@@ -316,6 +316,7 @@ source_set("chromeos") {
"//components/unified_consent",
"//components/user_manager",
"//components/vector_icons",
"//media/capture/video/chromeos/public:public",
# This depends directly on the variations target, rather than just
# transitively via the common target because the proto sources need to
......
......@@ -12,6 +12,7 @@
#include "base/feature_list.h"
#include "base/notreached.h"
#include "base/strings/string16.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/chromeos/camera_mic/vm_camera_mic_manager_factory.h"
......@@ -25,7 +26,10 @@
#include "chrome/grit/generated_resources.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "media/capture/video/chromeos/mojom/cros_camera_service.mojom-shared.h"
#include "media/capture/video/chromeos/public/cros_features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/public/cpp/notification.h"
......@@ -84,6 +88,15 @@ VmCameraMicManager::VmCameraMicManager(Profile* profile)
for (VmType vm : {VmType::kCrostiniVm, VmType::kPluginVm}) {
notification_map_[vm] = {};
}
// Camera service does not behave in non ChromeOS environment (e.g. testing,
// linux chromeos).
if (base::SysInfo::IsRunningOnChromeOS() &&
media::ShouldUseCrosCameraService()) {
// OnActiveClientChange() will be called automatically after the
// subscription, so there is no need to get the current status here.
camera_observation_.Observe(media::CameraHalDispatcherImpl::GetInstance());
}
}
VmCameraMicManager::~VmCameraMicManager() = default;
......@@ -142,6 +155,21 @@ bool VmCameraMicManager::IsNotificationActive(DeviceType device) const {
return false;
}
void VmCameraMicManager::OnActiveClientChange(
cros::mojom::CameraClientType type,
bool is_active) {
// TODO(b/167491603): `UNKNOWN` is for Parallels using v0 camera API. We
// should be able to remove it soon.
if (type == cros::mojom::CameraClientType::UNKNOWN ||
type == cros::mojom::CameraClientType::PLUGINVM) {
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&VmCameraMicManager::SetActive,
weak_ptr_factory_.GetWeakPtr(), VmType::kPluginVm,
DeviceType::kCamera, is_active));
}
}
void VmCameraMicManager::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
......
......@@ -13,8 +13,10 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/scoped_observation.h"
#include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h"
......@@ -27,7 +29,8 @@ namespace chromeos {
// the primary and non-incognito profile. We might need to change this if we
// extend this class to support the browser, in which case we will also need to
// make the notification ids different for different profiles.
class VmCameraMicManager : public KeyedService {
class VmCameraMicManager : public KeyedService,
public media::CameraActiveClientObserver {
public:
enum class VmType { kCrostiniVm, kPluginVm };
......@@ -101,6 +104,10 @@ class VmCameraMicManager : public KeyedService {
base::WeakPtrFactory<VmNotificationObserver> weak_ptr_factory_{this};
};
// media::CameraActiveClientObserver
void OnActiveClientChange(cros::mojom::CameraClientType type,
bool is_active) override;
static std::string GetNotificationId(VmType vm, NotificationType type);
void SetActive(VmType vm, DeviceType device, bool active);
......@@ -116,6 +123,15 @@ class VmCameraMicManager : public KeyedService {
base::RetainingOneShotTimer observer_timer_;
base::ObserverList<Observer> observers_;
base::ScopedObservation<
media::CameraHalDispatcherImpl,
media::CameraActiveClientObserver,
&media::CameraHalDispatcherImpl::AddActiveClientObserver,
&media::CameraHalDispatcherImpl::RemoveActiveClientObserver>
camera_observation_{this};
base::WeakPtrFactory<VmCameraMicManager> weak_ptr_factory_{this};
};
} // namespace chromeos
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment