Add ICU message format support
[chromium-blink-merge.git] / content / browser / bluetooth / bluetooth_dispatcher_host.h
blobfd79e5e737f642feae76fad73c520290ad2ba667
1 // Copyright 2014 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.
5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/public/browser/browser_message_filter.h"
11 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_gatt_connection.h"
13 #include "device/bluetooth/bluetooth_gatt_service.h"
15 namespace device {
16 class BluetoothUUID;
19 namespace content {
21 struct BluetoothScanFilter;
23 // Dispatches and sends bluetooth related messages sent to/from a child
24 // process BluetoothDispatcher from/to the main browser process.
26 // Intended to be instantiated by the RenderProcessHost and installed as
27 // a filter on the channel. BrowserMessageFilter is refcounted and typically
28 // lives as long as it is installed on a channel.
30 // UI Thread Note:
31 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI
32 // thread because BluetoothAdapter and related objects live there.
33 class CONTENT_EXPORT BluetoothDispatcherHost final
34 : public BrowserMessageFilter,
35 public device::BluetoothAdapter::Observer {
36 public:
37 BluetoothDispatcherHost(int render_process_id);
38 // BrowserMessageFilter:
39 void OnDestruct() const override;
40 void OverrideThreadForMessage(const IPC::Message& message,
41 BrowserThread::ID* thread) override;
42 bool OnMessageReceived(const IPC::Message& message) override;
44 void SetBluetoothAdapterForTesting(
45 scoped_refptr<device::BluetoothAdapter> mock_adapter);
47 protected:
48 ~BluetoothDispatcherHost() override;
50 private:
51 friend class base::DeleteHelper<BluetoothDispatcherHost>;
52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
54 struct RequestDeviceSession;
56 // Set |adapter_| to a BluetoothAdapter instance and register observers,
57 // releasing references to previous |adapter_|.
58 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter);
60 // IPC Handlers, see definitions in bluetooth_messages.h.
61 void OnRequestDevice(
62 int thread_id,
63 int request_id,
64 int frame_routing_id,
65 const std::vector<content::BluetoothScanFilter>& filters,
66 const std::vector<device::BluetoothUUID>& optional_services);
67 void OnConnectGATT(int thread_id, int request_id,
68 const std::string& device_instance_id);
69 void OnGetPrimaryService(int thread_id,
70 int request_id,
71 const std::string& device_instance_id,
72 const std::string& service_uuid);
73 void OnGetCharacteristic(int thread_id,
74 int request_id,
75 const std::string& service_instance_id,
76 const std::string& characteristic_uuid);
77 void OnReadValue(int thread_id,
78 int request_id,
79 const std::string& characteristic_instance_id);
80 void OnWriteValue(int thread_id,
81 int request_id,
82 const std::string& characteristic_instance_id,
83 const std::vector<uint8_t>& value);
85 // Callbacks for BluetoothAdapter::StartDiscoverySession.
86 void OnDiscoverySessionStarted(
87 int thread_id,
88 int request_id,
89 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
90 void OnDiscoverySessionStartedError(int thread_id, int request_id);
92 // Stop in progress discovery session.
93 void StopDiscoverySession(
94 int thread_id,
95 int request_id,
96 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
98 // Callbacks for BluetoothDiscoverySession::Stop.
99 void OnDiscoverySessionStopped(int thread_id, int request_id);
100 void OnDiscoverySessionStoppedError(int thread_id, int request_id);
102 // Callbacks for BluetoothDevice::CreateGattConnection.
103 void OnGATTConnectionCreated(
104 int thread_id,
105 int request_id,
106 const std::string& device_instance_id,
107 scoped_ptr<device::BluetoothGattConnection> connection);
108 void OnCreateGATTConnectionError(
109 int thread_id,
110 int request_id,
111 const std::string& device_instance_id,
112 device::BluetoothDevice::ConnectErrorCode error_code);
114 // Callback for future BluetoothAdapter::ServicesDiscovered callback:
115 // For now we just post a delayed task.
116 // See: https://crbug.com/484504
117 void OnServicesDiscovered(int thread_id,
118 int request_id,
119 const std::string& device_instance_id,
120 const std::string& service_uuid);
122 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic.
123 void OnCharacteristicValueRead(int thread_id,
124 int request_id,
125 const std::vector<uint8>& value);
126 void OnCharacteristicReadValueError(
127 int thread_id,
128 int request_id,
129 device::BluetoothGattService::GattErrorCode);
131 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic.
132 void OnWriteValueSuccess(int thread_id, int request_id);
133 void OnWriteValueFailed(int thread_id,
134 int request_id,
135 device::BluetoothGattService::GattErrorCode);
137 int render_process_id_;
139 // Maps a (thread_id,request_id) to information about its requestDevice call,
140 // including the chooser dialog.
141 // An entry is added to this map in OnRequestDevice, and should be removed
142 // again everywhere a requestDevice() reply is sent.
143 std::map<std::pair<int, int>, RequestDeviceSession> request_device_sessions_;
145 // Maps to get the object's parent based on it's instanceID
146 // Map of service_instance_id to device_instance_id.
147 std::map<std::string, std::string> service_to_device_;
148 // Map of characteristic_instance_id to service_instance_id.
149 std::map<std::string, std::string> characteristic_to_service_;
151 // Defines how long to scan for and how long to discover services for.
152 int current_delay_time_;
154 // A BluetoothAdapter instance representing an adapter of the system.
155 scoped_refptr<device::BluetoothAdapter> adapter_;
157 // Must be last member, see base/memory/weak_ptr.h documentation
158 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_;
160 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost);
163 } // namespace content
165 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_