| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 explicit BluetoothEventRouter(content::BrowserContext* context); | 42 explicit BluetoothEventRouter(content::BrowserContext* context); |
| 43 virtual ~BluetoothEventRouter(); | 43 virtual ~BluetoothEventRouter(); |
| 44 | 44 |
| 45 // Returns true if adapter_ has been initialized for testing or bluetooth | 45 // Returns true if adapter_ has been initialized for testing or bluetooth |
| 46 // adapter is available for the current platform. | 46 // adapter is available for the current platform. |
| 47 bool IsBluetoothSupported() const; | 47 bool IsBluetoothSupported() const; |
| 48 | 48 |
| 49 void GetAdapter( | 49 void GetAdapter( |
| 50 const device::BluetoothAdapterFactory::AdapterCallback& callback); | 50 const device::BluetoothAdapterFactory::AdapterCallback& callback); |
| 51 | 51 |
| 52 // Register the BluetoothSocket |socket| for use by the extensions system. |
| 53 // This class will hold onto the socket for its lifetime until |
| 54 // ReleaseSocket is called for the socket, or until the extension associated |
| 55 // with the socket is disabled/ reloaded. Returns an id for the socket. |
| 56 int RegisterSocket(const std::string& extension_id, |
| 57 scoped_refptr<device::BluetoothSocket> socket); |
| 58 |
| 59 // Release the BluetoothSocket corresponding to |id|. Returns true if |
| 60 // the socket was found and released, false otherwise. |
| 61 bool ReleaseSocket(int id); |
| 62 |
| 52 // Add the BluetoothProfile |bluetooth_profile| for use by the extension | 63 // Add the BluetoothProfile |bluetooth_profile| for use by the extension |
| 53 // system. This class will hold onto the profile until RemoveProfile is | 64 // system. This class will hold onto the profile until RemoveProfile is |
| 54 // called for the profile, or until the extension that added the profile | 65 // called for the profile, or until the extension that added the profile |
| 55 // is disabled/reloaded. | 66 // is disabled/reloaded. |
| 56 void AddProfile(const device::BluetoothUUID& uuid, | 67 void AddProfile(const device::BluetoothUUID& uuid, |
| 57 const std::string& extension_id, | 68 const std::string& extension_id, |
| 58 device::BluetoothProfile* bluetooth_profile); | 69 device::BluetoothProfile* bluetooth_profile); |
| 59 | 70 |
| 60 // Unregister the BluetoothProfile corersponding to |uuid| and release the | 71 // Unregister the BluetoothProfile corersponding to |uuid| and release the |
| 61 // object from this class. | 72 // object from this class. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 81 // extension. | 92 // extension. |
| 82 void StopDiscoverySession(device::BluetoothAdapter* adapter, | 93 void StopDiscoverySession(device::BluetoothAdapter* adapter, |
| 83 const std::string& extension_id, | 94 const std::string& extension_id, |
| 84 const base::Closure& callback, | 95 const base::Closure& callback, |
| 85 const base::Closure& error_callback); | 96 const base::Closure& error_callback); |
| 86 | 97 |
| 87 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL | 98 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL |
| 88 // if the BluetoothProfile with |uuid| does not exist. | 99 // if the BluetoothProfile with |uuid| does not exist. |
| 89 device::BluetoothProfile* GetProfile(const device::BluetoothUUID& uuid) const; | 100 device::BluetoothProfile* GetProfile(const device::BluetoothUUID& uuid) const; |
| 90 | 101 |
| 102 // Get the BluetoothSocket corresponding to |id|. |
| 103 scoped_refptr<device::BluetoothSocket> GetSocket(int id); |
| 104 |
| 105 // 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. |
| 107 void DispatchConnectionEvent(const std::string& extension_id, |
| 108 const device::BluetoothUUID& uuid, |
| 109 const device::BluetoothDevice* device, |
| 110 scoped_refptr<device::BluetoothSocket> socket); |
| 111 |
| 91 // Called when a bluetooth event listener is added. | 112 // Called when a bluetooth event listener is added. |
| 92 void OnListenerAdded(); | 113 void OnListenerAdded(); |
| 93 | 114 |
| 94 // Called when a bluetooth event listener is removed. | 115 // Called when a bluetooth event listener is removed. |
| 95 void OnListenerRemoved(); | 116 void OnListenerRemoved(); |
| 96 | 117 |
| 97 // Adds a pairing delegate for an extension. | 118 // Adds a pairing delegate for an extension. |
| 98 void AddPairingDelegate(const std::string& extension_id); | 119 void AddPairingDelegate(const std::string& extension_id); |
| 99 | 120 |
| 100 // Removes the pairing delegate for an extension. | 121 // Removes the pairing delegate for an extension. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void OnStartDiscoverySession( | 171 void OnStartDiscoverySession( |
| 151 const std::string& extension_id, | 172 const std::string& extension_id, |
| 152 const base::Closure& callback, | 173 const base::Closure& callback, |
| 153 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 174 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| 154 | 175 |
| 155 content::BrowserContext* browser_context_; | 176 content::BrowserContext* browser_context_; |
| 156 scoped_refptr<device::BluetoothAdapter> adapter_; | 177 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 157 | 178 |
| 158 int num_event_listeners_; | 179 int num_event_listeners_; |
| 159 | 180 |
| 181 // 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 |
| 183 // the extension javascript. |
| 184 int next_socket_id_; |
| 185 |
| 186 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; |
| 187 SocketMap socket_map_; |
| 188 |
| 160 // Maps uuids to a struct containing a Bluetooth profile and its | 189 // Maps uuids to a struct containing a Bluetooth profile and its |
| 161 // associated extension id. | 190 // associated extension id. |
| 162 typedef std::map<device::BluetoothUUID, ExtensionBluetoothProfileRecord> | 191 typedef std::map<device::BluetoothUUID, ExtensionBluetoothProfileRecord> |
| 163 BluetoothProfileMap; | 192 BluetoothProfileMap; |
| 164 BluetoothProfileMap bluetooth_profile_map_; | 193 BluetoothProfileMap bluetooth_profile_map_; |
| 165 | 194 |
| 166 // A map that maps extension ids to BluetoothDiscoverySession pointers. | 195 // A map that maps extension ids to BluetoothDiscoverySession pointers. |
| 167 typedef std::map<std::string, device::BluetoothDiscoverySession*> | 196 typedef std::map<std::string, device::BluetoothDiscoverySession*> |
| 168 DiscoverySessionMap; | 197 DiscoverySessionMap; |
| 169 DiscoverySessionMap discovery_session_map_; | 198 DiscoverySessionMap discovery_session_map_; |
| 170 | 199 |
| 171 // Maps an extension id to its pairing delegate. | 200 // Maps an extension id to its pairing delegate. |
| 172 typedef std::map<std::string, BluetoothApiPairingDelegate*> | 201 typedef std::map<std::string, BluetoothApiPairingDelegate*> |
| 173 PairingDelegateMap; | 202 PairingDelegateMap; |
| 174 PairingDelegateMap pairing_delegate_map_; | 203 PairingDelegateMap pairing_delegate_map_; |
| 175 | 204 |
| 176 content::NotificationRegistrar registrar_; | 205 content::NotificationRegistrar registrar_; |
| 177 | 206 |
| 178 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; | 207 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; |
| 179 | 208 |
| 180 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); | 209 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); |
| 181 }; | 210 }; |
| 182 | 211 |
| 183 } // namespace extensions | 212 } // namespace extensions |
| 184 | 213 |
| 185 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 214 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
| OLD | NEW |