Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ |
| 6 #define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 6 #define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "content/child/worker_task_runner.h" | 10 #include "content/child/worker_task_runner.h" |
| 11 #include "content/common/bluetooth/bluetooth_device.h" | 11 #include "content/common/bluetooth/bluetooth_device.h" |
| 12 #include "content/common/bluetooth/bluetooth_error.h" | 12 #include "content/common/bluetooth/bluetooth_error.h" |
| 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" | 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class MessageLoop; | 16 class MessageLoop; |
| 17 class TaskRunner; | 17 class TaskRunner; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace IPC { | 20 namespace IPC { |
| 21 class Message; | 21 class Message; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 class ThreadSafeSender; | 25 class ThreadSafeSender; |
| 26 struct BluetoothPrimaryServiceRequest; | |
| 26 | 27 |
| 27 // Dispatcher for child process threads which communicates to the browser's | 28 // Dispatcher for child process threads which communicates to the browser's |
| 28 // BluetoothDispatcherHost. | 29 // BluetoothDispatcherHost. |
| 29 // | 30 // |
| 30 // Instances are created for each thread as necessary by WebBluetoothImpl. | 31 // Instances are created for each thread as necessary by WebBluetoothImpl. |
| 31 // | 32 // |
| 32 // Incoming IPC messages are received by the BluetoothMessageFilter and | 33 // Incoming IPC messages are received by the BluetoothMessageFilter and |
| 33 // directed to the thread specific instance of this class. | 34 // directed to the thread specific instance of this class. |
| 34 // Outgoing messages come from WebBluetoothImpl. | 35 // Outgoing messages come from WebBluetoothImpl. |
| 35 class BluetoothDispatcher : public WorkerTaskRunner::Observer { | 36 class BluetoothDispatcher : public WorkerTaskRunner::Observer { |
| 36 public: | 37 public: |
| 37 explicit BluetoothDispatcher(ThreadSafeSender* sender); | 38 explicit BluetoothDispatcher(ThreadSafeSender* sender); |
| 38 ~BluetoothDispatcher() override; | 39 ~BluetoothDispatcher() override; |
| 39 | 40 |
| 40 // Gets or Creates a BluetoothDispatcher for the current thread. | 41 // Gets or Creates a BluetoothDispatcher for the current thread. |
| 41 // |thread_safe_sender| is required when constructing a BluetoothDispatcher. | 42 // |thread_safe_sender| is required when constructing a BluetoothDispatcher. |
| 42 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance( | 43 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance( |
| 43 ThreadSafeSender* thread_safe_sender); | 44 ThreadSafeSender* thread_safe_sender); |
| 44 | 45 |
| 45 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener. | 46 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener. |
| 46 bool Send(IPC::Message* msg); | 47 bool Send(IPC::Message* msg); |
| 47 void OnMessageReceived(const IPC::Message& msg); | 48 void OnMessageReceived(const IPC::Message& msg); |
| 48 | 49 |
| 49 // Corresponding to WebBluetoothImpl methods. | 50 // Corresponding to WebBluetoothImpl methods. |
| 50 void requestDevice(blink::WebBluetoothRequestDeviceCallbacks* callbacks); | 51 void requestDevice(blink::WebBluetoothRequestDeviceCallbacks* callbacks); |
| 51 void connectGATT(const blink::WebString& device_instance_id, | 52 void connectGATT(const blink::WebString& device_instance_id, |
| 52 blink::WebBluetoothConnectGATTCallbacks* callbacks); | 53 blink::WebBluetoothConnectGATTCallbacks* callbacks); |
| 54 void getPrimaryService( | |
| 55 const blink::WebString& device_instance_id, | |
| 56 const blink::WebString& service_uuid, | |
| 57 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks); | |
| 53 | 58 |
| 54 // WorkerTaskRunner::Observer implementation. | 59 // WorkerTaskRunner::Observer implementation. |
| 55 void OnWorkerRunLoopStopped() override; | 60 void OnWorkerRunLoopStopped() override; |
| 56 | 61 |
| 57 private: | 62 private: |
| 58 // IPC Handlers, see definitions in bluetooth_messages.h. | 63 // IPC Handlers, see definitions in bluetooth_messages.h. |
| 59 void OnRequestDeviceSuccess(int thread_id, | 64 void OnRequestDeviceSuccess(int thread_id, |
| 60 int request_id, | 65 int request_id, |
| 61 const BluetoothDevice& device); | 66 const BluetoothDevice& device); |
| 62 void OnRequestDeviceError(int thread_id, | 67 void OnRequestDeviceError(int thread_id, |
| 63 int request_id, | 68 int request_id, |
| 64 BluetoothError error_type); | 69 BluetoothError error_type); |
| 65 | 70 |
| 66 void OnConnectGATTSuccess(int thread_id, | 71 void OnConnectGATTSuccess(int thread_id, |
| 67 int request_id, | 72 int request_id, |
| 68 const std::string& message); | 73 const std::string& message); |
| 69 | 74 |
| 70 void OnConnectGATTError(int thread_id, | 75 void OnConnectGATTError(int thread_id, |
| 71 int request_id, | 76 int request_id, |
| 72 BluetoothError error_type); | 77 BluetoothError error_type); |
| 78 void OnGetPrimaryServiceSuccess(int thread_id, | |
| 79 int request_id, | |
| 80 const std::string& service_instance_id); | |
| 81 void OnGetPrimaryServiceError(int thread_id, | |
| 82 int request_id, | |
| 83 BluetoothError error_type); | |
| 73 | 84 |
| 74 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 85 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 75 | 86 |
| 76 // Tracks device requests sent to browser to match replies with callbacks. | 87 // Tracks device requests sent to browser to match replies with callbacks. |
| 77 // Owns callback objects. | 88 // Owns callback objects. |
| 78 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | 89 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> |
| 79 pending_requests_; | 90 pending_requests_; |
| 80 // Tracks requests to connect to a device. | 91 // Tracks requests to connect to a device. |
| 81 // Owns callback objects. | 92 // Owns callback objects. |
| 82 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer> | 93 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer> |
| 83 pending_connect_requests_; | 94 pending_connect_requests_; |
| 95 // Tracks requests to get a primary service from a device. | |
| 96 // Owns callback objects. | |
|
Jeffrey Yasskin
2015/05/29 20:31:42
They aren't callback objects anymore. :)
ortuno
2015/06/01 18:27:03
Done.
| |
| 97 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer> | |
| 98 pending_primary_service_requests_; | |
| 84 | 99 |
| 85 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); | 100 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); |
| 86 }; | 101 }; |
| 87 | 102 |
| 88 } // namespace content | 103 } // namespace content |
| 89 | 104 |
| 90 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 105 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ |
| OLD | NEW |