1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "device/vr/android/arcore/arcore_device_provider_factory.h" 6 7 #include "base/logging.h" 8 #include "device/vr/public/cpp/vr_device_provider.h" 9 10 namespace device { 11 12 namespace { 13 ArCoreDeviceProviderFactory* g_arcore_device_provider_factory = nullptr; 14 bool create_called = false; 15 } // namespace 16 17 // static 18 std::unique_ptr<device::VRDeviceProvider> Create()19ArCoreDeviceProviderFactory::Create() { 20 DVLOG(2) << __func__; 21 22 create_called = true; 23 if (!g_arcore_device_provider_factory) 24 return nullptr; 25 return g_arcore_device_provider_factory->CreateDeviceProvider(); 26 } 27 28 // static Install(std::unique_ptr<ArCoreDeviceProviderFactory> factory)29void ArCoreDeviceProviderFactory::Install( 30 std::unique_ptr<ArCoreDeviceProviderFactory> factory) { 31 DVLOG(2) << __func__; 32 33 DCHECK_NE(g_arcore_device_provider_factory, factory.get()); 34 if (g_arcore_device_provider_factory) { 35 delete g_arcore_device_provider_factory; 36 } else if (create_called) { 37 // TODO(crbug.com/1050470): Remove this logging after investigation. 38 // We only hit this code path if "Install" is called for the first time 39 // after a call to ArCoreDeviceProviderFactory::Create. This indicates that 40 // we previously did not return an ARCoreDeviceProvider, but the system we 41 // are on actually *can* support an ARCoreDeviceProvider. 42 LOG(ERROR) << "AR provider factory installed after create"; 43 } 44 45 g_arcore_device_provider_factory = factory.release(); 46 } 47 48 } // namespace device 49