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

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: Address code review feedback. Created 6 years, 9 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/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 void GetAdapter( 49 void GetAdapter(
50 const device::BluetoothAdapterFactory::AdapterCallback& callback); 50 const device::BluetoothAdapterFactory::AdapterCallback& callback);
51 51
52 // Called when a bluetooth event listener is added. 52 // Called when a bluetooth event listener is added.
53 void OnListenerAdded(); 53 void OnListenerAdded();
54 54
55 // Called when a bluetooth event listener is removed. 55 // Called when a bluetooth event listener is removed.
56 void OnListenerRemoved(); 56 void OnListenerRemoved();
57 57
58 // Register the BluetoothSocket |socket| for use by the extensions system.
59 // This class will hold onto the socket for its lifetime until
60 // ReleaseSocket is called for the socket, or until the extension associated
61 // with the socket is disabled/ reloaded. Returns an id for the socket.
62 int RegisterSocket(const std::string& extension_id,
63 scoped_refptr<device::BluetoothSocket> socket);
64
65 // Release the BluetoothSocket corresponding to |id|. Returns true if
66 // the socket was found and released, false otherwise.
67 bool ReleaseSocket(int id);
68
69 // Add the BluetoothProfile |bluetooth_profile| for use by the extension 58 // Add the BluetoothProfile |bluetooth_profile| for use by the extension
70 // system. This class will hold onto the profile until RemoveProfile is 59 // system. This class will hold onto the profile until RemoveProfile is
71 // called for the profile, or until the extension that added the profile 60 // called for the profile, or until the extension that added the profile
72 // is disabled/reloaded. 61 // is disabled/reloaded.
73 void AddProfile(const std::string& uuid, 62 void AddProfile(const std::string& uuid,
74 const std::string& extension_id, 63 const std::string& extension_id,
75 device::BluetoothProfile* bluetooth_profile); 64 device::BluetoothProfile* bluetooth_profile);
76 65
77 // Unregister the BluetoothProfile corersponding to |uuid| and release the 66 // Unregister the BluetoothProfile corersponding to |uuid| and release the
78 // object from this class. 67 // object from this class.
(...skipping 19 matching lines...) Expand all
98 // extension. 87 // extension.
99 void StopDiscoverySession(device::BluetoothAdapter* adapter, 88 void StopDiscoverySession(device::BluetoothAdapter* adapter,
100 const std::string& extension_id, 89 const std::string& extension_id,
101 const base::Closure& callback, 90 const base::Closure& callback,
102 const base::Closure& error_callback); 91 const base::Closure& error_callback);
103 92
104 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL 93 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL
105 // if the BluetoothProfile with |uuid| does not exist. 94 // if the BluetoothProfile with |uuid| does not exist.
106 device::BluetoothProfile* GetProfile(const std::string& uuid) const; 95 device::BluetoothProfile* GetProfile(const std::string& uuid) const;
107 96
108 // Get the BluetoothSocket corresponding to |id|.
109 scoped_refptr<device::BluetoothSocket> GetSocket(int id);
110
111 // Dispatch an event that takes a connection socket as a parameter to the
112 // extension that registered the profile that the socket has connected to.
113 void DispatchConnectionEvent(const std::string& extension_id,
114 const std::string& uuid,
115 const device::BluetoothDevice* device,
116 scoped_refptr<device::BluetoothSocket> socket);
117
118 // Override from device::BluetoothAdapter::Observer 97 // Override from device::BluetoothAdapter::Observer
119 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, 98 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter,
120 bool present) OVERRIDE; 99 bool present) OVERRIDE;
121 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, 100 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
122 bool has_power) OVERRIDE; 101 bool has_power) OVERRIDE;
123 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, 102 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter,
124 bool discovering) OVERRIDE; 103 bool discovering) OVERRIDE;
125 virtual void DeviceAdded(device::BluetoothAdapter* adapter, 104 virtual void DeviceAdded(device::BluetoothAdapter* adapter,
126 device::BluetoothDevice* device) OVERRIDE; 105 device::BluetoothDevice* device) OVERRIDE;
127 virtual void DeviceChanged(device::BluetoothAdapter* adapter, 106 virtual void DeviceChanged(device::BluetoothAdapter* adapter,
(...skipping 22 matching lines...) Expand all
150 void OnStartDiscoverySession( 129 void OnStartDiscoverySession(
151 const std::string& extension_id, 130 const std::string& extension_id,
152 const base::Closure& callback, 131 const base::Closure& callback,
153 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); 132 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
154 133
155 content::BrowserContext* browser_context_; 134 content::BrowserContext* browser_context_;
156 scoped_refptr<device::BluetoothAdapter> adapter_; 135 scoped_refptr<device::BluetoothAdapter> adapter_;
157 136
158 int num_event_listeners_; 137 int num_event_listeners_;
159 138
160 // The next id to use for referring to a BluetoothSocket. We avoid using
161 // the fd of the socket because we don't want to leak that information to
162 // the extension javascript.
163 int next_socket_id_;
164
165 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap;
166 SocketMap socket_map_;
167
168 // A map that maps uuids to ExtensionBluetoothProfileRecord. 139 // A map that maps uuids to ExtensionBluetoothProfileRecord.
169 typedef std::map<std::string, ExtensionBluetoothProfileRecord> 140 typedef std::map<std::string, ExtensionBluetoothProfileRecord>
170 BluetoothProfileMap; 141 BluetoothProfileMap;
171 BluetoothProfileMap bluetooth_profile_map_; 142 BluetoothProfileMap bluetooth_profile_map_;
172 143
173 // A map that maps extension ids to BluetoothDiscoverySession pointers. 144 // A map that maps extension ids to BluetoothDiscoverySession pointers.
174 typedef std::map<std::string, device::BluetoothDiscoverySession*> 145 typedef std::map<std::string, device::BluetoothDiscoverySession*>
175 DiscoverySessionMap; 146 DiscoverySessionMap;
176 DiscoverySessionMap discovery_session_map_; 147 DiscoverySessionMap discovery_session_map_;
177 148
178 content::NotificationRegistrar registrar_; 149 content::NotificationRegistrar registrar_;
179 150
180 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; 151 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_;
181 152
182 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 153 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
183 }; 154 };
184 155
185 } // namespace extensions 156 } // namespace extensions
186 157
187 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 158 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698