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_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_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/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
13 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" | |
14 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/api/experimental_bluetooth.h" | 13 #include "chrome/common/extensions/api/experimental_bluetooth.h" |
| 14 #include "device/bluetooth/bluetooth_adapter.h" |
| 15 #include "device/bluetooth/bluetooth_socket.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace extensions { |
18 | 18 |
19 class ExtensionBluetoothEventRouter | 19 class ExtensionBluetoothEventRouter |
20 : public chromeos::BluetoothAdapter::Observer { | 20 : public device::BluetoothAdapter::Observer { |
21 public: | 21 public: |
22 explicit ExtensionBluetoothEventRouter(Profile* profile); | 22 explicit ExtensionBluetoothEventRouter(Profile* profile); |
23 virtual ~ExtensionBluetoothEventRouter(); | 23 virtual ~ExtensionBluetoothEventRouter(); |
24 | 24 |
25 const chromeos::BluetoothAdapter& adapter() const { return *adapter_.get(); } | 25 // adapter() will return NULL if the bluetooth adapter is not supported in the |
| 26 // current platform. |
| 27 const device::BluetoothAdapter* adapter() const { |
| 28 return adapter_.get(); |
| 29 } |
26 | 30 |
27 // GetMutableAdapter will never return NULL. | 31 // GetMutableAdapter will return NULL if the bluetooth adapter is not |
28 chromeos::BluetoothAdapter* GetMutableAdapter() { return adapter_.get(); } | 32 // supported in the current platform. |
| 33 device::BluetoothAdapter* GetMutableAdapter() { |
| 34 return adapter_.get(); |
| 35 } |
29 | 36 |
30 // Register the BluetoothSocket |socket| for use by the extensions system. | 37 // Register the BluetoothSocket |socket| for use by the extensions system. |
31 // This class will hold onto the socket for its lifetime, or until | 38 // This class will hold onto the socket for its lifetime, or until |
32 // ReleaseSocket is called for the socket. Returns an id for the socket. | 39 // ReleaseSocket is called for the socket. Returns an id for the socket. |
33 int RegisterSocket(scoped_refptr<BluetoothSocket> socket); | 40 int RegisterSocket(scoped_refptr<device::BluetoothSocket> socket); |
34 | 41 |
35 // Release the BluetoothSocket corresponding to |id|. Returns true if | 42 // Release the BluetoothSocket corresponding to |id|. Returns true if |
36 // the socket was found and released, false otherwise. | 43 // the socket was found and released, false otherwise. |
37 bool ReleaseSocket(int id); | 44 bool ReleaseSocket(int id); |
38 | 45 |
39 // Get the BluetoothSocket corresponding to |id|. | 46 // Get the BluetoothSocket corresponding to |id|. |
40 scoped_refptr<BluetoothSocket> GetSocket(int id); | 47 scoped_refptr<device::BluetoothSocket> GetSocket(int id); |
41 | 48 |
42 // Sets whether this Profile is responsible for the discovering state of the | 49 // Sets whether this Profile is responsible for the discovering state of the |
43 // adapter. | 50 // adapter. |
44 void SetResponsibleForDiscovery(bool responsible); | 51 void SetResponsibleForDiscovery(bool responsible); |
45 bool IsResponsibleForDiscovery() const; | 52 bool IsResponsibleForDiscovery() const; |
46 | 53 |
47 // Sets whether or not DeviceAdded events will be dispatched to extensions. | 54 // Sets whether or not DeviceAdded events will be dispatched to extensions. |
48 void SetSendDiscoveryEvents(bool should_send); | 55 void SetSendDiscoveryEvents(bool should_send); |
49 | 56 |
50 // Dispatch an event that takes a device as a parameter to all renderers. | 57 // Dispatch an event that takes a device as a parameter to all renderers. |
51 void DispatchDeviceEvent( | 58 void DispatchDeviceEvent( |
52 const char* event_name, | 59 const char* event_name, |
53 const extensions::api::experimental_bluetooth::Device& device); | 60 const extensions::api::experimental_bluetooth::Device& device); |
54 | 61 |
55 // Override from chromeos::BluetoothAdapter::Observer | 62 // Override from device::BluetoothAdapter::Observer |
56 virtual void AdapterPresentChanged(chromeos::BluetoothAdapter* adapter, | 63 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
57 bool present) OVERRIDE; | 64 bool present) OVERRIDE; |
58 virtual void AdapterPoweredChanged(chromeos::BluetoothAdapter* adapter, | 65 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
59 bool has_power) OVERRIDE; | 66 bool has_power) OVERRIDE; |
60 virtual void AdapterDiscoveringChanged(chromeos::BluetoothAdapter* adapter, | 67 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, |
61 bool discovering) OVERRIDE; | 68 bool discovering) OVERRIDE; |
62 virtual void DeviceAdded(chromeos::BluetoothAdapter* adapter, | 69 virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
63 chromeos::BluetoothDevice* device) OVERRIDE; | 70 device::BluetoothDevice* device) OVERRIDE; |
64 | 71 |
65 // Exposed for testing. | 72 // Exposed for testing. |
66 void SetAdapterForTest(chromeos::BluetoothAdapter* adapter) { | 73 void SetAdapterForTest(device::BluetoothAdapter* adapter) { |
67 adapter_ = adapter; | 74 adapter_ = adapter; |
68 } | 75 } |
69 private: | 76 private: |
70 void DispatchBooleanValueEvent(const char* event_name, bool value); | 77 void DispatchBooleanValueEvent(const char* event_name, bool value); |
71 | 78 |
72 bool send_discovery_events_; | 79 bool send_discovery_events_; |
73 bool responsible_for_discovery_; | 80 bool responsible_for_discovery_; |
74 | 81 |
75 Profile* profile_; | 82 Profile* profile_; |
76 scoped_refptr<chromeos::BluetoothAdapter> adapter_; | 83 scoped_refptr<device::BluetoothAdapter> adapter_; |
77 | 84 |
78 // The next id to use for referring to a BluetoothSocket. We avoid using | 85 // The next id to use for referring to a BluetoothSocket. We avoid using |
79 // the fd of the socket because we don't want to leak that information to | 86 // the fd of the socket because we don't want to leak that information to |
80 // the extension javascript. | 87 // the extension javascript. |
81 int next_socket_id_; | 88 int next_socket_id_; |
82 | 89 |
83 typedef std::map<int, scoped_refptr<BluetoothSocket> > SocketMap; | 90 typedef std::map<int, scoped_refptr<device::BluetoothSocket> > SocketMap; |
84 SocketMap socket_map_; | 91 SocketMap socket_map_; |
85 | 92 |
86 typedef ScopedVector<extensions::api::experimental_bluetooth::Device> | 93 typedef ScopedVector<extensions::api::experimental_bluetooth::Device> |
87 DeviceList; | 94 DeviceList; |
88 DeviceList discovered_devices_; | 95 DeviceList discovered_devices_; |
89 | 96 |
90 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); | 97 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); |
91 }; | 98 }; |
92 | 99 |
93 } // namespace chromeos | 100 } // namespace extensions |
94 | 101 |
95 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ | 102 #endif // CHROME_BROWSER_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ |
OLD | NEW |