| 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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/common/extensions/api/bluetooth.h" | 13 #include "chrome/common/extensions/api/bluetooth.h" |
| 14 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 15 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 16 #include "device/bluetooth/bluetooth_socket.h" | 16 #include "device/bluetooth/bluetooth_socket.h" |
| 17 | 17 |
| 18 class Profile; | 18 class Profile; |
| 19 | 19 |
| 20 namespace device { |
| 21 |
| 22 class BluetoothDevice; |
| 23 class BluetoothProfile; |
| 24 |
| 25 } // namespace device |
| 26 |
| 20 namespace extensions { | 27 namespace extensions { |
| 21 | 28 |
| 22 class ExtensionBluetoothEventRouter | 29 class ExtensionBluetoothEventRouter |
| 23 : public device::BluetoothAdapter::Observer { | 30 : public device::BluetoothAdapter::Observer { |
| 24 public: | 31 public: |
| 25 explicit ExtensionBluetoothEventRouter(Profile* profile); | 32 explicit ExtensionBluetoothEventRouter(Profile* profile); |
| 26 virtual ~ExtensionBluetoothEventRouter(); | 33 virtual ~ExtensionBluetoothEventRouter(); |
| 27 | 34 |
| 28 // Returns true if adapter_ has been initialized for testing or bluetooth | 35 // Returns true if adapter_ has been initialized for testing or bluetooth |
| 29 // adapter is available for the current platform. | 36 // adapter is available for the current platform. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 | 47 |
| 41 // Register the BluetoothSocket |socket| for use by the extensions system. | 48 // Register the BluetoothSocket |socket| for use by the extensions system. |
| 42 // This class will hold onto the socket for its lifetime, or until | 49 // This class will hold onto the socket for its lifetime, or until |
| 43 // ReleaseSocket is called for the socket. Returns an id for the socket. | 50 // ReleaseSocket is called for the socket. Returns an id for the socket. |
| 44 int RegisterSocket(scoped_refptr<device::BluetoothSocket> socket); | 51 int RegisterSocket(scoped_refptr<device::BluetoothSocket> socket); |
| 45 | 52 |
| 46 // Release the BluetoothSocket corresponding to |id|. Returns true if | 53 // Release the BluetoothSocket corresponding to |id|. Returns true if |
| 47 // the socket was found and released, false otherwise. | 54 // the socket was found and released, false otherwise. |
| 48 bool ReleaseSocket(int id); | 55 bool ReleaseSocket(int id); |
| 49 | 56 |
| 57 // Add the BluetoothProfile |bluetooth_profile| for use by the extension |
| 58 // system. This class will hold onto the profile for its lifetime, or until |
| 59 // RemoveProfile is called for the profile. |
| 60 void AddProfile(const std::string& uuid, |
| 61 device::BluetoothProfile* bluetooth_profile); |
| 62 |
| 63 // Unregister the BluetoothProfile corersponding to |uuid| and release the |
| 64 // object from this class. |
| 65 void RemoveProfile(const std::string& uuid); |
| 66 |
| 67 // Returns true if the BluetoothProfile corresponding to |uuid| is already |
| 68 // registered. |
| 69 bool HasProfile(const std::string& uuid) const; |
| 70 |
| 50 // Get the BluetoothSocket corresponding to |id|. | 71 // Get the BluetoothSocket corresponding to |id|. |
| 51 scoped_refptr<device::BluetoothSocket> GetSocket(int id); | 72 scoped_refptr<device::BluetoothSocket> GetSocket(int id); |
| 52 | 73 |
| 53 // Sets whether this Profile is responsible for the discovering state of the | 74 // Sets whether this Profile is responsible for the discovering state of the |
| 54 // adapter. | 75 // adapter. |
| 55 void SetResponsibleForDiscovery(bool responsible); | 76 void SetResponsibleForDiscovery(bool responsible); |
| 56 bool IsResponsibleForDiscovery() const; | 77 bool IsResponsibleForDiscovery() const; |
| 57 | 78 |
| 58 // Sets whether or not DeviceAdded events will be dispatched to extensions. | 79 // Sets whether or not DeviceAdded events will be dispatched to extensions. |
| 59 void SetSendDiscoveryEvents(bool should_send); | 80 void SetSendDiscoveryEvents(bool should_send); |
| 60 | 81 |
| 61 // Dispatch an event that takes a device as a parameter to all renderers. | 82 // Dispatch an event that takes a device as a parameter to all renderers. |
| 62 void DispatchDeviceEvent( | 83 void DispatchDeviceEvent( |
| 63 const char* event_name, | 84 const char* event_name, |
| 64 const extensions::api::bluetooth::Device& device); | 85 const extensions::api::bluetooth::Device& device); |
| 65 | 86 |
| 87 // Dispatch an event that takes a connection socket as a parameter to the |
| 88 // extension that registered the profile that the socket has connected to. |
| 89 void DispatchConnectionEvent(const std::string& extension_id, |
| 90 const std::string& uuid, |
| 91 const device::BluetoothDevice* device, |
| 92 scoped_refptr<device::BluetoothSocket> socket); |
| 93 |
| 66 // Override from device::BluetoothAdapter::Observer | 94 // Override from device::BluetoothAdapter::Observer |
| 67 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 95 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
| 68 bool present) OVERRIDE; | 96 bool present) OVERRIDE; |
| 69 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 97 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
| 70 bool has_power) OVERRIDE; | 98 bool has_power) OVERRIDE; |
| 71 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, | 99 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, |
| 72 bool discovering) OVERRIDE; | 100 bool discovering) OVERRIDE; |
| 73 virtual void DeviceAdded(device::BluetoothAdapter* adapter, | 101 virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
| 74 device::BluetoothDevice* device) OVERRIDE; | 102 device::BluetoothDevice* device) OVERRIDE; |
| 75 | 103 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 // the extension javascript. | 124 // the extension javascript. |
| 97 int next_socket_id_; | 125 int next_socket_id_; |
| 98 | 126 |
| 99 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; | 127 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; |
| 100 SocketMap socket_map_; | 128 SocketMap socket_map_; |
| 101 | 129 |
| 102 typedef ScopedVector<extensions::api::bluetooth::Device> | 130 typedef ScopedVector<extensions::api::bluetooth::Device> |
| 103 DeviceList; | 131 DeviceList; |
| 104 DeviceList discovered_devices_; | 132 DeviceList discovered_devices_; |
| 105 | 133 |
| 134 // A map that maps uuids to the BluetoothProfile objects. |
| 135 typedef std::map<std::string, device::BluetoothProfile*> BluetoothProfileMap; |
| 136 BluetoothProfileMap bluetooth_profile_map_; |
| 137 |
| 106 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; | 138 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; |
| 107 | 139 |
| 108 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); | 140 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); |
| 109 }; | 141 }; |
| 110 | 142 |
| 111 } // namespace extensions | 143 } // namespace extensions |
| 112 | 144 |
| 113 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 145 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
| OLD | NEW |