Fix link in German terms of service.
[chromium-blink-merge.git] / content / child / bluetooth / bluetooth_dispatcher.h
blob4bd4f250257e666a045ab51eca9a4baa528d6cd4
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_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
6 #define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
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 "content/common/bluetooth/bluetooth_error.h"
13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h"
15 namespace base {
16 class MessageLoop;
17 class TaskRunner;
20 namespace IPC {
21 class Message;
24 namespace content {
25 class ThreadSafeSender;
27 // Dispatcher for child process threads which communicates to the browser's
28 // BluetoothDispatcherHost.
30 // Instances are created for each thread as necessary by WebBluetoothImpl.
32 // Incoming IPC messages are received by the BluetoothMessageFilter and
33 // directed to the thread specific instance of this class.
34 // Outgoing messages come from WebBluetoothImpl.
35 class BluetoothDispatcher : public WorkerTaskRunner::Observer {
36 public:
37 explicit BluetoothDispatcher(ThreadSafeSender* sender);
38 ~BluetoothDispatcher() override;
40 // Gets or Creates a BluetoothDispatcher for the current thread.
41 // |thread_safe_sender| is required when constructing a BluetoothDispatcher.
42 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance(
43 ThreadSafeSender* thread_safe_sender);
45 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener.
46 bool Send(IPC::Message* msg);
47 void OnMessageReceived(const IPC::Message& msg);
49 // Corresponding to WebBluetoothImpl methods.
50 void requestDevice(blink::WebBluetoothRequestDeviceCallbacks* callbacks);
51 void connectGATT(const blink::WebString& device_instance_id,
52 blink::WebBluetoothConnectGATTCallbacks* callbacks);
54 // WorkerTaskRunner::Observer implementation.
55 void OnWorkerRunLoopStopped() override;
57 private:
58 // IPC Handlers, see definitions in bluetooth_messages.h.
59 void OnRequestDeviceSuccess(int thread_id,
60 int request_id,
61 const BluetoothDevice& device);
62 void OnRequestDeviceError(int thread_id,
63 int request_id,
64 BluetoothError error_type);
66 void OnConnectGATTSuccess(int thread_id,
67 int request_id,
68 const std::string& message);
70 void OnConnectGATTError(int thread_id,
71 int request_id,
72 BluetoothError error_type);
74 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
76 // Tracks device requests sent to browser to match replies with callbacks.
77 // Owns callback objects.
78 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer>
79 pending_requests_;
80 // Tracks requests to connect to a device.
81 // Owns callback objects.
82 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer>
83 pending_connect_requests_;
85 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher);
88 } // namespace content
90 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_