Commit 093a0f56 authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Migrate ArcService to BrowserContextKeyedService part 27.

This CL migrates GpuArcVideoServiceHost.

BUG=672829
TEST=Ran try.

Change-Id: I1b1643d953081559b81364ee7275cc640f5bee48
Reviewed-on: https://chromium-review.googlesource.com/574513
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487422}
parent 2baad015
......@@ -95,8 +95,6 @@ void ArcServiceLauncher::Initialize() {
// List in lexicographical order.
arc_service_manager_->AddService(
base::MakeUnique<ArcIntentHelperBridge>(arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<GpuArcVideoServiceHost>(arc_bridge_service));
}
void ArcServiceLauncher::MaybeSetProfile(Profile* profile) {
......@@ -170,6 +168,7 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
ArcVoiceInteractionFrameworkService::GetForBrowserContext(profile);
ArcVolumeMounterBridge::GetForBrowserContext(profile);
ArcWallpaperService::GetForBrowserContext(profile);
GpuArcVideoServiceHost::GetForBrowserContext(profile);
arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>(
arc_service_manager_->arc_bridge_service(),
......
......@@ -10,9 +10,11 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/common/video_decode_accelerator.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/gpu_service_registry.h"
......@@ -36,6 +38,25 @@ void ConnectToVideoEncodeAcceleratorOnIOThread(
content::BindInterfaceInGpuProcess(std::move(request));
}
// Singleton factory for GpuArcVideoServiceHost.
class GpuArcVideoServiceHostFactory
: public internal::ArcBrowserContextKeyedServiceFactoryBase<
GpuArcVideoServiceHost,
GpuArcVideoServiceHostFactory> {
public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
static constexpr const char* kName = "GpuArcVideoServiceHostFactory";
static GpuArcVideoServiceHostFactory* GetInstance() {
return base::Singleton<GpuArcVideoServiceHostFactory>::get();
}
private:
friend base::DefaultSingletonTraits<GpuArcVideoServiceHostFactory>;
GpuArcVideoServiceHostFactory() = default;
~GpuArcVideoServiceHostFactory() override = default;
};
} // namespace
class VideoAcceleratorFactoryService : public mojom::VideoAcceleratorFactory {
......@@ -62,21 +83,33 @@ class VideoAcceleratorFactoryService : public mojom::VideoAcceleratorFactory {
DISALLOW_COPY_AND_ASSIGN(VideoAcceleratorFactoryService);
};
GpuArcVideoServiceHost::GpuArcVideoServiceHost(ArcBridgeService* bridge_service)
: ArcService(bridge_service), binding_(this) {
// static
GpuArcVideoServiceHost* GpuArcVideoServiceHost::GetForBrowserContext(
content::BrowserContext* context) {
return GpuArcVideoServiceHostFactory::GetForBrowserContext(context);
}
GpuArcVideoServiceHost::GpuArcVideoServiceHost(content::BrowserContext* context,
ArcBridgeService* bridge_service)
: arc_bridge_service_(bridge_service), binding_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc_bridge_service()->video()->AddObserver(this);
arc_bridge_service_->video()->AddObserver(this);
}
GpuArcVideoServiceHost::~GpuArcVideoServiceHost() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
arc_bridge_service()->video()->RemoveObserver(this);
// TODO(hidehiko): Currently, the lifetime of ArcBridgeService and
// BrowserContextKeyedService is not nested.
// If ArcServiceManager::Get() returns nullptr, it is already destructed,
// so do not touch it.
if (ArcServiceManager::Get())
arc_bridge_service_->video()->RemoveObserver(this);
}
void GpuArcVideoServiceHost::OnInstanceReady() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto* video_instance =
ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->video(), Init);
ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service_->video(), Init);
DCHECK(video_instance);
mojom::VideoHostPtr host_proxy;
binding_.Bind(mojo::MakeRequest(&host_proxy));
......
......@@ -6,11 +6,15 @@
#define CHROME_BROWSER_CHROMEOS_ARC_VIDEO_GPU_ARC_VIDEO_SERVICE_HOST_H_
#include "base/macros.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/video.mojom.h"
#include "components/arc/instance_holder.h"
#include "components/keyed_service/core/keyed_service.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc {
class ArcBridgeService;
......@@ -23,11 +27,17 @@ class ArcBridgeService;
//
// Lives on the UI thread.
class GpuArcVideoServiceHost
: public ArcService,
: public KeyedService,
public InstanceHolder<mojom::VideoInstance>::Observer,
public mojom::VideoHost {
public:
explicit GpuArcVideoServiceHost(ArcBridgeService* bridge_service);
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static GpuArcVideoServiceHost* GetForBrowserContext(
content::BrowserContext* context);
GpuArcVideoServiceHost(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~GpuArcVideoServiceHost() override;
// arc::InstanceHolder<mojom::VideoInstance>::Observer implementation.
......@@ -38,6 +48,7 @@ class GpuArcVideoServiceHost
const OnBootstrapVideoAcceleratorFactoryCallback& callback) override;
private:
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
mojo::Binding<mojom::VideoHost> binding_;
DISALLOW_COPY_AND_ASSIGN(GpuArcVideoServiceHost);
......
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