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

Side by Side Diff: third_party/WebKit/Source/modules/webusb/USB.h

Issue 1946063002: Replace DeviceManager::GetDeviceChanges with a client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proper_stubs
Patch Set: Rebase.d Created 4 years, 7 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
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 #ifndef USB_h 5 #ifndef USB_h
6 #define USB_h 6 #define USB_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptWrappable.h" 9 #include "bindings/core/v8/ScriptWrappable.h"
10 #include "core/dom/ContextLifecycleObserver.h" 10 #include "core/dom/ContextLifecycleObserver.h"
11 #include "core/events/EventTarget.h" 11 #include "core/events/EventTarget.h"
12 #include "device/usb/public/interfaces/chooser_service.mojom-blink.h" 12 #include "device/usb/public/interfaces/chooser_service.mojom-blink.h"
13 #include "device/usb/public/interfaces/device_manager.mojom-blink.h" 13 #include "device/usb/public/interfaces/device_manager.mojom-blink.h"
14 #include "mojo/public/cpp/bindings/binding.h"
14 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
18 class LocalFrame; 19 class LocalFrame;
19 class ScopedScriptPromiseResolver; 20 class ScopedScriptPromiseResolver;
20 class ScriptState; 21 class ScriptState;
21 class USBDeviceRequestOptions; 22 class USBDeviceRequestOptions;
22 23
23 class USB final 24 class USB final
24 : public EventTargetWithInlineData 25 : public EventTargetWithInlineData
25 , public ContextLifecycleObserver { 26 , public ContextLifecycleObserver
27 , public device::usb::blink::DeviceManagerClient {
26 DEFINE_WRAPPERTYPEINFO(); 28 DEFINE_WRAPPERTYPEINFO();
27 USING_GARBAGE_COLLECTED_MIXIN(USB); 29 USING_GARBAGE_COLLECTED_MIXIN(USB);
30 USING_PRE_FINALIZER(USB, dispose);
28 public: 31 public:
29 static USB* create(LocalFrame& frame) 32 static USB* create(LocalFrame& frame)
30 { 33 {
31 return new USB(frame); 34 return new USB(frame);
32 } 35 }
33 36
34 virtual ~USB(); 37 virtual ~USB();
35 38
39 void dispose();
40
36 // USB.idl 41 // USB.idl
37 ScriptPromise getDevices(ScriptState*); 42 ScriptPromise getDevices(ScriptState*);
38 ScriptPromise requestDevice(ScriptState*, const USBDeviceRequestOptions&); 43 ScriptPromise requestDevice(ScriptState*, const USBDeviceRequestOptions&);
39 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); 44 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
40 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); 45 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
41 46
42 // EventTarget overrides. 47 // EventTarget overrides.
43 ExecutionContext* getExecutionContext() const override; 48 ExecutionContext* getExecutionContext() const override;
44 const AtomicString& interfaceName() const override; 49 const AtomicString& interfaceName() const override;
45 50
46 // ContextLifecycleObserver overrides. 51 // ContextLifecycleObserver overrides.
47 void contextDestroyed() override; 52 void contextDestroyed() override;
48 53
54 // DeviceManagerClient implementation.
55 void OnDeviceAdded(device::usb::blink::DeviceInfoPtr);
56 void OnDeviceRemoved(device::usb::blink::DeviceInfoPtr);
57
49 device::usb::blink::DeviceManager* deviceManager() const { return m_deviceMa nager.get(); } 58 device::usb::blink::DeviceManager* deviceManager() const { return m_deviceMa nager.get(); }
50 59
51 void onGetDevices(ScriptPromiseResolver*, mojo::WTFArray<device::usb::blink: :DeviceInfoPtr>); 60 void onGetDevices(ScriptPromiseResolver*, mojo::WTFArray<device::usb::blink: :DeviceInfoPtr>);
52 void onGetPermission(ScriptPromiseResolver*, device::usb::blink::DeviceInfoP tr); 61 void onGetPermission(ScriptPromiseResolver*, device::usb::blink::DeviceInfoP tr);
53 void onDeviceChanges(device::usb::blink::DeviceChangeNotificationPtr);
54 62
55 void onDeviceManagerConnectionError(); 63 void onDeviceManagerConnectionError();
56 void onChooserServiceConnectionError(); 64 void onChooserServiceConnectionError();
57 65
58 DECLARE_VIRTUAL_TRACE(); 66 DECLARE_VIRTUAL_TRACE();
59 67
60 private: 68 private:
61 explicit USB(LocalFrame& frame); 69 explicit USB(LocalFrame& frame);
62 70
63 device::usb::blink::DeviceManagerPtr m_deviceManager; 71 device::usb::blink::DeviceManagerPtr m_deviceManager;
64 HeapHashSet<Member<ScriptPromiseResolver>> m_deviceManagerRequests; 72 HeapHashSet<Member<ScriptPromiseResolver>> m_deviceManagerRequests;
65 device::usb::blink::ChooserServicePtr m_chooserService; 73 device::usb::blink::ChooserServicePtr m_chooserService;
66 HeapHashSet<Member<ScriptPromiseResolver>> m_chooserServiceRequests; 74 HeapHashSet<Member<ScriptPromiseResolver>> m_chooserServiceRequests;
75 mojo::Binding<device::usb::blink::DeviceManagerClient> m_clientBinding;
67 }; 76 };
68 77
69 } // namespace blink 78 } // namespace blink
70 79
71 #endif // USB_h 80 #endif // USB_h
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/usb/usbDevice-iframe.html ('k') | third_party/WebKit/Source/modules/webusb/USB.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698