OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatc
her.h" | 5 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatc
her.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "device/bluetooth/bluetooth_device.h" | 8 #include "device/bluetooth/bluetooth_device.h" |
9 #include "device/bluetooth/bluetooth_socket.h" | 9 #include "device/bluetooth/bluetooth_socket.h" |
10 #include "extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h" | 10 #include "extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 int bytes_read, | 187 int bytes_read, |
188 scoped_refptr<net::IOBuffer> io_buffer) { | 188 scoped_refptr<net::IOBuffer> io_buffer) { |
189 DCHECK(BrowserThread::CurrentlyOn(params.thread_id)); | 189 DCHECK(BrowserThread::CurrentlyOn(params.thread_id)); |
190 | 190 |
191 // Dispatch "onReceive" event. | 191 // Dispatch "onReceive" event. |
192 bluetooth_socket::ReceiveInfo receive_info; | 192 bluetooth_socket::ReceiveInfo receive_info; |
193 receive_info.socket_id = params.socket_id; | 193 receive_info.socket_id = params.socket_id; |
194 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read); | 194 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read); |
195 scoped_ptr<base::ListValue> args = | 195 scoped_ptr<base::ListValue> args = |
196 bluetooth_socket::OnReceive::Create(receive_info); | 196 bluetooth_socket::OnReceive::Create(receive_info); |
197 scoped_ptr<Event> event( | 197 scoped_ptr<Event> event(new Event( |
198 new Event(bluetooth_socket::OnReceive::kEventName, args.Pass())); | 198 events::UNKNOWN, bluetooth_socket::OnReceive::kEventName, args.Pass())); |
199 PostEvent(params, event.Pass()); | 199 PostEvent(params, event.Pass()); |
200 | 200 |
201 // Post a task to delay the read until the socket is available, as | 201 // Post a task to delay the read until the socket is available, as |
202 // calling StartReceive at this point would error with ERR_IO_PENDING. | 202 // calling StartReceive at this point would error with ERR_IO_PENDING. |
203 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
204 params.thread_id, | 204 params.thread_id, |
205 FROM_HERE, | 205 FROM_HERE, |
206 base::Bind(&BluetoothSocketEventDispatcher::StartReceive, params)); | 206 base::Bind(&BluetoothSocketEventDispatcher::StartReceive, params)); |
207 } | 207 } |
208 | 208 |
(...skipping 13 matching lines...) Expand all Loading... |
222 | 222 |
223 // Dispatch "onReceiveError" event but don't start another read to avoid | 223 // Dispatch "onReceiveError" event but don't start another read to avoid |
224 // potential infinite reads if we have a persistent network error. | 224 // potential infinite reads if we have a persistent network error. |
225 bluetooth_socket::ReceiveErrorInfo receive_error_info; | 225 bluetooth_socket::ReceiveErrorInfo receive_error_info; |
226 receive_error_info.socket_id = params.socket_id; | 226 receive_error_info.socket_id = params.socket_id; |
227 receive_error_info.error_message = error; | 227 receive_error_info.error_message = error; |
228 receive_error_info.error = MapReceiveErrorReason(error_reason); | 228 receive_error_info.error = MapReceiveErrorReason(error_reason); |
229 scoped_ptr<base::ListValue> args = | 229 scoped_ptr<base::ListValue> args = |
230 bluetooth_socket::OnReceiveError::Create(receive_error_info); | 230 bluetooth_socket::OnReceiveError::Create(receive_error_info); |
231 scoped_ptr<Event> event( | 231 scoped_ptr<Event> event( |
232 new Event(bluetooth_socket::OnReceiveError::kEventName, args.Pass())); | 232 new Event(events::UNKNOWN, bluetooth_socket::OnReceiveError::kEventName, |
| 233 args.Pass())); |
233 PostEvent(params, event.Pass()); | 234 PostEvent(params, event.Pass()); |
234 | 235 |
235 // Since we got an error, the socket is now "paused" until the application | 236 // Since we got an error, the socket is now "paused" until the application |
236 // "resumes" it. | 237 // "resumes" it. |
237 BluetoothApiSocket* socket = | 238 BluetoothApiSocket* socket = |
238 params.sockets->Get(params.extension_id, params.socket_id); | 239 params.sockets->Get(params.extension_id, params.socket_id); |
239 if (socket) { | 240 if (socket) { |
240 socket->set_paused(true); | 241 socket->set_paused(true); |
241 } | 242 } |
242 } | 243 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 device->GetAddress(), | 283 device->GetAddress(), |
283 server_api_socket->uuid()); | 284 server_api_socket->uuid()); |
284 int client_socket_id = params.sockets->Add(client_api_socket); | 285 int client_socket_id = params.sockets->Add(client_api_socket); |
285 | 286 |
286 // Dispatch "onAccept" event. | 287 // Dispatch "onAccept" event. |
287 bluetooth_socket::AcceptInfo accept_info; | 288 bluetooth_socket::AcceptInfo accept_info; |
288 accept_info.socket_id = params.socket_id; | 289 accept_info.socket_id = params.socket_id; |
289 accept_info.client_socket_id = client_socket_id; | 290 accept_info.client_socket_id = client_socket_id; |
290 scoped_ptr<base::ListValue> args = | 291 scoped_ptr<base::ListValue> args = |
291 bluetooth_socket::OnAccept::Create(accept_info); | 292 bluetooth_socket::OnAccept::Create(accept_info); |
292 scoped_ptr<Event> event( | 293 scoped_ptr<Event> event(new Event( |
293 new Event(bluetooth_socket::OnAccept::kEventName, args.Pass())); | 294 events::UNKNOWN, bluetooth_socket::OnAccept::kEventName, args.Pass())); |
294 PostEvent(params, event.Pass()); | 295 PostEvent(params, event.Pass()); |
295 | 296 |
296 // Post a task to delay the accept until the socket is available, as | 297 // Post a task to delay the accept until the socket is available, as |
297 // calling StartAccept at this point would error with ERR_IO_PENDING. | 298 // calling StartAccept at this point would error with ERR_IO_PENDING. |
298 BrowserThread::PostTask( | 299 BrowserThread::PostTask( |
299 params.thread_id, | 300 params.thread_id, |
300 FROM_HERE, | 301 FROM_HERE, |
301 base::Bind(&BluetoothSocketEventDispatcher::StartAccept, params)); | 302 base::Bind(&BluetoothSocketEventDispatcher::StartAccept, params)); |
302 } | 303 } |
303 | 304 |
(...skipping 12 matching lines...) Expand all Loading... |
316 } | 317 } |
317 | 318 |
318 // Dispatch "onAcceptError" event but don't start another accept to avoid | 319 // Dispatch "onAcceptError" event but don't start another accept to avoid |
319 // potential infinite accepts if we have a persistent network error. | 320 // potential infinite accepts if we have a persistent network error. |
320 bluetooth_socket::AcceptErrorInfo accept_error_info; | 321 bluetooth_socket::AcceptErrorInfo accept_error_info; |
321 accept_error_info.socket_id = params.socket_id; | 322 accept_error_info.socket_id = params.socket_id; |
322 accept_error_info.error_message = error; | 323 accept_error_info.error_message = error; |
323 accept_error_info.error = MapAcceptErrorReason(error_reason); | 324 accept_error_info.error = MapAcceptErrorReason(error_reason); |
324 scoped_ptr<base::ListValue> args = | 325 scoped_ptr<base::ListValue> args = |
325 bluetooth_socket::OnAcceptError::Create(accept_error_info); | 326 bluetooth_socket::OnAcceptError::Create(accept_error_info); |
326 scoped_ptr<Event> event( | 327 scoped_ptr<Event> event(new Event(events::UNKNOWN, |
327 new Event(bluetooth_socket::OnAcceptError::kEventName, args.Pass())); | 328 bluetooth_socket::OnAcceptError::kEventName, |
| 329 args.Pass())); |
328 PostEvent(params, event.Pass()); | 330 PostEvent(params, event.Pass()); |
329 | 331 |
330 // Since we got an error, the socket is now "paused" until the application | 332 // Since we got an error, the socket is now "paused" until the application |
331 // "resumes" it. | 333 // "resumes" it. |
332 BluetoothApiSocket* socket = | 334 BluetoothApiSocket* socket = |
333 params.sockets->Get(params.extension_id, params.socket_id); | 335 params.sockets->Get(params.extension_id, params.socket_id); |
334 if (socket) { | 336 if (socket) { |
335 socket->set_paused(true); | 337 socket->set_paused(true); |
336 } | 338 } |
337 } | 339 } |
(...skipping 24 matching lines...) Expand all Loading... |
362 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) | 364 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) |
363 return; | 365 return; |
364 | 366 |
365 EventRouter* router = EventRouter::Get(context); | 367 EventRouter* router = EventRouter::Get(context); |
366 if (router) | 368 if (router) |
367 router->DispatchEventToExtension(extension_id, event.Pass()); | 369 router->DispatchEventToExtension(extension_id, event.Pass()); |
368 } | 370 } |
369 | 371 |
370 } // namespace core_api | 372 } // namespace core_api |
371 } // namespace extensions | 373 } // namespace extensions |
OLD | NEW |