| 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/sockets_udp/udp_socket_event_dispatcher.h" | 5 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "extensions/browser/api/socket/udp_socket.h" | 10 #include "extensions/browser/api/socket/udp_socket.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // Post a task to delay the read until the socket is available, as | 129 // Post a task to delay the read until the socket is available, as |
| 130 // calling StartReceive at this point would error with ERR_IO_PENDING. | 130 // calling StartReceive at this point would error with ERR_IO_PENDING. |
| 131 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
| 132 params.thread_id, | 132 params.thread_id, |
| 133 FROM_HERE, | 133 FROM_HERE, |
| 134 base::Bind(&UDPSocketEventDispatcher::StartReceive, params)); | 134 base::Bind(&UDPSocketEventDispatcher::StartReceive, params)); |
| 135 } else if (bytes_read == net::ERR_IO_PENDING) { | 135 } else if (bytes_read == net::ERR_IO_PENDING) { |
| 136 // This happens when resuming a socket which already had an | 136 // This happens when resuming a socket which already had an |
| 137 // active "recv" callback. | 137 // active "recv" callback. |
| 138 } else if (bytes_read == net::ERR_CONNECTION_CLOSED) { |
| 139 // This happens when the socket closes, which is expected since we |
| 140 // continually add a receive listener in the success block above. |
| 138 } else { | 141 } else { |
| 139 // Dispatch "onReceiveError" event but don't start another read to avoid | 142 // Dispatch "onReceiveError" event but don't start another read to avoid |
| 140 // potential infinite reads if we have a persistent network error. | 143 // potential infinite reads if we have a persistent network error. |
| 141 sockets_udp::ReceiveErrorInfo receive_error_info; | 144 sockets_udp::ReceiveErrorInfo receive_error_info; |
| 142 receive_error_info.socket_id = params.socket_id; | 145 receive_error_info.socket_id = params.socket_id; |
| 143 receive_error_info.result_code = bytes_read; | 146 receive_error_info.result_code = bytes_read; |
| 144 std::unique_ptr<base::ListValue> args = | 147 std::unique_ptr<base::ListValue> args = |
| 145 sockets_udp::OnReceiveError::Create(receive_error_info); | 148 sockets_udp::OnReceiveError::Create(receive_error_info); |
| 146 std::unique_ptr<Event> event( | 149 std::unique_ptr<Event> event( |
| 147 new Event(events::SOCKETS_UDP_ON_RECEIVE_ERROR, | 150 new Event(events::SOCKETS_UDP_ON_RECEIVE_ERROR, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 reinterpret_cast<content::BrowserContext*>(browser_context_id); | 182 reinterpret_cast<content::BrowserContext*>(browser_context_id); |
| 180 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) | 183 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) |
| 181 return; | 184 return; |
| 182 EventRouter* router = EventRouter::Get(context); | 185 EventRouter* router = EventRouter::Get(context); |
| 183 if (router) | 186 if (router) |
| 184 router->DispatchEventToExtension(extension_id, std::move(event)); | 187 router->DispatchEventToExtension(extension_id, std::move(event)); |
| 185 } | 188 } |
| 186 | 189 |
| 187 } // namespace api | 190 } // namespace api |
| 188 } // namespace extensions | 191 } // namespace extensions |
| OLD | NEW |