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