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

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

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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_reader.h" 5 #include "remoting/host/native_messaging/native_messaging_reader.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 std::string message_json(message_length, '\0'); 106 std::string message_json(message_length, '\0');
107 read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_json), 107 read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_json),
108 message_length); 108 message_length);
109 if (read_result != static_cast<int>(message_length)) { 109 if (read_result != static_cast<int>(message_length)) {
110 LOG(ERROR) << "Failed to read message body, read returned " 110 LOG(ERROR) << "Failed to read message body, read returned "
111 << read_result; 111 << read_result;
112 NotifyEof(); 112 NotifyEof();
113 return; 113 return;
114 } 114 }
115 115
116 scoped_ptr<base::Value> message = base::JSONReader::Read(message_json); 116 std::unique_ptr<base::Value> message = base::JSONReader::Read(message_json);
117 if (!message) { 117 if (!message) {
118 LOG(ERROR) << "Failed to parse JSON message: " << message.get(); 118 LOG(ERROR) << "Failed to parse JSON message: " << message.get();
119 NotifyEof(); 119 NotifyEof();
120 return; 120 return;
121 } 121 }
122 122
123 // Notify callback of new message. 123 // Notify callback of new message.
124 caller_task_runner_->PostTask( 124 caller_task_runner_->PostTask(
125 FROM_HERE, base::Bind(&NativeMessagingReader::InvokeMessageCallback, 125 FROM_HERE, base::Bind(&NativeMessagingReader::InvokeMessageCallback,
126 reader_, base::Passed(&message))); 126 reader_, base::Passed(&message)));
(...skipping 26 matching lines...) Expand all
153 eof_callback_ = eof_callback; 153 eof_callback_ = eof_callback;
154 154
155 // base::Unretained is safe since |core_| is only deleted via the 155 // base::Unretained is safe since |core_| is only deleted via the
156 // DeleteSoon task which is posted from this class's dtor. 156 // DeleteSoon task which is posted from this class's dtor.
157 read_task_runner_->PostTask( 157 read_task_runner_->PostTask(
158 FROM_HERE, base::Bind(&NativeMessagingReader::Core::ReadMessage, 158 FROM_HERE, base::Bind(&NativeMessagingReader::Core::ReadMessage,
159 base::Unretained(core_.get()))); 159 base::Unretained(core_.get())));
160 } 160 }
161 161
162 void NativeMessagingReader::InvokeMessageCallback( 162 void NativeMessagingReader::InvokeMessageCallback(
163 scoped_ptr<base::Value> message) { 163 std::unique_ptr<base::Value> message) {
164 message_callback_.Run(std::move(message)); 164 message_callback_.Run(std::move(message));
165 } 165 }
166 166
167 void NativeMessagingReader::InvokeEofCallback() { 167 void NativeMessagingReader::InvokeEofCallback() {
168 eof_callback_.Run(); 168 eof_callback_.Run();
169 } 169 }
170 170
171 } // namespace remoting 171 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698