| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | |
| 6 #define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | |
| 7 | |
| 8 #include "base/id_map.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "content/child/worker_task_runner.h" | |
| 11 #include "content/common/bluetooth/bluetooth_device.h" | |
| 12 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" | |
| 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError
.h" | |
| 14 | |
| 15 namespace base { | |
| 16 class MessageLoop; | |
| 17 class TaskRunner; | |
| 18 } | |
| 19 | |
| 20 namespace IPC { | |
| 21 class Message; | |
| 22 } | |
| 23 | |
| 24 struct BluetoothCharacteristicRequest; | |
| 25 struct BluetoothPrimaryServiceRequest; | |
| 26 | |
| 27 namespace content { | |
| 28 class ThreadSafeSender; | |
| 29 | |
| 30 // Dispatcher for child process threads which communicates to the browser's | |
| 31 // BluetoothDispatcherHost. | |
| 32 // | |
| 33 // Instances are created for each thread as necessary by WebBluetoothImpl. | |
| 34 // | |
| 35 // Incoming IPC messages are received by the BluetoothMessageFilter and | |
| 36 // directed to the thread specific instance of this class. | |
| 37 // Outgoing messages come from WebBluetoothImpl. | |
| 38 class BluetoothDispatcher : public WorkerTaskRunner::Observer { | |
| 39 public: | |
| 40 explicit BluetoothDispatcher(ThreadSafeSender* sender); | |
| 41 ~BluetoothDispatcher() override; | |
| 42 | |
| 43 // Gets or Creates a BluetoothDispatcher for the current thread. | |
| 44 // |thread_safe_sender| is required when constructing a BluetoothDispatcher. | |
| 45 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance( | |
| 46 ThreadSafeSender* thread_safe_sender); | |
| 47 | |
| 48 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener. | |
| 49 bool Send(IPC::Message* msg); | |
| 50 void OnMessageReceived(const IPC::Message& msg); | |
| 51 | |
| 52 // Corresponding to WebBluetoothImpl methods. | |
| 53 void requestDevice(const blink::WebRequestDeviceOptions& options, | |
| 54 blink::WebBluetoothRequestDeviceCallbacks* callbacks); | |
| 55 void connectGATT(const blink::WebString& device_instance_id, | |
| 56 blink::WebBluetoothConnectGATTCallbacks* callbacks); | |
| 57 void getPrimaryService( | |
| 58 const blink::WebString& device_instance_id, | |
| 59 const blink::WebString& service_uuid, | |
| 60 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks); | |
| 61 | |
| 62 void getCharacteristic( | |
| 63 const blink::WebString& service_instance_id, | |
| 64 const blink::WebString& characteristic_uuid, | |
| 65 blink::WebBluetoothGetCharacteristicCallbacks* callbacks); | |
| 66 void readValue(const blink::WebString& characteristic_instance_id, | |
| 67 blink::WebBluetoothReadValueCallbacks* callbacks); | |
| 68 void writeValue(const blink::WebString& characteristic_instance_id, | |
| 69 const std::vector<uint8_t>& value, | |
| 70 blink::WebBluetoothWriteValueCallbacks*); | |
| 71 | |
| 72 // WorkerTaskRunner::Observer implementation. | |
| 73 void OnWorkerRunLoopStopped() override; | |
| 74 | |
| 75 private: | |
| 76 // IPC Handlers, see definitions in bluetooth_messages.h. | |
| 77 void OnRequestDeviceSuccess(int thread_id, | |
| 78 int request_id, | |
| 79 const BluetoothDevice& device); | |
| 80 void OnRequestDeviceError(int thread_id, | |
| 81 int request_id, | |
| 82 blink::WebBluetoothError error); | |
| 83 | |
| 84 void OnConnectGATTSuccess(int thread_id, | |
| 85 int request_id, | |
| 86 const std::string& message); | |
| 87 | |
| 88 void OnConnectGATTError(int thread_id, | |
| 89 int request_id, | |
| 90 blink::WebBluetoothError error); | |
| 91 void OnGetPrimaryServiceSuccess(int thread_id, | |
| 92 int request_id, | |
| 93 const std::string& service_instance_id); | |
| 94 void OnGetPrimaryServiceError(int thread_id, | |
| 95 int request_id, | |
| 96 blink::WebBluetoothError error); | |
| 97 void OnGetCharacteristicSuccess( | |
| 98 int thread_id, | |
| 99 int request_id, | |
| 100 const std::string& characteristic_instance_id); | |
| 101 void OnGetCharacteristicError(int thread_id, | |
| 102 int request_id, | |
| 103 blink::WebBluetoothError error); | |
| 104 void OnReadValueSuccess(int thread_id, | |
| 105 int request_id, | |
| 106 const std::vector<uint8_t>& value); | |
| 107 void OnReadValueError(int thread_id, | |
| 108 int request_id, | |
| 109 blink::WebBluetoothError error); | |
| 110 void OnWriteValueSuccess(int thread_id, int request_id); | |
| 111 void OnWriteValueError(int thread_id, | |
| 112 int request_id, | |
| 113 blink::WebBluetoothError error); | |
| 114 | |
| 115 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
| 116 | |
| 117 // Tracks device requests sent to browser to match replies with callbacks. | |
| 118 // Owns callback objects. | |
| 119 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | |
| 120 pending_requests_; | |
| 121 // Tracks requests to connect to a device. | |
| 122 // Owns callback objects. | |
| 123 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer> | |
| 124 pending_connect_requests_; | |
| 125 // Tracks requests to get a primary service from a device. | |
| 126 // Owns request objects. | |
| 127 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer> | |
| 128 pending_primary_service_requests_; | |
| 129 // Tracks requests to get a characteristic from a service. | |
| 130 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer> | |
| 131 pending_characteristic_requests_; | |
| 132 // Tracks requests to read from a characteristics. | |
| 133 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer> | |
| 134 pending_read_value_requests_; | |
| 135 IDMap<blink::WebBluetoothWriteValueCallbacks, IDMapOwnPointer> | |
| 136 pending_write_value_requests_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); | |
| 139 }; | |
| 140 | |
| 141 } // namespace content | |
| 142 | |
| 143 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | |
| OLD | NEW |