Chromium Code Reviews| Index: device/vr/android/gvr/gvr_device_provider.cc |
| diff --git a/device/vr/android/gvr/gvr_device_provider.cc b/device/vr/android/gvr/gvr_device_provider.cc |
| index 4aff6ce54860890f749df2ec638836a32b48f671..fcf6562a219cb4acda4411bde703a11fa4725772 100644 |
| --- a/device/vr/android/gvr/gvr_device_provider.cc |
| +++ b/device/vr/android/gvr/gvr_device_provider.cc |
| @@ -33,9 +33,14 @@ GvrDeviceProvider::~GvrDeviceProvider() { |
| } |
| void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { |
| - Initialize(); |
| - if (initialized_) |
| - devices->push_back(vr_device_.get()); |
| + devices->push_back(vr_device_.get()); |
| +} |
| + |
| +device::GvrDelegateProvider* GvrDeviceProvider::GetDelegateProvider() { |
| + device::GvrDelegateProvider* provider = |
| + device::GvrDelegateProvider::GetInstance(); |
| + Initialize(device::GvrDelegateProvider::GetInstance()); |
|
dcheng
2017/03/08 07:23:40
Nit: pass provider here
klausw
2017/03/08 08:11:09
Done.
|
| + return provider; |
| } |
| void GvrDeviceProvider::Initialize() { |
| @@ -43,41 +48,36 @@ void GvrDeviceProvider::Initialize() { |
| // GvrDeviceProvider so we don't have to call this function multiple times. |
| // Ideally the DelegateProvider would always be available, and GetInstance() |
| // would create it. |
| - if (initialized_) |
| + Initialize(device::GvrDelegateProvider::GetInstance()); |
| +} |
| + |
| +void GvrDeviceProvider::Initialize(device::GvrDelegateProvider* provider) { |
| + if (!provider) |
| return; |
| - device::GvrDelegateProvider* delegate_provider = |
| - device::GvrDelegateProvider::GetInstance(); |
| - if (!delegate_provider) |
| - return; |
| - delegate_provider->SetDeviceProvider(this); |
| - initialized_ = true; |
| + provider->SetDeviceProvider(this); |
| } |
| void GvrDeviceProvider::RequestPresent( |
| + mojom::VRSubmitFrameClientPtr submit_client, |
| const base::Callback<void(bool)>& callback) { |
| - Initialize(); |
| - device::GvrDelegateProvider* delegate_provider = |
| - device::GvrDelegateProvider::GetInstance(); |
| + device::GvrDelegateProvider* delegate_provider = GetDelegateProvider(); |
| if (!delegate_provider) |
| return callback.Run(false); |
| // RequestWebVRPresent is async as we may trigger a DON flow that pauses |
| // Chrome. |
| - delegate_provider->RequestWebVRPresent(callback); |
| + delegate_provider->RequestWebVRPresent(std::move(submit_client), callback); |
| } |
| // VR presentation exit requested by the API. |
| void GvrDeviceProvider::ExitPresent() { |
| - Initialize(); |
| - GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); |
| + device::GvrDelegateProvider* delegate_provider = GetDelegateProvider(); |
| if (delegate_provider) |
| delegate_provider->ExitWebVRPresent(); |
| } |
| void GvrDeviceProvider::SetListeningForActivate(bool listening) { |
| - Initialize(); |
| - device::GvrDelegateProvider* delegate_provider = |
| - device::GvrDelegateProvider::GetInstance(); |
| + device::GvrDelegateProvider* delegate_provider = GetDelegateProvider(); |
| if (!delegate_provider) |
| return; |