OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/socket/socket_api.h" | 5 #include "chrome/browser/extensions/api/socket/socket_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/extensions/api/api_resource_controller.h" | 8 #include "chrome/browser/extensions/api/api_resource_controller.h" |
9 #include "chrome/browser/extensions/api/socket/socket.h" | 9 #include "chrome/browser/extensions/api/socket/socket.h" |
10 #include "chrome/browser/extensions/api/socket/tcp_socket.h" | 10 #include "chrome/browser/extensions/api/socket/tcp_socket.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 void SocketReadFunction::OnCompleted(int bytes_read, | 167 void SocketReadFunction::OnCompleted(int bytes_read, |
168 scoped_refptr<net::IOBuffer> io_buffer) { | 168 scoped_refptr<net::IOBuffer> io_buffer) { |
169 DictionaryValue* result = new DictionaryValue(); | 169 DictionaryValue* result = new DictionaryValue(); |
170 result->SetInteger(kResultCodeKey, bytes_read); | 170 result->SetInteger(kResultCodeKey, bytes_read); |
171 if (bytes_read > 0) { | 171 if (bytes_read > 0) { |
172 result->Set(kDataKey, | 172 result->Set(kDataKey, |
173 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), | 173 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), |
174 bytes_read)); | 174 bytes_read)); |
175 } else { | 175 } else { |
176 // BinaryValue does not support NULL buffer. Workaround it with new char[1]. | 176 result->Set(kDataKey, new base::BinaryValue()); |
177 // http://crbug.com/127630 | |
178 result->Set(kDataKey, base::BinaryValue::Create(new char[1], 0)); | |
179 } | 177 } |
180 result_.reset(result); | 178 result_.reset(result); |
181 | 179 |
182 AsyncWorkCompleted(); | 180 AsyncWorkCompleted(); |
183 } | 181 } |
184 | 182 |
185 SocketWriteFunction::SocketWriteFunction() | 183 SocketWriteFunction::SocketWriteFunction() |
186 : socket_id_(0), | 184 : socket_id_(0), |
187 io_buffer_(NULL), | 185 io_buffer_(NULL), |
188 io_buffer_size_(0) { | 186 io_buffer_size_(0) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 scoped_refptr<net::IOBuffer> io_buffer, | 247 scoped_refptr<net::IOBuffer> io_buffer, |
250 const std::string& address, | 248 const std::string& address, |
251 int port) { | 249 int port) { |
252 DictionaryValue* result = new DictionaryValue(); | 250 DictionaryValue* result = new DictionaryValue(); |
253 result->SetInteger(kResultCodeKey, bytes_read); | 251 result->SetInteger(kResultCodeKey, bytes_read); |
254 if (bytes_read > 0) { | 252 if (bytes_read > 0) { |
255 result->Set(kDataKey, | 253 result->Set(kDataKey, |
256 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), | 254 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), |
257 bytes_read)); | 255 bytes_read)); |
258 } else { | 256 } else { |
259 // BinaryValue does not support NULL buffer. Workaround it with new char[1]. | 257 result->Set(kDataKey, new base::BinaryValue()); |
260 // http://crbug.com/127630 | |
261 result->Set(kDataKey, base::BinaryValue::Create(new char[1], 0)); | |
262 } | 258 } |
263 result->SetString(kAddressKey, address); | 259 result->SetString(kAddressKey, address); |
264 result->SetInteger(kPortKey, port); | 260 result->SetInteger(kPortKey, port); |
265 result_.reset(result); | 261 result_.reset(result); |
266 | 262 |
267 AsyncWorkCompleted(); | 263 AsyncWorkCompleted(); |
268 } | 264 } |
269 | 265 |
270 SocketSendToFunction::SocketSendToFunction() | 266 SocketSendToFunction::SocketSendToFunction() |
271 : socket_id_(0), | 267 : socket_id_(0), |
(...skipping 29 matching lines...) Expand all Loading... |
301 | 297 |
302 void SocketSendToFunction::OnCompleted(int bytes_written) { | 298 void SocketSendToFunction::OnCompleted(int bytes_written) { |
303 DictionaryValue* result = new DictionaryValue(); | 299 DictionaryValue* result = new DictionaryValue(); |
304 result->SetInteger(kBytesWrittenKey, bytes_written); | 300 result->SetInteger(kBytesWrittenKey, bytes_written); |
305 result_.reset(result); | 301 result_.reset(result); |
306 | 302 |
307 AsyncWorkCompleted(); | 303 AsyncWorkCompleted(); |
308 } | 304 } |
309 | 305 |
310 } // namespace extensions | 306 } // namespace extensions |
OLD | NEW |