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

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

Issue 188663003: Revert 255262 "Migrate chrome.bluetooth API backend to use devic..." (Closed) Base URL: svn://svn.chromium.org/chrome/
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;
28 class BluetoothProfile; 27 class BluetoothProfile;
29 28
30 } // namespace device 29 } // namespace device
31 30
32 namespace extensions { 31 namespace extensions {
33 32
34 // Foward declarations of internal structs. 33 // Foward declarations of internal structs.
35 struct ExtensionBluetoothSocketRecord; 34 struct ExtensionBluetoothSocketRecord;
36 struct ExtensionBluetoothProfileRecord; 35 struct ExtensionBluetoothProfileRecord;
37 36
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 device::BluetoothProfile* bluetooth_profile); 74 device::BluetoothProfile* bluetooth_profile);
76 75
77 // Unregister the BluetoothProfile corersponding to |uuid| and release the 76 // Unregister the BluetoothProfile corersponding to |uuid| and release the
78 // object from this class. 77 // object from this class.
79 void RemoveProfile(const std::string& uuid); 78 void RemoveProfile(const std::string& uuid);
80 79
81 // Returns true if the BluetoothProfile corresponding to |uuid| is already 80 // Returns true if the BluetoothProfile corresponding to |uuid| is already
82 // registered. 81 // registered.
83 bool HasProfile(const std::string& uuid) const; 82 bool HasProfile(const std::string& uuid) const;
84 83
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
104 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL 84 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL
105 // if the BluetoothProfile with |uuid| does not exist. 85 // if the BluetoothProfile with |uuid| does not exist.
106 device::BluetoothProfile* GetProfile(const std::string& uuid) const; 86 device::BluetoothProfile* GetProfile(const std::string& uuid) const;
107 87
108 // Get the BluetoothSocket corresponding to |id|. 88 // Get the BluetoothSocket corresponding to |id|.
109 scoped_refptr<device::BluetoothSocket> GetSocket(int id); 89 scoped_refptr<device::BluetoothSocket> GetSocket(int id);
110 90
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
111 // Dispatch an event that takes a device as a parameter to all renderers. 99 // Dispatch an event that takes a device as a parameter to all renderers.
112 void DispatchDeviceEvent( 100 void DispatchDeviceEvent(
113 const std::string& event_name, 101 const std::string& event_name,
114 const extensions::api::bluetooth::Device& device); 102 const extensions::api::bluetooth::Device& device);
115 103
116 // Dispatch an event that takes a connection socket as a parameter to the 104 // Dispatch an event that takes a connection socket as a parameter to the
117 // extension that registered the profile that the socket has connected to. 105 // extension that registered the profile that the socket has connected to.
118 void DispatchConnectionEvent(const std::string& extension_id, 106 void DispatchConnectionEvent(const std::string& extension_id,
119 const std::string& uuid, 107 const std::string& uuid,
120 const device::BluetoothDevice* device, 108 const device::BluetoothDevice* device,
(...skipping 11 matching lines...) Expand all
132 120
133 // Overridden from content::NotificationObserver 121 // Overridden from content::NotificationObserver
134 virtual void Observe(int type, 122 virtual void Observe(int type,
135 const content::NotificationSource& source, 123 const content::NotificationSource& source,
136 const content::NotificationDetails& details) OVERRIDE; 124 const content::NotificationDetails& details) OVERRIDE;
137 125
138 // Exposed for testing. 126 // Exposed for testing.
139 void SetAdapterForTest(device::BluetoothAdapter* adapter) { 127 void SetAdapterForTest(device::BluetoothAdapter* adapter) {
140 adapter_ = adapter; 128 adapter_ = adapter;
141 } 129 }
142
143 private: 130 private:
144 void InitializeAdapterIfNeeded(); 131 void InitializeAdapterIfNeeded();
145 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); 132 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
146 void MaybeReleaseAdapter(); 133 void MaybeReleaseAdapter();
147 void DispatchAdapterStateEvent(); 134 void DispatchAdapterStateEvent();
148 void CleanUpForExtension(const std::string& extension_id); 135 void CleanUpForExtension(const std::string& extension_id);
149 void OnStartDiscoverySession( 136
150 const std::string& extension_id, 137 bool send_discovery_events_;
151 const base::Closure& callback, 138 bool responsible_for_discovery_;
152 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
153 139
154 content::BrowserContext* browser_context_; 140 content::BrowserContext* browser_context_;
155 scoped_refptr<device::BluetoothAdapter> adapter_; 141 scoped_refptr<device::BluetoothAdapter> adapter_;
156 142
157 int num_event_listeners_; 143 int num_event_listeners_;
158 144
159 // The next id to use for referring to a BluetoothSocket. We avoid using 145 // The next id to use for referring to a BluetoothSocket. We avoid using
160 // the fd of the socket because we don't want to leak that information to 146 // the fd of the socket because we don't want to leak that information to
161 // the extension javascript. 147 // the extension javascript.
162 int next_socket_id_; 148 int next_socket_id_;
163 149
164 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap; 150 typedef std::map<int, ExtensionBluetoothSocketRecord> SocketMap;
165 SocketMap socket_map_; 151 SocketMap socket_map_;
166 152
153 typedef ScopedVector<extensions::api::bluetooth::Device>
154 DeviceList;
155 DeviceList discovered_devices_;
156
167 // A map that maps uuids to ExtensionBluetoothProfileRecord. 157 // A map that maps uuids to ExtensionBluetoothProfileRecord.
168 typedef std::map<std::string, ExtensionBluetoothProfileRecord> 158 typedef std::map<std::string, ExtensionBluetoothProfileRecord>
169 BluetoothProfileMap; 159 BluetoothProfileMap;
170 BluetoothProfileMap bluetooth_profile_map_; 160 BluetoothProfileMap bluetooth_profile_map_;
171 161
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
177 content::NotificationRegistrar registrar_; 162 content::NotificationRegistrar registrar_;
178 163
179 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; 164 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_;
180 165
181 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); 166 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter);
182 }; 167 };
183 168
184 } // namespace extensions 169 } // namespace extensions
185 170
186 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ 171 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698