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 EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 6 #define EXTENSIONS_BROWSER_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 17 matching lines...) Expand all Loading... |
28 namespace device { | 28 namespace device { |
29 | 29 |
30 class BluetoothDevice; | 30 class BluetoothDevice; |
31 class BluetoothDiscoverySession; | 31 class BluetoothDiscoverySession; |
32 | 32 |
33 } // namespace device | 33 } // namespace device |
34 | 34 |
35 namespace extensions { | 35 namespace extensions { |
36 class BluetoothApiPairingDelegate; | 36 class BluetoothApiPairingDelegate; |
37 class ExtensionRegistry; | 37 class ExtensionRegistry; |
| 38 struct EventListenerInfo; |
38 | 39 |
39 class BluetoothEventRouter : public device::BluetoothAdapter::Observer, | 40 class BluetoothEventRouter : public device::BluetoothAdapter::Observer, |
40 public content::NotificationObserver, | 41 public content::NotificationObserver, |
41 public ExtensionRegistryObserver { | 42 public ExtensionRegistryObserver { |
42 public: | 43 public: |
43 explicit BluetoothEventRouter(content::BrowserContext* context); | 44 explicit BluetoothEventRouter(content::BrowserContext* context); |
44 ~BluetoothEventRouter() override; | 45 ~BluetoothEventRouter() override; |
45 | 46 |
46 // Returns true if adapter_ has been initialized for testing or bluetooth | 47 // Returns true if adapter_ has been initialized for testing or bluetooth |
47 // adapter is available for the current platform. | 48 // adapter is available for the current platform. |
(...skipping 26 matching lines...) Expand all Loading... |
74 // Callback is called, if the filter was successfully updated. | 75 // Callback is called, if the filter was successfully updated. |
75 // |error_callback| is called, if filter update failed. | 76 // |error_callback| is called, if filter update failed. |
76 void SetDiscoveryFilter( | 77 void SetDiscoveryFilter( |
77 std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter, | 78 std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter, |
78 device::BluetoothAdapter* adapter, | 79 device::BluetoothAdapter* adapter, |
79 const std::string& extension_id, | 80 const std::string& extension_id, |
80 const base::Closure& callback, | 81 const base::Closure& callback, |
81 const base::Closure& error_callback); | 82 const base::Closure& error_callback); |
82 | 83 |
83 // Called when a bluetooth event listener is added. | 84 // Called when a bluetooth event listener is added. |
84 void OnListenerAdded(); | 85 void OnListenerAdded(const EventListenerInfo& details); |
85 | 86 |
86 // Called when a bluetooth event listener is removed. | 87 // Called when a bluetooth event listener is removed. |
87 void OnListenerRemoved(); | 88 void OnListenerRemoved(const EventListenerInfo& details); |
88 | 89 |
89 // Adds a pairing delegate for an extension. | 90 // Adds a pairing delegate for an extension. |
90 void AddPairingDelegate(const std::string& extension_id); | 91 void AddPairingDelegate(const std::string& extension_id); |
91 | 92 |
92 // Removes the pairing delegate for an extension. | 93 // Removes the pairing delegate for an extension. |
93 void RemovePairingDelegate(const std::string& extension_id); | 94 void RemovePairingDelegate(const std::string& extension_id); |
94 | 95 |
95 // Returns the pairing delegate for an extension or NULL if it doesn't have a | 96 // Returns the pairing delegate for an extension or NULL if it doesn't have a |
96 // pairing delegate. | 97 // pairing delegate. |
97 BluetoothApiPairingDelegate* GetPairingDelegate( | 98 BluetoothApiPairingDelegate* GetPairingDelegate( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const std::string& extension_id, | 153 const std::string& extension_id, |
153 const base::Closure& callback, | 154 const base::Closure& callback, |
154 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); | 155 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); |
155 | 156 |
156 void OnSetDiscoveryFilter(const std::string& extension_id, | 157 void OnSetDiscoveryFilter(const std::string& extension_id, |
157 const base::Closure& callback); | 158 const base::Closure& callback); |
158 | 159 |
159 content::BrowserContext* browser_context_; | 160 content::BrowserContext* browser_context_; |
160 scoped_refptr<device::BluetoothAdapter> adapter_; | 161 scoped_refptr<device::BluetoothAdapter> adapter_; |
161 | 162 |
162 int num_event_listeners_; | 163 // Map of listener id -> listener count. |
| 164 std::map<std::string, int> event_listener_count_; |
163 | 165 |
164 // A map that maps extension ids to BluetoothDiscoverySession pointers. | 166 // A map that maps extension ids to BluetoothDiscoverySession pointers. |
165 typedef std::map<std::string, device::BluetoothDiscoverySession*> | 167 typedef std::map<std::string, device::BluetoothDiscoverySession*> |
166 DiscoverySessionMap; | 168 DiscoverySessionMap; |
167 DiscoverySessionMap discovery_session_map_; | 169 DiscoverySessionMap discovery_session_map_; |
168 | 170 |
169 typedef std::map<std::string, device::BluetoothDiscoveryFilter*> | 171 typedef std::map<std::string, device::BluetoothDiscoveryFilter*> |
170 PreSetFilterMap; | 172 PreSetFilterMap; |
171 | 173 |
172 // Maps an extension id to it's pre-set discovery filter. | 174 // Maps an extension id to it's pre-set discovery filter. |
(...skipping 10 matching lines...) Expand all Loading... |
183 extension_registry_observer_; | 185 extension_registry_observer_; |
184 | 186 |
185 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; | 187 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; |
186 | 188 |
187 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); | 189 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); |
188 }; | 190 }; |
189 | 191 |
190 } // namespace extensions | 192 } // namespace extensions |
191 | 193 |
192 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 194 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
OLD | NEW |