// Copyright 2016 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 DEVICE_VR_VR_SERVICE_IMPL_H #define DEVICE_VR_VR_SERVICE_IMPL_H #include #include "base/macros.h" #include "device/vr/vr_device.h" #include "device/vr/vr_display_impl.h" #include "device/vr/vr_export.h" #include "device/vr/vr_service.mojom.h" #include "mojo/public/cpp/bindings/binding.h" namespace service_manager { struct BindSourceInfo; } namespace device { // Browser process representation of a WebVR site session. Instantiated through // Mojo once the user loads a page containing WebVR. // It instantiates a VRDisplayImpl for each newly connected VRDisplay and sends // the display's info to the render process through its connected // mojom::VRServiceClient. class VRServiceImpl : public mojom::VRService { public: DEVICE_VR_EXPORT VRServiceImpl(); DEVICE_VR_EXPORT ~VRServiceImpl() override; DEVICE_VR_EXPORT static void Create( const service_manager::BindSourceInfo& source_info, mojom::VRServiceRequest request); // mojom::VRService implementation // Adds this service to the VRDeviceManager. void SetClient(mojom::VRServiceClientPtr service_client, const SetClientCallback& callback) override; bool listening_for_activate() { return listening_for_activate_; } // Tells the render process that a new VR device is available. void ConnectDevice(VRDevice* device); private: friend class FakeVRServiceClient; friend class VRDeviceManagerTest; friend class VRDisplayImplTest; friend class VRServiceImplTest; void SetListeningForActivate(bool listening) override; void OnVRDisplayInfoCreated(VRDevice* device, mojom::VRDisplayInfoPtr display_info); std::map> displays_; mojom::VRServiceClientPtr client_; bool listening_for_activate_; bool in_set_client_; unsigned connected_devices_; unsigned handled_devices_; base::WeakPtrFactory weak_ptr_factory_; // Getter for testing. DEVICE_VR_EXPORT VRDisplayImpl* GetVRDisplayImplForTesting(VRDevice* device); DISALLOW_COPY_AND_ASSIGN(VRServiceImpl); }; } // namespace device #endif // DEVICE_VR_VR_SERVICE_IMPL_H