OLD | NEW |
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 const base::Closure& callback, | 101 const base::Closure& callback, |
102 const base::Closure& error_callback); | 102 const base::Closure& error_callback); |
103 | 103 |
104 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL | 104 // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL |
105 // if the BluetoothProfile with |uuid| does not exist. | 105 // if the BluetoothProfile with |uuid| does not exist. |
106 device::BluetoothProfile* GetProfile(const std::string& uuid) const; | 106 device::BluetoothProfile* GetProfile(const std::string& uuid) const; |
107 | 107 |
108 // Get the BluetoothSocket corresponding to |id|. | 108 // Get the BluetoothSocket corresponding to |id|. |
109 scoped_refptr<device::BluetoothSocket> GetSocket(int id); | 109 scoped_refptr<device::BluetoothSocket> GetSocket(int id); |
110 | 110 |
111 // Dispatch an event that takes a device as a parameter to all renderers. | |
112 void DispatchDeviceEvent( | |
113 const std::string& event_name, | |
114 const extensions::api::bluetooth::Device& device); | |
115 | |
116 // Dispatch an event that takes a connection socket as a parameter to the | 111 // 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. | 112 // extension that registered the profile that the socket has connected to. |
118 void DispatchConnectionEvent(const std::string& extension_id, | 113 void DispatchConnectionEvent(const std::string& extension_id, |
119 const std::string& uuid, | 114 const std::string& uuid, |
120 const device::BluetoothDevice* device, | 115 const device::BluetoothDevice* device, |
121 scoped_refptr<device::BluetoothSocket> socket); | 116 scoped_refptr<device::BluetoothSocket> socket); |
122 | 117 |
123 // Override from device::BluetoothAdapter::Observer | 118 // Override from device::BluetoothAdapter::Observer |
124 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 119 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
125 bool present) OVERRIDE; | 120 bool present) OVERRIDE; |
126 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 121 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
127 bool has_power) OVERRIDE; | 122 bool has_power) OVERRIDE; |
128 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, | 123 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, |
129 bool discovering) OVERRIDE; | 124 bool discovering) OVERRIDE; |
130 virtual void DeviceAdded(device::BluetoothAdapter* adapter, | 125 virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
131 device::BluetoothDevice* device) OVERRIDE; | 126 device::BluetoothDevice* device) OVERRIDE; |
| 127 virtual void DeviceChanged(device::BluetoothAdapter* adapter, |
| 128 device::BluetoothDevice* device) OVERRIDE; |
| 129 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 130 device::BluetoothDevice* device) OVERRIDE; |
132 | 131 |
133 // Overridden from content::NotificationObserver | 132 // Overridden from content::NotificationObserver |
134 virtual void Observe(int type, | 133 virtual void Observe(int type, |
135 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
136 const content::NotificationDetails& details) OVERRIDE; | 135 const content::NotificationDetails& details) OVERRIDE; |
137 | 136 |
138 // Exposed for testing. | 137 // Exposed for testing. |
139 void SetAdapterForTest(device::BluetoothAdapter* adapter) { | 138 void SetAdapterForTest(device::BluetoothAdapter* adapter) { |
140 adapter_ = adapter; | 139 adapter_ = adapter; |
141 } | 140 } |
142 | 141 |
143 private: | 142 private: |
144 void InitializeAdapterIfNeeded(); | 143 void InitializeAdapterIfNeeded(); |
145 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | 144 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
146 void MaybeReleaseAdapter(); | 145 void MaybeReleaseAdapter(); |
147 void DispatchAdapterStateEvent(); | 146 void DispatchAdapterStateEvent(); |
| 147 void DispatchDeviceEvent(const std::string& event_name, |
| 148 device::BluetoothDevice* device); |
148 void CleanUpForExtension(const std::string& extension_id); | 149 void CleanUpForExtension(const std::string& extension_id); |
149 void OnStartDiscoverySession( | 150 void OnStartDiscoverySession( |
150 const std::string& extension_id, | 151 const std::string& extension_id, |
151 const base::Closure& callback, | 152 const base::Closure& callback, |
152 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 153 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
153 | 154 |
154 content::BrowserContext* browser_context_; | 155 content::BrowserContext* browser_context_; |
155 scoped_refptr<device::BluetoothAdapter> adapter_; | 156 scoped_refptr<device::BluetoothAdapter> adapter_; |
156 | 157 |
157 int num_event_listeners_; | 158 int num_event_listeners_; |
(...skipping 19 matching lines...) Expand all Loading... |
177 content::NotificationRegistrar registrar_; | 178 content::NotificationRegistrar registrar_; |
178 | 179 |
179 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; | 180 base::WeakPtrFactory<ExtensionBluetoothEventRouter> weak_ptr_factory_; |
180 | 181 |
181 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); | 182 DISALLOW_COPY_AND_ASSIGN(ExtensionBluetoothEventRouter); |
182 }; | 183 }; |
183 | 184 |
184 } // namespace extensions | 185 } // namespace extensions |
185 | 186 |
186 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ | 187 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_EVENT_ROUTER_H_ |
OLD | NEW |