| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "remoting/host/native_messaging/native_messaging_writer.h" | 5 #include "remoting/host/native_messaging/native_messaging_writer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 NativeMessagingWriter::~NativeMessagingWriter() { | 37 NativeMessagingWriter::~NativeMessagingWriter() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool NativeMessagingWriter::WriteMessage(const base::Value& message) { | 40 bool NativeMessagingWriter::WriteMessage(const base::Value& message) { |
| 41 if (fail_) { | 41 if (fail_) { |
| 42 LOG(ERROR) << "Stream marked as corrupt."; | 42 LOG(ERROR) << "Stream marked as corrupt."; |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 | 45 |
| 46 std::string message_json; | 46 std::string message_json; |
| 47 base::JSONWriter::Write(&message, &message_json); | 47 base::JSONWriter::Write(message, &message_json); |
| 48 | 48 |
| 49 CHECK_LE(message_json.length(), kMaximumMessageSize); | 49 CHECK_LE(message_json.length(), kMaximumMessageSize); |
| 50 | 50 |
| 51 // Cast from size_t to the proper header type. The check above ensures this | 51 // Cast from size_t to the proper header type. The check above ensures this |
| 52 // won't overflow. | 52 // won't overflow. |
| 53 MessageLengthType message_length = | 53 MessageLengthType message_length = |
| 54 static_cast<MessageLengthType>(message_json.length()); | 54 static_cast<MessageLengthType>(message_json.length()); |
| 55 | 55 |
| 56 int result = write_stream_.WriteAtCurrentPos( | 56 int result = write_stream_.WriteAtCurrentPos( |
| 57 reinterpret_cast<char*>(&message_length), kMessageHeaderSize); | 57 reinterpret_cast<char*>(&message_length), kMessageHeaderSize); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 if (result != message_length_as_int) { | 72 if (result != message_length_as_int) { |
| 73 LOG(ERROR) << "Failed to send message body, write returned " << result; | 73 LOG(ERROR) << "Failed to send message body, write returned " << result; |
| 74 fail_ = true; | 74 fail_ = true; |
| 75 return false; | 75 return false; |
| 76 } | 76 } |
| 77 | 77 |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace remoting | 81 } // namespace remoting |
| OLD | NEW |