Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: remoting/host/native_messaging/native_messaging_writer.cc

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « remoting/host/native_messaging/native_messaging_pipe.cc ('k') | remoting/host/policy_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698