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 // RenderFrameHostImpl will create an instance of this class and keep | |
| 32 // ownership of it. | |
|
scheib
2016/03/31 04:17:51
Not thread safe, and created on the UI thread as r
ortuno
2016/03/31 16:56:44
Done.
| |
| 33 class WebBluetoothServiceImpl : public blink::mojom::WebBluetoothService { | |
| 34 public: | |
| 35 // |render_frame_host|: The RFH that owns this instance. | |
| 36 // |request|: The instance will be bound to this request's pipe. | |
| 37 WebBluetoothServiceImpl(RenderFrameHost* render_frame_host, | |
| 38 blink::mojom::WebBluetoothServiceRequest request); | |
| 39 ~WebBluetoothServiceImpl() override; | |
| 40 | |
| 41 private: | |
| 42 // WebBluetoothService methods: | |
| 43 void RemoteCharacteristicWriteValue( | |
| 44 const mojo::String& characteristic_instance_id, | |
| 45 mojo::Array<uint8_t> value, | |
| 46 const RemoteCharacteristicWriteValueCallback& callback) override; | |
| 47 | |
| 48 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. | |
| 49 void OnWriteValueSuccess( | |
| 50 const RemoteCharacteristicWriteValueCallback& callback); | |
| 51 void OnWriteValueFailed( | |
| 52 const RemoteCharacteristicWriteValueCallback& callback, | |
| 53 device::BluetoothGattService::GattErrorCode error_code); | |
| 54 | |
| 55 RenderProcessHost* GetRenderProcessHost(); | |
| 56 BluetoothDispatcherHost* GetBluetoothDispatcherHost(); | |
| 57 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); | |
| 58 url::Origin GetOrigin(); | |
| 59 | |
| 60 // The RFH that owns this instance. | |
| 61 RenderFrameHost* render_frame_host_; | |
| 62 | |
| 63 // The lifetime of this instance is exclusively managed by the RFH that | |
| 64 // owns it so we can't use the self-deleting behavior of a StrongBinding. | |
| 65 mojo::Binding<blink::mojom::WebBluetoothService> binding_; | |
| 66 | |
| 67 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); | |
| 70 }; | |
| 71 | |
| 72 } // namespace content | |
| 73 | |
| 74 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | |
| OLD | NEW |