| 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_error.h" |
| 12 #include "third_party/WebKit/public/platform/WebBluetooth.h" |
| 13 |
| 14 namespace base { |
| 15 class MessageLoop; |
| 16 class TaskRunner; |
| 17 } |
| 18 |
| 19 namespace IPC { |
| 20 class Message; |
| 21 } |
| 22 |
| 23 namespace content { |
| 24 class ThreadSafeSender; |
| 25 |
| 26 // Dispatcher for child process threads which communicates to the browser's |
| 27 // BluetoothDispatcherHost. |
| 28 // |
| 29 // Instances are created for each thread as necessary by WebBluetoothImpl. |
| 30 // |
| 31 // Incoming IPC messages are received by the BluetoothMessageFilter and |
| 32 // directed to the thread specific instance of this class. |
| 33 // Outgoing messages come from WebBluetoothImpl. |
| 34 class BluetoothDispatcher : public WorkerTaskRunner::Observer { |
| 35 public: |
| 36 explicit BluetoothDispatcher(ThreadSafeSender* sender); |
| 37 ~BluetoothDispatcher() override; |
| 38 |
| 39 // Gets or Creates a BluetoothDispatcher for the current thread. |
| 40 // |thread_safe_sender| is required when constructing a BluetoothDispatcher. |
| 41 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance( |
| 42 ThreadSafeSender* thread_safe_sender); |
| 43 |
| 44 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener. |
| 45 bool Send(IPC::Message* msg); |
| 46 void OnMessageReceived(const IPC::Message& msg); |
| 47 |
| 48 // Corresponding to WebBluetoothImpl methods. |
| 49 // TODO(scheib): Remove old void version after crrev.com/715613005 lands. |
| 50 void requestDevice( |
| 51 blink::WebCallbacks<void, blink::WebBluetoothError>* callbacks); |
| 52 void requestDevice(blink::WebCallbacks<blink::WebBluetoothDevice, |
| 53 blink::WebBluetoothError>* callbacks); |
| 54 void SetBluetoothMockDataSetForTesting(const std::string& name); |
| 55 |
| 56 // WorkerTaskRunner::Observer implementation. |
| 57 void OnWorkerRunLoopStopped() override; |
| 58 |
| 59 private: |
| 60 // IPC Handlers, see definitions in bluetooth_messages.h. |
| 61 void OnRequestDeviceSuccess(int thread_id, |
| 62 int request_id, |
| 63 const std::string& device_instance_id); |
| 64 void OnRequestDeviceError(int thread_id, |
| 65 int request_id, |
| 66 BluetoothError error_type); |
| 67 |
| 68 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 69 |
| 70 // Tracks requests sent to browser to match replies with callbacks. |
| 71 // Owns callback objects. |
| 72 // TODO(scheib): Remove old void version after crrev.com/715613005 lands. |
| 73 IDMap<blink::WebCallbacks<void, blink::WebBluetoothError>, IDMapOwnPointer> |
| 74 pending_requests_old_; |
| 75 IDMap< |
| 76 blink::WebCallbacks<blink::WebBluetoothDevice, blink::WebBluetoothError>, |
| 77 IDMapOwnPointer> pending_requests_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); |
| 80 }; |
| 81 |
| 82 } // namespace content |
| 83 |
| 84 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ |
| OLD | NEW |