| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 114 receive_info.data = std::string(io_buffer->data(), bytes_read); | 114 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read); |
| 115 receive_info.remote_address = address; | 115 receive_info.remote_address = address; |
| 116 receive_info.remote_port = port; | 116 receive_info.remote_port = port; |
| 117 scoped_ptr<base::ListValue> args = | 117 scoped_ptr<base::ListValue> args = |
| 118 sockets_udp::OnReceive::Create(receive_info); | 118 sockets_udp::OnReceive::Create(receive_info); |
| 119 scoped_ptr<Event> event( | 119 scoped_ptr<Event> event( |
| 120 new Event(sockets_udp::OnReceive::kEventName, args.Pass())); | 120 new Event(sockets_udp::OnReceive::kEventName, args.Pass())); |
| 121 PostEvent(params, event.Pass()); | 121 PostEvent(params, event.Pass()); |
| 122 | 122 |
| 123 // Post a task to delay the read until the socket is available, as | 123 // Post a task to delay the read until the socket is available, as |
| 124 // calling StartReceive at this point would error with ERR_IO_PENDING. | 124 // calling StartReceive at this point would error with ERR_IO_PENDING. |
| (...skipping 49 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 |