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

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

Powered by Google App Engine
This is Rietveld 408576698