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_tcp/tcp_socket_event_dispatcher.h" | 5 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "extensions/browser/api/socket/tcp_socket.h" | 8 #include "extensions/browser/api/socket/tcp_socket.h" |
9 #include "extensions/browser/event_router.h" | 9 #include "extensions/browser/event_router.h" |
10 #include "extensions/browser/extension_system.h" | 10 #include "extensions/browser/extension_system.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // from "net::ERR_". | 121 // from "net::ERR_". |
122 | 122 |
123 if (bytes_read == 0) { | 123 if (bytes_read == 0) { |
124 bytes_read = net::ERR_CONNECTION_CLOSED; | 124 bytes_read = net::ERR_CONNECTION_CLOSED; |
125 } | 125 } |
126 | 126 |
127 if (bytes_read > 0) { | 127 if (bytes_read > 0) { |
128 // Dispatch "onReceive" event. | 128 // Dispatch "onReceive" event. |
129 sockets_tcp::ReceiveInfo receive_info; | 129 sockets_tcp::ReceiveInfo receive_info; |
130 receive_info.socket_id = params.socket_id; | 130 receive_info.socket_id = params.socket_id; |
131 receive_info.data = std::string(io_buffer->data(), bytes_read); | 131 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read); |
132 scoped_ptr<base::ListValue> args = | 132 scoped_ptr<base::ListValue> args = |
133 sockets_tcp::OnReceive::Create(receive_info); | 133 sockets_tcp::OnReceive::Create(receive_info); |
134 scoped_ptr<Event> event( | 134 scoped_ptr<Event> event( |
135 new Event(sockets_tcp::OnReceive::kEventName, args.Pass())); | 135 new Event(sockets_tcp::OnReceive::kEventName, args.Pass())); |
136 PostEvent(params, event.Pass()); | 136 PostEvent(params, event.Pass()); |
137 | 137 |
138 // Post a task to delay the read until the socket is available, as | 138 // Post a task to delay the read until the socket is available, as |
139 // calling StartReceive at this point would error with ERR_IO_PENDING. | 139 // calling StartReceive at this point would error with ERR_IO_PENDING. |
140 BrowserThread::PostTask( | 140 BrowserThread::PostTask( |
141 params.thread_id, | 141 params.thread_id, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) | 190 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) |
191 return; | 191 return; |
192 | 192 |
193 EventRouter* event_router = EventRouter::Get(context); | 193 EventRouter* event_router = EventRouter::Get(context); |
194 if (event_router) | 194 if (event_router) |
195 event_router->DispatchEventToExtension(extension_id, event.Pass()); | 195 event_router->DispatchEventToExtension(extension_id, event.Pass()); |
196 } | 196 } |
197 | 197 |
198 } // namespace core_api | 198 } // namespace core_api |
199 } // namespace extensions | 199 } // namespace extensions |
OLD | NEW |