Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "content/browser/bad_message.h" | |
| 10 #include "content/common/content_export.h" | |
| 11 #include "device/bluetooth/bluetooth_gatt_service.h" | |
| 12 #include "mojo/public/cpp/bindings/binding.h" | |
| 13 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" | |
| 14 | |
| 15 namespace url { | |
| 16 class Origin; | |
| 17 } // namespace url | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 class BluetoothDispatcherHost; | |
| 22 class RenderFrameHost; | |
| 23 class RenderProcessHost; | |
| 24 | |
| 25 // Implementation of Mojo WebBluetoothService located in | |
| 26 // third_party/WebKit/public/platform/modules/bluetooth. | |
| 27 // It handles Web Bluetooth API requests coming from Blink / renderer | |
| 28 // process and uses the platform abstraction of device/bluetooth. | |
| 29 // This class is instantiated on-demand via Mojo's ConnectToRemoteService | |
| 30 // from the renderer when the first Web Bluetooth API request is handled. | |
| 31 // When this happens RenderFrameHostImpl will create an instance of this | |
| 32 // class and save it in a scope pointer, thus making the lifetime of the | |
|
Jeffrey Yasskin
2016/03/29 20:30:02
s/scope pointer/scoped_ptr/?
You could make this
ortuno
2016/03/29 22:14:03
Done.
| |
| 33 // instance depend on the lifetime of the RenderFrameHost. | |
| 34 class WebBluetoothServiceImpl : public blink::mojom::WebBluetoothService { | |
| 35 public: | |
| 36 // |render_frame_host|: The RFH that owns this instance. | |
| 37 // |request|: The instance will be bound to this request. Used for mojo | |
|
Jeffrey Yasskin
2016/03/29 20:30:02
"this request's pipe", I think, looking at https:/
ortuno
2016/03/29 22:14:03
Done.
| |
| 38 // setup. | |
| 39 WebBluetoothServiceImpl(RenderFrameHost* render_frame_host, | |
| 40 blink::mojom::WebBluetoothServiceRequest request); | |
| 41 ~WebBluetoothServiceImpl() override; | |
| 42 | |
| 43 private: | |
| 44 // WebBluetoothService methods: | |
| 45 void RemoteCharacteristicWriteValue( | |
| 46 const mojo::String& characteristic_instance_id, | |
| 47 mojo::Array<uint8_t> value, | |
| 48 const RemoteCharacteristicWriteValueCallback& callback) override; | |
| 49 | |
| 50 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. | |
| 51 void OnWriteValueSuccess( | |
| 52 const RemoteCharacteristicWriteValueCallback& callback); | |
| 53 void OnWriteValueFailed( | |
| 54 const RemoteCharacteristicWriteValueCallback& callback, | |
| 55 device::BluetoothGattService::GattErrorCode error_code); | |
| 56 | |
| 57 RenderProcessHost* GetRenderProcessHost(); | |
| 58 BluetoothDispatcherHost* GetBluetoothDispatcherHost(); | |
| 59 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); | |
| 60 url::Origin GetOrigin(); | |
| 61 | |
| 62 // The RFH that owns this instance. | |
| 63 RenderFrameHost* render_frame_host_; | |
| 64 | |
| 65 // The lifetime of this instance is exclusively managed by the RFH that | |
| 66 // owns it. Using a Binding instead of a StrongBinding means that this | |
|
Jeffrey Yasskin
2016/03/29 20:30:02
"... owns it, so we can't use the self-deleting be
ortuno
2016/03/29 22:14:03
Done.
| |
| 67 // instance will not be deleted when the pipe is closed or an error occurs. | |
| 68 mojo::Binding<blink::mojom::WebBluetoothService> binding_; | |
| 69 | |
| 70 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; | |
| 71 | |
| 72 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); | |
| 73 }; | |
| 74 | |
| 75 } // namespace content | |
| 76 | |
| 77 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | |
| OLD | NEW |