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 <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <queue> | |
12 | |
13 #include "base/id_map.h" | |
14 #include "base/macros.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "content/common/bluetooth/bluetooth_device.h" | |
17 #include "content/public/child/worker_thread.h" | |
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" | |
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError
.h" | |
20 | |
21 namespace base { | |
22 class MessageLoop; | |
23 class TaskRunner; | |
24 } | |
25 | |
26 namespace IPC { | |
27 class Message; | |
28 } | |
29 | |
30 namespace content { | |
31 class ThreadSafeSender; | |
32 | |
33 // Dispatcher for child process threads which communicates to the browser's | |
34 // BluetoothDispatcherHost. | |
35 // | |
36 // Instances are created for each thread as necessary by WebBluetoothImpl. | |
37 // | |
38 // Incoming IPC messages are received by the BluetoothMessageFilter and | |
39 // directed to the thread specific instance of this class. | |
40 // Outgoing messages come from WebBluetoothImpl. | |
41 class BluetoothDispatcher : public WorkerThread::Observer { | |
42 public: | |
43 explicit BluetoothDispatcher(ThreadSafeSender* sender); | |
44 ~BluetoothDispatcher() override; | |
45 | |
46 // Gets or Creates a BluetoothDispatcher for the current thread. | |
47 // |thread_safe_sender| is required when constructing a BluetoothDispatcher. | |
48 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance( | |
49 ThreadSafeSender* thread_safe_sender); | |
50 | |
51 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener. | |
52 bool Send(IPC::Message* msg); | |
53 void OnMessageReceived(const IPC::Message& msg); | |
54 | |
55 // Corresponding to WebBluetoothImpl methods. | |
56 void requestDevice(int frame_routing_id, | |
57 const blink::WebRequestDeviceOptions& options, | |
58 blink::WebBluetoothRequestDeviceCallbacks* callbacks); | |
59 | |
60 // WorkerThread::Observer implementation. | |
61 void WillStopCurrentWorkerThread() override; | |
62 | |
63 private: | |
64 // IPC Handlers, see definitions in bluetooth_messages.h. | |
65 void OnRequestDeviceSuccess(int thread_id, | |
66 int request_id, | |
67 const BluetoothDevice& device); | |
68 void OnRequestDeviceError(int thread_id, | |
69 int request_id, | |
70 blink::WebBluetoothError error); | |
71 | |
72 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
73 | |
74 // Tracks device requests sent to browser to match replies with callbacks. | |
75 // Owns callback objects. | |
76 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | |
77 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 |