OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "chrome/common/extensions/api/bluetooth.h" | 14 #include "chrome/common/extensions/api/bluetooth.h" |
15 #include "chrome/common/extensions/api/bluetooth_private.h" | 15 #include "chrome/common/extensions/api/bluetooth_private.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_adapter_factory.h" | 19 #include "device/bluetooth/bluetooth_adapter_factory.h" |
20 #include "device/bluetooth/bluetooth_socket.h" | 20 #include "device/bluetooth/bluetooth_socket.h" |
21 #include "device/bluetooth/bluetooth_uuid.h" | |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 class BrowserContext; | 23 class BrowserContext; |
25 } | 24 } |
26 | 25 |
27 namespace device { | 26 namespace device { |
28 | 27 |
29 class BluetoothDevice; | 28 class BluetoothDevice; |
30 class BluetoothDiscoverySession; | 29 class BluetoothDiscoverySession; |
31 class BluetoothProfile; | 30 class BluetoothProfile; |
(...skipping 25 matching lines...) Expand all Loading... |
57 scoped_refptr<device::BluetoothSocket> socket); | 56 scoped_refptr<device::BluetoothSocket> socket); |
58 | 57 |
59 // Release the BluetoothSocket corresponding to |id|. Returns true if | 58 // Release the BluetoothSocket corresponding to |id|. Returns true if |
60 // the socket was found and released, false otherwise. | 59 // the socket was found and released, false otherwise. |
61 bool ReleaseSocket(int id); | 60 bool ReleaseSocket(int id); |
62 | 61 |
63 // Add the BluetoothProfile |bluetooth_profile| for use by the extension | 62 // Add the BluetoothProfile |bluetooth_profile| for use by the extension |
64 // system. This class will hold onto the profile until RemoveProfile is | 63 // system. This class will hold onto the profile until RemoveProfile is |
65 // called for the profile, or until the extension that added the profile | 64 // called for the profile, or until the extension that added the profile |
66 // is disabled/reloaded. | 65 // is disabled/reloaded. |
67 void AddProfile(const device::BluetoothUUID& uuid, | 66 void AddProfile(const std::string& uuid, |
68 const std::string& extension_id, | 67 const std::string& extension_id, |
69 device::BluetoothProfile* bluetooth_profile); | 68 device::BluetoothProfile* bluetooth_profile); |
70 | 69 |
71 // Unregister the BluetoothProfile corersponding to |uuid| and release the | 70 // Unregister the BluetoothProfile corersponding to |uuid| and release the |
72 // object from this class. | 71 // object from this class. |
73 void RemoveProfile(const device::BluetoothUUID& uuid); | 72 void RemoveProfile(const std::string& uuid); |
74 | 73 |
75 // Returns true if the BluetoothProfile corresponding to |uuid| is already | 74 // Returns true if the BluetoothProfile corresponding to |uuid| is already |
76 // registered. | 75 // registered. |
77 bool HasProfile(const device::BluetoothUUID& uuid) const; | 76 bool HasProfile(const std::string& uuid) const; |
78 | 77 |
79 // Requests that a new device discovery session be initiated for extension | 78 // Requests that a new device discovery session be initiated for extension |
80 // with id |extension_id|. |callback| is called, if a session has been | 79 // with id |extension_id|. |callback| is called, if a session has been |
81 // initiated. |error_callback| is called, if the adapter failed to initiate | 80 // initiated. |error_callback| is called, if the adapter failed to initiate |
82 // the session or if an active session already exists for the extension. | 81 // the session or if an active session already exists for the extension. |
83 void StartDiscoverySession(device::BluetoothAdapter* adapter, | 82 void StartDiscoverySession(device::BluetoothAdapter* adapter, |
84 const std::string& extension_id, | 83 const std::string& extension_id, |
85 const base::Closure& callback, | 84 const base::Closure& callback, |
86 const base::Closure& error_callback); | 85 const base::Closure& error_callback); |
87 | 86 |
88 // Requests that the active discovery session that belongs to the extension | 87 // Requests that the active discovery session that belongs to the extension |
89 // with id |extension_id| be terminated. |callback| is called, if the session | 88 // with id |extension_id| be terminated. |callback| is called, if the session |
90 // successfully ended. |error_callback| is called, if the adapter failed to | 89 // successfully ended. |error_callback| is called, if the adapter failed to |
91 // terminate the session or if no active discovery session exists for the | 90 // terminate the session or if no active discovery session exists for the |
92 // extension. | 91 // extension. |
93 void StopDiscoverySession(device::BluetoothAdapter* adapter, | 92 void StopDiscoverySession(device::BluetoothAdapter* adapter, |
94 const std::string& extension_id, | 93 const std::string& extension_id, |
95 const base::Closure& callback, | 94 const base::Closure& callback, |
96 const base::Closure& error_callback); | 95 const base::Closure& error_callback); |
97 | 96 |
98 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL | 97 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL |
99 // if the BluetoothProfile with |uuid| does not exist. | 98 // if the BluetoothProfile with |uuid| does not exist. |
100 device::BluetoothProfile* GetProfile(const device::BluetoothUUID& uuid) const; | 99 device::BluetoothProfile* GetProfile(const std::string& uuid) const; |
101 | 100 |
102 // Get the BluetoothSocket corresponding to |id|. | 101 // Get the BluetoothSocket corresponding to |id|. |
103 scoped_refptr<device::BluetoothSocket> GetSocket(int id); | 102 scoped_refptr<device::BluetoothSocket> GetSocket(int id); |
104 | 103 |
105 // Dispatch an event that takes a connection socket as a parameter to the | 104 // Dispatch an event that takes a connection socket as a parameter to the |
106 // extension that registered the profile that the socket has connected to. | 105 // extension that registered the profile that the socket has connected to. |
107 void DispatchConnectionEvent(const std::string& extension_id, | 106 void DispatchConnectionEvent(const std::string& extension_id, |
108 const device::BluetoothUUID& uuid, | 107 const std::string& uuid, |
109 const device::BluetoothDevice* device, | 108 const device::BluetoothDevice* device, |
110 scoped_refptr<device::BluetoothSocket> socket); | 109 scoped_refptr<device::BluetoothSocket> socket); |
111 | 110 |
112 // Called when a bluetooth event listener is added. | 111 // Called when a bluetooth event listener is added. |
113 void OnListenerAdded(); | 112 void OnListenerAdded(); |
114 | 113 |
115 // Called when a bluetooth event listener is removed. | 114 // Called when a bluetooth event listener is removed. |
116 void OnListenerRemoved(); | 115 void OnListenerRemoved(); |
117 | 116 |
118 // Adds a pairing delegate for an extension. | 117 // Adds a pairing delegate for an extension. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // The next id to use for referring to a BluetoothSocket. We avoid using | 180 // The next id to use for referring to a BluetoothSocket. We avoid using |
182 // the fd of the socket because we don't want to leak that information to | 181 // the fd of the socket because we don't want to leak that information to |
183 // the extension javascript. | 182 // the extension javascript. |
184 int next_socket_id_; | 183 int next_socket_id_; |
185 | 184 |
186 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; | 185 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; |
187 SocketMap socket_map_; | 186 SocketMap socket_map_; |
188 | 187 |
189 // Maps uuids to a struct containing a Bluetooth profile and its | 188 // Maps uuids to a struct containing a Bluetooth profile and its |
190 // associated extension id. | 189 // associated extension id. |
191 typedef std::map<device::BluetoothUUID, ExtensionBluetoothProfileRecord> | 190 typedef std::map<std::string, ExtensionBluetoothProfileRecord> |
192 BluetoothProfileMap; | 191 BluetoothProfileMap; |
193 BluetoothProfileMap bluetooth_profile_map_; | 192 BluetoothProfileMap bluetooth_profile_map_; |
194 | 193 |
195 // A map that maps extension ids to BluetoothDiscoverySession pointers. | 194 // A map that maps extension ids to BluetoothDiscoverySession pointers. |
196 typedef std::map<std::string, device::BluetoothDiscoverySession*> | 195 typedef std::map<std::string, device::BluetoothDiscoverySession*> |
197 DiscoverySessionMap; | 196 DiscoverySessionMap; |
198 DiscoverySessionMap discovery_session_map_; | 197 DiscoverySessionMap discovery_session_map_; |
199 | 198 |
200 // Maps an extension id to its pairing delegate. | 199 // Maps an extension id to its pairing delegate. |
201 typedef std::map<std::string, BluetoothApiPairingDelegate*> | 200 typedef std::map<std::string, BluetoothApiPairingDelegate*> |
202 PairingDelegateMap; | 201 PairingDelegateMap; |
203 PairingDelegateMap pairing_delegate_map_; | 202 PairingDelegateMap pairing_delegate_map_; |
204 | 203 |
205 content::NotificationRegistrar registrar_; | 204 content::NotificationRegistrar registrar_; |
206 | 205 |
207 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; | 206 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; |
208 | 207 |
209 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); | 208 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); |
210 }; | 209 }; |
211 | 210 |
212 } // namespace extensions | 211 } // namespace extensions |
213 | 212 |
214 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 213 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
OLD | NEW |