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