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/copresence_socket/copresence_socket_api.h" | 5 #include "extensions/browser/api/copresence_socket/copresence_socket_api.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 EXTENSION_FUNCTION_VALIDATE(params.get()); | 262 EXTENSION_FUNCTION_VALIDATE(params.get()); |
263 | 263 |
264 CopresenceSocketResource* socket = GetSocket(params->socket_id); | 264 CopresenceSocketResource* socket = GetSocket(params->socket_id); |
265 if (!socket) { | 265 if (!socket) { |
266 VLOG(1) << "Socket not found. ID = " << params->socket_id; | 266 VLOG(1) << "Socket not found. ID = " << params->socket_id; |
267 return RespondNow( | 267 return RespondNow( |
268 ArgumentList(core_api::copresence_socket::Send::Results::Create( | 268 ArgumentList(core_api::copresence_socket::Send::Results::Create( |
269 core_api::copresence_socket::SOCKET_STATUS_INVALID_SOCKET))); | 269 core_api::copresence_socket::SOCKET_STATUS_INVALID_SOCKET))); |
270 } | 270 } |
271 | 271 |
272 socket->socket()->Send(new net::StringIOBuffer(CreateMessage(params->data)), | 272 const std::string& message = CreateMessage(params->data); |
273 params->data.size()); | 273 VLOG(3) << "Sending message to socket_id = " << params->socket_id |
| 274 << " with data[0] = " << static_cast<int>(message[0]) |
| 275 << ", data[1] = " << static_cast<int>(message[1]) << ", data[2:] = " |
| 276 << std::string((message.c_str() + 2), message.size() - 2); |
| 277 |
| 278 socket->socket()->Send(new net::StringIOBuffer(message), message.size()); |
| 279 |
274 return RespondNow( | 280 return RespondNow( |
275 ArgumentList(core_api::copresence_socket::Send::Results::Create( | 281 ArgumentList(core_api::copresence_socket::Send::Results::Create( |
276 core_api::copresence_socket::SOCKET_STATUS_NO_ERROR))); | 282 core_api::copresence_socket::SOCKET_STATUS_NO_ERROR))); |
277 } | 283 } |
278 | 284 |
279 // CopresenceSocketDisconnectFunction implementation: | 285 // CopresenceSocketDisconnectFunction implementation: |
280 ExtensionFunction::ResponseAction | 286 ExtensionFunction::ResponseAction |
281 CopresenceSocketDisconnectFunction::Execute() { | 287 CopresenceSocketDisconnectFunction::Execute() { |
282 scoped_ptr<core_api::copresence_socket::Disconnect::Params> params( | 288 scoped_ptr<core_api::copresence_socket::Disconnect::Params> params( |
283 core_api::copresence_socket::Disconnect::Params::Create(*args_)); | 289 core_api::copresence_socket::Disconnect::Params::Create(*args_)); |
284 EXTENSION_FUNCTION_VALIDATE(params.get()); | 290 EXTENSION_FUNCTION_VALIDATE(params.get()); |
285 | 291 |
286 return RespondLater(); | 292 return RespondLater(); |
287 } | 293 } |
288 | 294 |
289 } // namespace extensions | 295 } // namespace extensions |
OLD | NEW |