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 "chrome/common/extensions/api/bluetooth.h" | 12 #include "chrome/common/extensions/api/bluetooth.h" |
13 #include "device/bluetooth/bluetooth_adapter.h" | 13 #include "device/bluetooth/bluetooth_adapter.h" |
14 #include "device/bluetooth/bluetooth_adapter_factory.h" | |
14 #include "device/bluetooth/bluetooth_socket.h" | 15 #include "device/bluetooth/bluetooth_socket.h" |
15 | 16 |
16 class Profile; | 17 class Profile; |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
20 class ExtensionBluetoothEventRouter | 21 class ExtensionBluetoothEventRouter |
21 : public device::BluetoothAdapter::Observer { | 22 : public device::BluetoothAdapter::Observer { |
22 public: | 23 public: |
23 explicit ExtensionBluetoothEventRouter(Profile* profile); | 24 explicit ExtensionBluetoothEventRouter(Profile* profile); |
24 virtual ~ExtensionBluetoothEventRouter(); | 25 virtual ~ExtensionBluetoothEventRouter(); |
25 | 26 |
26 // GetAdapter will return NULL if the bluetooth adapter is not | 27 // |callback| will not be run if the bluetooth is not supported in the current |
bryeung
2013/01/08 22:24:27
This seems like a frustrating API. Can we have th
youngki
2013/01/09 15:12:03
Done.
| |
27 // supported in the current platform. | 28 // platform. |
28 scoped_refptr<device::BluetoothAdapter> GetAdapter(); | 29 void RunCallbackOnAdapterReady( |
30 const device::BluetoothAdapterFactory::AdapterCallback& callback); | |
29 | 31 |
30 // Called when a bluetooth event listener is added. | 32 // Called when a bluetooth event listener is added. |
31 void OnListenerAdded(); | 33 void OnListenerAdded(); |
32 | 34 |
33 // Called when a bluetooth event listener is removed. | 35 // Called when a bluetooth event listener is removed. |
34 void OnListenerRemoved(); | 36 void OnListenerRemoved(); |
35 | 37 |
36 // Register the BluetoothSocket |socket| for use by the extensions system. | 38 // Register the BluetoothSocket |socket| for use by the extensions system. |
37 // This class will hold onto the socket for its lifetime, or until | 39 // This class will hold onto the socket for its lifetime, or until |
38 // ReleaseSocket is called for the socket. Returns an id for the socket. | 40 // ReleaseSocket is called for the socket. Returns an id for the socket. |
(...skipping 28 matching lines...) Expand all Loading... | |
67 bool discovering) OVERRIDE; | 69 bool discovering) OVERRIDE; |
68 virtual void DeviceAdded(device::BluetoothAdapter* adapter, | 70 virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
69 device::BluetoothDevice* device) OVERRIDE; | 71 device::BluetoothDevice* device) OVERRIDE; |
70 | 72 |
71 // Exposed for testing. | 73 // Exposed for testing. |
72 void SetAdapterForTest(device::BluetoothAdapter* adapter) { | 74 void SetAdapterForTest(device::BluetoothAdapter* adapter) { |
73 adapter_ = adapter; | 75 adapter_ = adapter; |
74 } | 76 } |
75 private: | 77 private: |
76 void InitializeAdapterIfNeeded(); | 78 void InitializeAdapterIfNeeded(); |
79 bool InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
77 void MaybeReleaseAdapter(); | 80 void MaybeReleaseAdapter(); |
78 void DispatchAdapterStateEvent(); | 81 void DispatchAdapterStateEvent(); |
79 | 82 |
80 bool send_discovery_events_; | 83 bool send_discovery_events_; |
81 bool responsible_for_discovery_; | 84 bool responsible_for_discovery_; |
82 | 85 |
83 Profile* profile_; | 86 Profile* profile_; |
84 scoped_refptr<device::BluetoothAdapter> adapter_; | 87 scoped_refptr<device::BluetoothAdapter> adapter_; |
85 | 88 |
86 int num_event_listeners_; | 89 int num_event_listeners_; |
87 | 90 |
88 // The next id to use for referring to a BluetoothSocket. We avoid using | 91 // The next id to use for referring to a BluetoothSocket. We avoid using |
89 // the fd of the socket because we don't want to leak that information to | 92 // the fd of the socket because we don't want to leak that information to |
90 // the extension javascript. | 93 // the extension javascript. |
91 int next_socket_id_; | 94 int next_socket_id_; |
92 | 95 |
93 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; | 96 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; |
94 SocketMap socket_map_; | 97 SocketMap socket_map_; |
95 | 98 |
96 typedef ScopedVector<extensions::api::bluetooth::Device> | 99 typedef ScopedVector<extensions::api::bluetooth::Device> |
97 DeviceList; | 100 DeviceList; |
98 DeviceList discovered_devices_; | 101 DeviceList discovered_devices_; |
99 | 102 |
100 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); | 103 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); |
101 }; | 104 }; |
102 | 105 |
103 } // namespace extensions | 106 } // namespace extensions |
104 | 107 |
105 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
OLD | NEW |