Chromium Code Reviews| Index: content/browser/bluetooth/web_bluetooth_service_impl.h |
| diff --git a/content/browser/bluetooth/web_bluetooth_service_impl.h b/content/browser/bluetooth/web_bluetooth_service_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d6d16ccb8e509cafdab675d733eb24f55d000703 |
| --- /dev/null |
| +++ b/content/browser/bluetooth/web_bluetooth_service_impl.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
| +#define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
| + |
| +#include "base/macros.h" |
| +#include "content/browser/bad_message.h" |
| +#include "content/common/content_export.h" |
| +#include "device/bluetooth/bluetooth_gatt_service.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.mojom.h" |
| + |
| +namespace url { |
| +class Origin; |
| +} // namespace url |
| + |
| +namespace content { |
| + |
| +class BluetoothDispatcherHost; |
| +class RenderFrameHost; |
| +class RenderProcessHost; |
| + |
| +// Implementation of Mojo WebBluetoothService located in |
| +// third_party/WebKit/public/platform/modules/bluetooth. |
| +// It handles Web Bluetooth API requests coming from Blink / renderer |
| +// process and uses the platform abstraction of device/bluetooth. |
| +// This class is instantiated on-demand via Mojo's ConnectToRemoteService |
| +// from the renderer when the first Web Bluetooth API request is handled. |
| +// RenderFrameHostImpl will create an instance of this class and keep |
| +// 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.
|
| +class WebBluetoothServiceImpl : public blink::mojom::WebBluetoothService { |
| + public: |
| + // |render_frame_host|: The RFH that owns this instance. |
| + // |request|: The instance will be bound to this request's pipe. |
| + WebBluetoothServiceImpl(RenderFrameHost* render_frame_host, |
| + blink::mojom::WebBluetoothServiceRequest request); |
| + ~WebBluetoothServiceImpl() override; |
| + |
| + private: |
| + // WebBluetoothService methods: |
| + void RemoteCharacteristicWriteValue( |
| + const mojo::String& characteristic_instance_id, |
| + mojo::Array<uint8_t> value, |
| + const RemoteCharacteristicWriteValueCallback& callback) override; |
| + |
| + // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. |
| + void OnWriteValueSuccess( |
| + const RemoteCharacteristicWriteValueCallback& callback); |
| + void OnWriteValueFailed( |
| + const RemoteCharacteristicWriteValueCallback& callback, |
| + device::BluetoothGattService::GattErrorCode error_code); |
| + |
| + RenderProcessHost* GetRenderProcessHost(); |
| + BluetoothDispatcherHost* GetBluetoothDispatcherHost(); |
| + void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); |
| + url::Origin GetOrigin(); |
| + |
| + // The RFH that owns this instance. |
| + RenderFrameHost* render_frame_host_; |
| + |
| + // The lifetime of this instance is exclusively managed by the RFH that |
| + // owns it so we can't use the self-deleting behavior of a StrongBinding. |
| + mojo::Binding<blink::mojom::WebBluetoothService> binding_; |
| + |
| + base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |