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

Side by Side Diff: remoting/host/security_key/gnubby_socket.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/security_key/gnubby_socket.h" 5 #include "remoting/host/security_key/gnubby_socket.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/socket/stream_socket.h" 14 #include "net/socket/stream_socket.h"
15 15
16 namespace remoting { 16 namespace remoting {
17 17
18 namespace { 18 namespace {
19 19
20 const size_t kRequestSizeBytes = 4; 20 const size_t kRequestSizeBytes = 4;
21 const size_t kMaxRequestLength = 16384; 21 const size_t kMaxRequestLength = 16384;
22 const size_t kRequestReadBufferLength = kRequestSizeBytes + kMaxRequestLength; 22 const size_t kRequestReadBufferLength = kRequestSizeBytes + kMaxRequestLength;
23 23
24 // SSH Failure Code 24 // SSH Failure Code
25 const char kSshError[] = {0x05}; 25 const char kSshError[] = {0x05};
26 26
27 } // namespace 27 } // namespace
28 28
29 GnubbySocket::GnubbySocket(scoped_ptr<net::StreamSocket> socket, 29 GnubbySocket::GnubbySocket(std::unique_ptr<net::StreamSocket> socket,
30 base::TimeDelta timeout, 30 base::TimeDelta timeout,
31 const base::Closure& timeout_callback) 31 const base::Closure& timeout_callback)
32 : socket_(std::move(socket)), 32 : socket_(std::move(socket)),
33 read_completed_(false), 33 read_completed_(false),
34 read_buffer_(new net::IOBufferWithSize(kRequestReadBufferLength)) { 34 read_buffer_(new net::IOBufferWithSize(kRequestReadBufferLength)) {
35 timer_.reset(new base::Timer(false, false)); 35 timer_.reset(new base::Timer(false, false));
36 timer_->Start(FROM_HERE, timeout, timeout_callback); 36 timer_->Start(FROM_HERE, timeout, timeout_callback);
37 } 37 }
38 38
39 GnubbySocket::~GnubbySocket() {} 39 GnubbySocket::~GnubbySocket() {}
(...skipping 12 matching lines...) Expand all
52 request_data_.clear(); 52 request_data_.clear();
53 return true; 53 return true;
54 } 54 }
55 55
56 void GnubbySocket::SendResponse(const std::string& response_data) { 56 void GnubbySocket::SendResponse(const std::string& response_data) {
57 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
58 DCHECK(!write_buffer_); 58 DCHECK(!write_buffer_);
59 59
60 std::string response_length_string = GetResponseLengthAsBytes(response_data); 60 std::string response_length_string = GetResponseLengthAsBytes(response_data);
61 int response_len = response_length_string.size() + response_data.size(); 61 int response_len = response_length_string.size() + response_data.size();
62 scoped_ptr<std::string> response( 62 std::unique_ptr<std::string> response(
63 new std::string(response_length_string + response_data)); 63 new std::string(response_length_string + response_data));
64 write_buffer_ = new net::DrainableIOBuffer( 64 write_buffer_ = new net::DrainableIOBuffer(
65 new net::StringIOBuffer(std::move(response)), response_len); 65 new net::StringIOBuffer(std::move(response)), response_len);
66 DoWrite(); 66 DoWrite();
67 } 67 }
68 68
69 void GnubbySocket::SendSshError() { 69 void GnubbySocket::SendSshError() {
70 DCHECK(thread_checker_.CalledOnValidThread()); 70 DCHECK(thread_checker_.CalledOnValidThread());
71 71
72 SendResponse(std::string(kSshError, arraysize(kSshError))); 72 SendResponse(std::string(kSshError, arraysize(kSshError)));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 return response_len; 180 return response_len;
181 } 181 }
182 182
183 void GnubbySocket::ResetTimer() { 183 void GnubbySocket::ResetTimer() {
184 if (timer_->IsRunning()) 184 if (timer_->IsRunning())
185 timer_->Reset(); 185 timer_->Reset();
186 } 186 }
187 187
188 } // namespace remoting 188 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/gnubby_socket.h ('k') | remoting/host/security_key/remote_security_key_ipc_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698