| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "extensions/browser/api/socket/udp_socket.h" | 8 #include "extensions/browser/api/socket/udp_socket.h" |
| 9 #include "extensions/browser/event_router.h" | 9 #include "extensions/browser/event_router.h" |
| 10 #include "extensions/browser/extensions_browser_client.h" | 10 #include "extensions/browser/extensions_browser_client.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 buffer_size, | 93 buffer_size, |
| 94 base::Bind(&UDPSocketEventDispatcher::ReceiveCallback, params)); | 94 base::Bind(&UDPSocketEventDispatcher::ReceiveCallback, params)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 /* static */ | 97 /* static */ |
| 98 void UDPSocketEventDispatcher::ReceiveCallback( | 98 void UDPSocketEventDispatcher::ReceiveCallback( |
| 99 const ReceiveParams& params, | 99 const ReceiveParams& params, |
| 100 int bytes_read, | 100 int bytes_read, |
| 101 scoped_refptr<net::IOBuffer> io_buffer, | 101 scoped_refptr<net::IOBuffer> io_buffer, |
| 102 const std::string& address, | 102 const std::string& address, |
| 103 int port) { | 103 uint16 port) { |
| 104 DCHECK_CURRENTLY_ON(params.thread_id); | 104 DCHECK_CURRENTLY_ON(params.thread_id); |
| 105 | 105 |
| 106 // If |bytes_read| == 0, the message contained no data. | 106 // If |bytes_read| == 0, the message contained no data. |
| 107 // If |bytes_read| < 0, there was a network error, and |bytes_read| is a value | 107 // If |bytes_read| < 0, there was a network error, and |bytes_read| is a value |
| 108 // from "net::ERR_". | 108 // from "net::ERR_". |
| 109 | 109 |
| 110 if (bytes_read >= 0) { | 110 if (bytes_read >= 0) { |
| 111 // Dispatch "onReceive" event. | 111 // Dispatch "onReceive" event. |
| 112 sockets_udp::ReceiveInfo receive_info; | 112 sockets_udp::ReceiveInfo receive_info; |
| 113 receive_info.socket_id = params.socket_id; | 113 receive_info.socket_id = params.socket_id; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 reinterpret_cast<content::BrowserContext*>(browser_context_id); | 174 reinterpret_cast<content::BrowserContext*>(browser_context_id); |
| 175 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) | 175 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) |
| 176 return; | 176 return; |
| 177 EventRouter* router = EventRouter::Get(context); | 177 EventRouter* router = EventRouter::Get(context); |
| 178 if (router) | 178 if (router) |
| 179 router->DispatchEventToExtension(extension_id, event.Pass()); | 179 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace core_api | 182 } // namespace core_api |
| 183 } // namespace extensions | 183 } // namespace extensions |
| OLD | NEW |