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

Delay MediaClientImpl's subscription to VmCameraMicManager

... until the primary profile is ready since VmCameraMicManager is not
ready until then.

Bug: b/167491603
Change-Id: Ib2388a95a26ec6c128f2fca0f9c4e5561802bb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586286
Commit-Queue: Jason Lin <lxj@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836457}
parent 65ba6b4d
......@@ -13,6 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/arc/session/arc_service_launcher.h"
#include "chrome/browser/chromeos/camera_mic/vm_camera_mic_manager_factory.h"
#include "chrome/browser/chromeos/child_accounts/child_status_reporting_service_factory.h"
#include "chrome/browser/chromeos/child_accounts/child_user_service_factory.h"
#include "chrome/browser/chromeos/child_accounts/family_user_metrics_service_factory.h"
......@@ -30,6 +31,7 @@
#include "chrome/browser/google/google_brand_chromeos.h"
#include "chrome/browser/net/nss_context.h"
#include "chrome/browser/ui/ash/clipboard_image_model_factory_impl.h"
#include "chrome/browser/ui/ash/media_client_impl.h"
#include "chrome/common/pref_names.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/network/network_cert_loader.h"
......@@ -210,6 +212,12 @@ void UserSessionInitializer::OnUserSessionStarted(bool is_primary_user) {
plugin_vm::PluginVmManagerFactory::GetForProfile(primary_profile_);
if (plugin_vm_manager)
plugin_vm_manager->OnPrimaryUserSessionStarted();
VmCameraMicManagerFactory::GetForProfile(primary_profile_);
auto* media_client_impl = MediaClientImpl::Get();
if (media_client_impl)
media_client_impl->OnPrimaryUserSessionStarted(primary_profile_);
}
}
......
......@@ -11,6 +11,7 @@
#include "base/check_op.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/system/sys_info.h"
#include "base/task/current_thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/camera_mic/vm_camera_mic_manager.h"
......@@ -140,11 +141,6 @@ MediaClientImpl::MediaClientImpl() {
MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
BrowserList::AddObserver(this);
auto* vm_camera_mic_manager = chromeos::VmCameraMicManager::GetForProfile(
ProfileManager::GetPrimaryUserProfile());
if (vm_camera_mic_manager)
vm_camera_mic_manager->AddObserver(this);
DCHECK(!g_media_client);
g_media_client = this;
}
......@@ -183,6 +179,18 @@ void MediaClientImpl::InitForTesting(ash::MediaController* controller) {
media_controller_->SetClient(this);
}
void MediaClientImpl::OnPrimaryUserSessionStarted(Profile* primary_profile) {
// Skip when not on real device (i.e. tests and emulator on dev box). The
// reason is that some tests cause this function to be run more than once,
// which results in a crash.
if (base::SysInfo::IsRunningOnChromeOS()) {
auto* vm_camera_mic_manager =
chromeos::VmCameraMicManager::GetForProfile(primary_profile);
if (vm_camera_mic_manager)
vm_camera_mic_manager->AddObserver(this);
}
}
void MediaClientImpl::HandleMediaNextTrack() {
HandleMediaAction(ui::VKEY_MEDIA_NEXT_TRACK);
}
......
......@@ -29,6 +29,8 @@ class MediaClientImpl : public ash::MediaClient,
// Tests can provide a mock mojo interface for the ash controller.
void InitForTesting(ash::MediaController* controller);
void OnPrimaryUserSessionStarted(Profile* primary_prifle);
// Returns a pointer to the singleton MediaClient, or nullptr if none exists.
static MediaClientImpl* Get();
......
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