chrome/browser/extensions: Remove use of MessageLoopProxy and deprecated MessageLoop...
[chromium-blink-merge.git] / content / browser / bluetooth / bluetooth_dispatcher_host.h
blobbd21686020a2766de0bc112530f90a71418f08c1
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_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/common/bluetooth/bluetooth_error.h"
11 #include "content/public/browser/browser_message_filter.h"
12 #include "device/bluetooth/bluetooth_adapter.h"
13 #include "device/bluetooth/bluetooth_gatt_connection.h"
15 namespace content {
17 // Dispatches and sends bluetooth related messages sent to/from a child
18 // process BluetoothDispatcher from/to the main browser process.
20 // Intended to be instantiated by the RenderProcessHost and installed as
21 // a filter on the channel. BrowserMessageFilter is refcounted and typically
22 // lives as long as it is installed on a channel.
24 // UI Thread Note:
25 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI
26 // thread because BluetoothAdapter and related objects live there.
27 class CONTENT_EXPORT BluetoothDispatcherHost final
28 : public BrowserMessageFilter,
29 public device::BluetoothAdapter::Observer {
30 public:
31 BluetoothDispatcherHost();
32 // BrowserMessageFilter:
33 void OnDestruct() const override;
34 void OverrideThreadForMessage(const IPC::Message& message,
35 BrowserThread::ID* thread) override;
36 bool OnMessageReceived(const IPC::Message& message) override;
38 void SetBluetoothAdapterForTesting(
39 scoped_refptr<device::BluetoothAdapter> mock_adapter);
41 protected:
42 ~BluetoothDispatcherHost() override;
44 private:
45 friend class base::DeleteHelper<BluetoothDispatcherHost>;
46 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
48 // Set |adapter_| to a BluetoothAdapter instance and register observers,
49 // releasing references to previous |adapter_|.
50 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter);
52 // IPC Handlers, see definitions in bluetooth_messages.h.
53 void OnRequestDevice(int thread_id, int request_id);
54 void OnConnectGATT(int thread_id, int request_id,
55 const std::string& device_instance_id);
56 void OnGetPrimaryService(int thread_id,
57 int request_id,
58 const std::string& device_instance_id,
59 const std::string& service_uuid);
61 // Callbacks for BluetoothAdapter::StartDiscoverySession.
62 void OnDiscoverySessionStarted(
63 int thread_id,
64 int request_id,
65 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
66 void OnDiscoverySessionStartedError(int thread_id, int request_id);
68 // Stop in progress discovery session.
69 void StopDiscoverySession(
70 int thread_id,
71 int request_id,
72 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
74 // Callbacks for BluetoothDiscoverySession::Stop.
75 void OnDiscoverySessionStopped(int thread_id, int request_id);
76 void OnDiscoverySessionStoppedError(int thread_id, int request_id);
78 // Callbacks for BluetoothDevice::CreateGattConnection
79 void OnGATTConnectionCreated(
80 int thread_id,
81 int request_id,
82 const std::string& device_instance_id,
83 scoped_ptr<device::BluetoothGattConnection> connection);
84 void OnCreateGATTConnectionError(
85 int thread_id,
86 int request_id,
87 const std::string& device_instance_id,
88 device::BluetoothDevice::ConnectErrorCode error_code);
90 // Callback for future BluetoothAdapter::ServicesDiscovered callback:
91 // For now we just post a delayed task.
92 // See: https://crbug.com/484504
93 void OnServicesDiscovered(int thread_id,
94 int request_id,
95 const std::string& device_instance_id,
96 const std::string& service_uuid);
98 // Defines how long to scan for and how long to discover services for.
99 int current_delay_time_;
101 // A BluetoothAdapter instance representing an adapter of the system.
102 scoped_refptr<device::BluetoothAdapter> adapter_;
104 // Must be last member, see base/memory/weak_ptr.h documentation
105 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_;
107 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost);
110 } // namespace content
112 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_