Give names to all utility processes.
[chromium-blink-merge.git] / content / child / bluetooth / bluetooth_dispatcher.h
blob8f3476af9ad9f2a7d388c91bdce27e7709291261
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/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 SetBluetoothMockDataSetForTesting(const std::string& name);
53 // WorkerTaskRunner::Observer implementation.
54 void OnWorkerRunLoopStopped() override;
56 private:
57 // IPC Handlers, see definitions in bluetooth_messages.h.
58 void OnRequestDeviceSuccess(int thread_id,
59 int request_id,
60 const BluetoothDevice& device);
61 void OnRequestDeviceError(int thread_id,
62 int request_id,
63 BluetoothError error_type);
65 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
67 // Tracks requests sent to browser to match replies with callbacks.
68 // Owns callback objects.
69 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer>
70 pending_requests_;
72 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher);
75 } // namespace content
77 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_