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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused code. Created 6 years, 8 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
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_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/callback_forward.h" 10 #include "base/callback_forward.h"
(...skipping 30 matching lines...) Expand all
41 explicit BluetoothEventRouter(content::BrowserContext* context); 41 explicit BluetoothEventRouter(content::BrowserContext* context);
42 virtual ~BluetoothEventRouter(); 42 virtual ~BluetoothEventRouter();
43 43
44 // Returns true if adapter_ has been initialized for testing or bluetooth 44 // Returns true if adapter_ has been initialized for testing or bluetooth
45 // adapter is available for the current platform. 45 // adapter is available for the current platform.
46 bool IsBluetoothSupported() const; 46 bool IsBluetoothSupported() const;
47 47
48 void GetAdapter( 48 void GetAdapter(
49 const device::BluetoothAdapterFactory::AdapterCallback& callback); 49 const device::BluetoothAdapterFactory::AdapterCallback& callback);
50 50
51 // Register the BluetoothSocket |socket| for use by the extensions system.
52 // This class will hold onto the socket for its lifetime until
53 // ReleaseSocket is called for the socket, or until the extension associated
54 // with the socket is disabled/ reloaded. Returns an id for the socket.
55 int RegisterSocket(const std::string& extension_id,
56 scoped_refptr<device::BluetoothSocket> socket);
57
58 // Release the BluetoothSocket corresponding to |id|. Returns true if
59 // the socket was found and released, false otherwise.
60 bool ReleaseSocket(int id);
61
62 // Add the BluetoothProfile |bluetooth_profile| for use by the extension 51 // Add the BluetoothProfile |bluetooth_profile| for use by the extension
63 // system. This class will hold onto the profile until RemoveProfile is 52 // system. This class will hold onto the profile until RemoveProfile is
64 // called for the profile, or until the extension that added the profile 53 // called for the profile, or until the extension that added the profile
65 // is disabled/reloaded. 54 // is disabled/reloaded.
66 void AddProfile(const std::string& uuid, 55 void AddProfile(const std::string& uuid,
67 const std::string& extension_id, 56 const std::string& extension_id,
68 device::BluetoothProfile* bluetooth_profile); 57 device::BluetoothProfile* bluetooth_profile);
69 58
70 // Unregister the BluetoothProfile corersponding to |uuid| and release the 59 // Unregister the BluetoothProfile corersponding to |uuid| and release the
71 // object from this class. 60 // object from this class.
(...skipping 19 matching lines...) Expand all
91 // extension. 80 // extension.
92 void StopDiscoverySession(device::BluetoothAdapter* adapter, 81 void StopDiscoverySession(device::BluetoothAdapter* adapter,
93 const std::string& extension_id, 82 const std::string& extension_id,
94 const base::Closure& callback, 83 const base::Closure& callback,
95 const base::Closure& error_callback); 84 const base::Closure& error_callback);
96 85
97 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL 86 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL
98 // if the BluetoothProfile with |uuid| does not exist. 87 // if the BluetoothProfile with |uuid| does not exist.
99 device::BluetoothProfile* GetProfile(const std::string& uuid) const; 88 device::BluetoothProfile* GetProfile(const std::string& uuid) const;
100 89
101 // Get the BluetoothSocket corresponding to |id|.
102 scoped_refptr<device::BluetoothSocket> GetSocket(int id);
103
104 // Dispatch an event that takes a connection socket as a parameter to the
105 // extension that registered the profile that the socket has connected to.
106 void DispatchConnectionEvent(const std::string& extension_id,
107 const std::string& uuid,
108 const device::BluetoothDevice* device,
109 scoped_refptr<device::BluetoothSocket> socket);
110
111 // Called when a bluetooth event listener is added. 90 // Called when a bluetooth event listener is added.
112 void OnListenerAdded(); 91 void OnListenerAdded();
113 92
114 // Called when a bluetooth event listener is removed. 93 // Called when a bluetooth event listener is removed.
115 void OnListenerRemoved(); 94 void OnListenerRemoved();
116 95
117 // Adds a pairing delegate for an extension. 96 // Adds a pairing delegate for an extension.
118 void AddPairingDelegate(const std::string& extension_id); 97 void AddPairingDelegate(const std::string& extension_id);
119 98
120 // Removes the pairing delegate for an extension. 99 // Removes the pairing delegate for an extension.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 void OnStartDiscoverySession( 149 void OnStartDiscoverySession(
171 const std::string& extension_id, 150 const std::string& extension_id,
172 const base::Closure& callback, 151 const base::Closure& callback,
173 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); 152 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
174 153
175 content::BrowserContext* browser_context_; 154 content::BrowserContext* browser_context_;
176 scoped_refptr<device::BluetoothAdapter> adapter_; 155 scoped_refptr<device::BluetoothAdapter> adapter_;
177 156
178 int num_event_listeners_; 157 int num_event_listeners_;
179 158
180 // The next id to use for referring to a BluetoothSocket. We avoid using
181 // the fd of the socket because we don't want to leak that information to
182 // the extension javascript.
183 int next_socket_id_;
184
185 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap;
186 SocketMap socket_map_;
187
188 // Maps uuids to a struct containing a Bluetooth profile and its 159 // Maps uuids to a struct containing a Bluetooth profile and its
189 // associated extension id. 160 // associated extension id.
190 typedef std::map<std::string, ExtensionBluetoothProfileRecord> 161 typedef std::map<std::string, ExtensionBluetoothProfileRecord>
191 BluetoothProfileMap; 162 BluetoothProfileMap;
192 BluetoothProfileMap bluetooth_profile_map_; 163 BluetoothProfileMap bluetooth_profile_map_;
193 164
194 // A map that maps extension ids to BluetoothDiscoverySession pointers. 165 // A map that maps extension ids to BluetoothDiscoverySession pointers.
195 typedef std::map<std::string, device::BluetoothDiscoverySession*> 166 typedef std::map<std::string, device::BluetoothDiscoverySession*>
196 DiscoverySessionMap; 167 DiscoverySessionMap;
197 DiscoverySessionMap discovery_session_map_; 168 DiscoverySessionMap discovery_session_map_;
198 169
199 // Maps an extension id to its pairing delegate. 170 // Maps an extension id to its pairing delegate.
200 typedef std::map<std::string, BluetoothApiPairingDelegate*> 171 typedef std::map<std::string, BluetoothApiPairingDelegate*>
201 PairingDelegateMap; 172 PairingDelegateMap;
202 PairingDelegateMap pairing_delegate_map_; 173 PairingDelegateMap pairing_delegate_map_;
203 174
204 content::NotificationRegistrar registrar_; 175 content::NotificationRegistrar registrar_;
205 176
206 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_; 177 base::WeakPtrFactory<BluetoothEventRouter> weak_ptr_factory_;
207 178
208 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter); 179 DISALLOW_COPY_AND_ASSIGN(BluetoothEventRouter);
209 }; 180 };
210 181
211 } // namespace extensions 182 } // namespace extensions
212 183
213 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 184 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698