Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRController.cpp

Issue 2635293002: Ensure navigator.getVRDisplays always resolves. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/vr/getVRDisplays_always_resolves.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/vr/VRController.h" 5 #include "modules/vr/VRController.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "core/dom/DOMException.h" 8 #include "core/dom/DOMException.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
11 #include "modules/vr/NavigatorVR.h" 11 #include "modules/vr/NavigatorVR.h"
12 #include "modules/vr/VRGetDevicesCallback.h" 12 #include "modules/vr/VRGetDevicesCallback.h"
13 #include "public/platform/InterfaceProvider.h" 13 #include "public/platform/InterfaceProvider.h"
14 14
15 #include "wtf/Assertions.h" 15 #include "wtf/Assertions.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 VRController::VRController(NavigatorVR* navigatorVR) 19 VRController::VRController(NavigatorVR* navigatorVR)
20 : ContextLifecycleObserver(navigatorVR->document()), 20 : ContextLifecycleObserver(navigatorVR->document()),
21 m_navigatorVR(navigatorVR), 21 m_navigatorVR(navigatorVR),
22 m_displaySynced(false), 22 m_displaySynced(false),
23 m_binding(this) { 23 m_binding(this) {
24 navigatorVR->document()->frame()->interfaceProvider()->getInterface( 24 navigatorVR->document()->frame()->interfaceProvider()->getInterface(
25 mojo::GetProxy(&m_service)); 25 mojo::GetProxy(&m_service));
26 m_service.set_connection_error_handler(convertToBaseCallback(
27 WTF::bind(&VRController::dispose, wrapWeakPersistent(this))));
26 m_service->SetClient( 28 m_service->SetClient(
27 m_binding.CreateInterfacePtrAndBind(), 29 m_binding.CreateInterfacePtrAndBind(),
28 convertToBaseCallback( 30 convertToBaseCallback(
29 WTF::bind(&VRController::onDisplaysSynced, wrapPersistent(this)))); 31 WTF::bind(&VRController::onDisplaysSynced, wrapPersistent(this))));
30 ThreadState::current()->registerPreFinalizer(this); 32 ThreadState::current()->registerPreFinalizer(this);
31 } 33 }
32 34
33 VRController::~VRController() {} 35 VRController::~VRController() {}
34 36
35 void VRController::getDisplays(ScriptPromiseResolver* resolver) { 37 void VRController::getDisplays(ScriptPromiseResolver* resolver) {
36 if (!m_service) { 38 // If we've previously synced the VRDisplays or no longer have a valid service
37 DOMException* exception = DOMException::create( 39 // connection just return the current list. In the case of the service being
38 InvalidStateError, "The service is no longer active."); 40 // disconnected this will be an empty array.
39 resolver->reject(exception); 41 if (!m_service || m_displaySynced) {
40 return;
41 }
42
43 // If we've previously synced the VRDisplays just return the current list.
44 if (m_displaySynced) {
45 resolver->resolve(m_displays); 42 resolver->resolve(m_displays);
46 return; 43 return;
47 } 44 }
48 45
49 // Otherwise we're still waiting for the full list of displays to be populated 46 // Otherwise we're still waiting for the full list of displays to be populated
50 // so queue up the promise for resolution when onDisplaysSynced is called. 47 // so queue up the promise for resolution when onDisplaysSynced is called.
51 m_pendingGetDevicesCallbacks.append( 48 m_pendingGetDevicesCallbacks.append(
52 makeUnique<VRGetDevicesCallback>(resolver)); 49 makeUnique<VRGetDevicesCallback>(resolver));
53 } 50 }
54 51
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 99
103 void VRController::dispose() { 100 void VRController::dispose() {
104 // If the document context was destroyed, shut down the client connection 101 // If the document context was destroyed, shut down the client connection
105 // and never call the mojo service again. 102 // and never call the mojo service again.
106 m_service.reset(); 103 m_service.reset();
107 m_binding.Close(); 104 m_binding.Close();
108 105
109 // Shutdown all displays' message pipe 106 // Shutdown all displays' message pipe
110 for (size_t i = 0; i < m_displays.size(); ++i) 107 for (size_t i = 0; i < m_displays.size(); ++i)
111 m_displays[i]->dispose(); 108 m_displays[i]->dispose();
109
110 m_displays.clear();
111
112 // Ensure that any outstanding getDisplays promises are resolved.
113 onGetDisplays();
112 } 114 }
113 115
114 DEFINE_TRACE(VRController) { 116 DEFINE_TRACE(VRController) {
115 visitor->trace(m_navigatorVR); 117 visitor->trace(m_navigatorVR);
116 visitor->trace(m_displays); 118 visitor->trace(m_displays);
117 119
118 ContextLifecycleObserver::trace(visitor); 120 ContextLifecycleObserver::trace(visitor);
119 } 121 }
120 122
121 } // namespace blink 123 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/vr/getVRDisplays_always_resolves.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698