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