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

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

Issue 189463002: Migrate chrome.bluetooth API backend to use device::BluetoothDiscoverySession. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | 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_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"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "chrome/common/extensions/api/bluetooth.h" 13 #include "chrome/common/extensions/api/bluetooth.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 #include "device/bluetooth/bluetooth_adapter.h" 16 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_adapter_factory.h" 17 #include "device/bluetooth/bluetooth_adapter_factory.h"
18 #include "device/bluetooth/bluetooth_socket.h" 18 #include "device/bluetooth/bluetooth_socket.h"
19 19
20 namespace content { 20 namespace content {
21 class BrowserContext; 21 class BrowserContext;
22 } 22 }
23 23
24 namespace device { 24 namespace device {
25 25
26 class BluetoothDevice; 26 class BluetoothDevice;
27 class BluetoothDiscoverySession;
27 class BluetoothProfile; 28 class BluetoothProfile;
28 29
29 } // namespace device 30 } // namespace device
30 31
31 namespace extensions { 32 namespace extensions {
32 33
33 // Foward declarations of internal structs. 34 // Foward declarations of internal structs.
34 struct ExtensionBluetoothSocketRecord; 35 struct ExtensionBluetoothSocketRecord;
35 struct ExtensionBluetoothProfileRecord; 36 struct ExtensionBluetoothProfileRecord;
36 37
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 device::BluetoothProfile* bluetooth_profile); 75 device::BluetoothProfile* bluetooth_profile);
75 76
76 // Unregister the BluetoothProfile corersponding to |uuid| and release the 77 // Unregister the BluetoothProfile corersponding to |uuid| and release the
77 // object from this class. 78 // object from this class.
78 void RemoveProfile(const std::string& uuid); 79 void RemoveProfile(const std::string& uuid);
79 80
80 // Returns true if the BluetoothProfile corresponding to |uuid| is already 81 // Returns true if the BluetoothProfile corresponding to |uuid| is already
81 // registered. 82 // registered.
82 bool HasProfile(const std::string& uuid) const; 83 bool HasProfile(const std::string& uuid) const;
83 84
85 // Requests that a new device discovery session be initiated for extension
86 // with id |extension_id|. |callback| is called, if a session has been
87 // initiated. |error_callback| is called, if the adapter failed to initiate
88 // the session or if an active session already exists for the extension.
89 void StartDiscoverySession(device::BluetoothAdapter* adapter,
90 const std::string& extension_id,
91 const base::Closure& callback,
92 const base::Closure& error_callback);
93
94 // Requests that the active discovery session that belongs to the extension
95 // with id |extension_id| be terminated. |callback| is called, if the session
96 // successfully ended. |error_callback| is called, if the adapter failed to
97 // terminate the session or if no active discovery session exists for the
98 // extension.
99 void StopDiscoverySession(device::BluetoothAdapter* adapter,
100 const std::string& extension_id,
101 const base::Closure& callback,
102 const base::Closure& error_callback);
103
84 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL 104 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL
85 // if the BluetoothProfile with |uuid| does not exist. 105 // if the BluetoothProfile with |uuid| does not exist.
86 device::BluetoothProfile* GetProfile(const std::string& uuid) const; 106 device::BluetoothProfile* GetProfile(const std::string& uuid) const;
87 107
88 // Get the BluetoothSocket corresponding to |id|. 108 // Get the BluetoothSocket corresponding to |id|.
89 scoped_refptr<device::BluetoothSocket> GetSocket(int id); 109 scoped_refptr<device::BluetoothSocket> GetSocket(int id);
90 110
91 // Sets whether this Profile is responsible for the discovering state of the
92 // adapter.
93 void SetResponsibleForDiscovery(bool responsible);
94 bool IsResponsibleForDiscovery() const;
95
96 // Sets whether or not DeviceAdded events will be dispatched to extensions.
97 void SetSendDiscoveryEvents(bool should_send);
98
99 // Dispatch an event that takes a device as a parameter to all renderers. 111 // Dispatch an event that takes a device as a parameter to all renderers.
100 void DispatchDeviceEvent( 112 void DispatchDeviceEvent(
101 const std::string& event_name, 113 const std::string& event_name,
102 const extensions::api::bluetooth::Device& device); 114 const extensions::api::bluetooth::Device& device);
103 115
104 // Dispatch an event that takes a connection socket as a parameter to the 116 // 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. 117 // extension that registered the profile that the socket has connected to.
106 void DispatchConnectionEvent(const std::string& extension_id, 118 void DispatchConnectionEvent(const std::string& extension_id,
107 const std::string& uuid, 119 const std::string& uuid,
108 const device::BluetoothDevice* device, 120 const device::BluetoothDevice* device,
(...skipping 11 matching lines...) Expand all
120 132
121 // Overridden from content::NotificationObserver 133 // Overridden from content::NotificationObserver
122 virtual void Observe(int type, 134 virtual void Observe(int type,
123 const content::NotificationSource& source, 135 const content::NotificationSource& source,
124 const content::NotificationDetails& details) OVERRIDE; 136 const content::NotificationDetails& details) OVERRIDE;
125 137
126 // Exposed for testing. 138 // Exposed for testing.
127 void SetAdapterForTest(device::BluetoothAdapter* adapter) { 139 void SetAdapterForTest(device::BluetoothAdapter* adapter) {
128 adapter_ = adapter; 140 adapter_ = adapter;
129 } 141 }
142
130 private: 143 private:
131 void InitializeAdapterIfNeeded(); 144 void InitializeAdapterIfNeeded();
132 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); 145 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
133 void MaybeReleaseAdapter(); 146 void MaybeReleaseAdapter();
134 void DispatchAdapterStateEvent(); 147 void DispatchAdapterStateEvent();
135 void CleanUpForExtension(const std::string& extension_id); 148 void CleanUpForExtension(const std::string& extension_id);
136 149 void OnStartDiscoverySession(
137 bool send_discovery_events_; 150 const std::string& extension_id,
138 bool responsible_for_discovery_; 151 const base::Closure& callback,
152 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
139 153
140 content::BrowserContext* browser_context_; 154 content::BrowserContext* browser_context_;
141 scoped_refptr<device::BluetoothAdapter> adapter_; 155 scoped_refptr<device::BluetoothAdapter> adapter_;
142 156
143 int num_event_listeners_; 157 int num_event_listeners_;
144 158
145 // The next id to use for referring to a BluetoothSocket. We avoid using 159 // The next id to use for referring to a BluetoothSocket. We avoid using
146 // the fd of the socket because we don't want to leak that information to 160 // the fd of the socket because we don't want to leak that information to
147 // the extension javascript. 161 // the extension javascript.
148 int next_socket_id_; 162 int next_socket_id_;
149 163
150 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; 164 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap;
151 SocketMap socket_map_; 165 SocketMap socket_map_;
152 166
153 typedef ScopedVector<extensions::api::bluetooth::Device>
154 DeviceList;
155 DeviceList discovered_devices_;
156
157 // A map that maps uuids to ExtensionBluetoothProfileRecord. 167 // A map that maps uuids to ExtensionBluetoothProfileRecord.
158 typedef std::map<std::string, ExtensionBluetoothProfileRecord> 168 typedef std::map<std::string, ExtensionBluetoothProfileRecord>
159 BluetoothProfileMap; 169 BluetoothProfileMap;
160 BluetoothProfileMap bluetooth_profile_map_; 170 BluetoothProfileMap bluetooth_profile_map_;
161 171
172 // A map that maps extension ids to BluetoothDiscoverySession pointers.
173 typedef std::map<std::string, device::BluetoothDiscoverySession*>
174 DiscoverySessionMap;
175 DiscoverySessionMap discovery_session_map_;
176
162 content::NotificationRegistrar registrar_; 177 content::NotificationRegistrar registrar_;
163 178
164 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; 179 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_;
165 180
166 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 181 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
167 }; 182 };
168 183
169 } // namespace extensions 184 } // namespace extensions
170 185
171 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 186 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698