Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/chromeos/extensions/bluetooth_event_router.h

Issue 10815072: Bluetooth API: improve discovery (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix licenses Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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 ScopedVector<extensions::api::experimental_bluetooth::Device>
82 DeviceList;
83 DeviceList discovered_devices_;
84
71 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 85 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
72 }; 86 };
73 87
74 } // namespace chromeos 88 } // namespace chromeos
75 89
76 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_ 90 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698