| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // 4-byte type used for the message header. | 17 // 4-byte type used for the message header. |
| 17 typedef uint32_t MessageLengthType; | 18 typedef uint32_t MessageLengthType; |
| 18 | 19 |
| 19 // Defined as an int, for passing to APIs that take an int, to avoid | 20 // Defined as an int, for passing to APIs that take an int, to avoid |
| 20 // signed/unsigned warnings about implicit cast. | 21 // signed/unsigned warnings about implicit cast. |
| 21 const int kMessageHeaderSize = sizeof(MessageLengthType); | 22 const int kMessageHeaderSize = sizeof(MessageLengthType); |
| 22 | 23 |
| 23 // Limit the size of sent messages, since Chrome will not accept messages | 24 // Limit the size of sent messages, since Chrome will not accept messages |
| 24 // larger than 1MB, and this helps deal with the problem of integer overflow | 25 // larger than 1MB, and this helps deal with the problem of integer overflow |
| 25 // when passing sizes to net::FileStream APIs that take |int| parameters. | 26 // when passing sizes to net::FileStream APIs that take |int| parameters. |
| 26 // This is defined as size_t (unsigned type) so it can be compared with the | 27 // This is defined as size_t (unsigned type) so it can be compared with the |
| 27 // result of std::string::length() without compiler warnings. | 28 // result of std::string::length() without compiler warnings. |
| 28 const size_t kMaximumMessageSize = 1024 * 1024; | 29 const size_t kMaximumMessageSize = 1024 * 1024; |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 namespace remoting { | 33 namespace remoting { |
| 33 | 34 |
| 34 NativeMessagingWriter::NativeMessagingWriter(base::File file) | 35 NativeMessagingWriter::NativeMessagingWriter(base::File file) |
| 35 : write_stream_(file.Pass()), | 36 : write_stream_(std::move(file)), fail_(false) {} |
| 36 fail_(false) { | |
| 37 } | |
| 38 | 37 |
| 39 NativeMessagingWriter::~NativeMessagingWriter() { | 38 NativeMessagingWriter::~NativeMessagingWriter() { |
| 40 } | 39 } |
| 41 | 40 |
| 42 bool NativeMessagingWriter::WriteMessage(const base::Value& message) { | 41 bool NativeMessagingWriter::WriteMessage(const base::Value& message) { |
| 43 if (fail_) { | 42 if (fail_) { |
| 44 LOG(ERROR) << "Stream marked as corrupt."; | 43 LOG(ERROR) << "Stream marked as corrupt."; |
| 45 return false; | 44 return false; |
| 46 } | 45 } |
| 47 | 46 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 74 if (result != message_length_as_int) { | 73 if (result != message_length_as_int) { |
| 75 LOG(ERROR) << "Failed to send message body, write returned " << result; | 74 LOG(ERROR) << "Failed to send message body, write returned " << result; |
| 76 fail_ = true; | 75 fail_ = true; |
| 77 return false; | 76 return false; |
| 78 } | 77 } |
| 79 | 78 |
| 80 return true; | 79 return true; |
| 81 } | 80 } |
| 82 | 81 |
| 83 } // namespace remoting | 82 } // namespace remoting |
| OLD | NEW |