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

Side by Side Diff: remoting/host/gnubby_connection.cc

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually add braces Created 6 years, 10 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/gnubby_connection.h"
6
7 #include "net/base/net_errors.h"
8 #include "remoting/base/logging.h"
9 #include "remoting/host/gnubby_auth_handler.h"
10
11 namespace remoting {
12
13 GnubbyConnection::GnubbyConnection(
14 GnubbyAuthHandler* auth_handler,
15 int connection_id,
16 net::StreamSocket* socket)
17 : auth_handler_(auth_handler),
18 connection_id_(connection_id),
19 socket_(socket) {
20 DCHECK(auth_handler_);
21 DCHECK(socket_);
22
23 in_buffer_ = new net::IOBufferWithSize(512);
24 }
25
26 GnubbyConnection::~GnubbyConnection() {}
27
28 void GnubbyConnection::Read() {
29 DCHECK(CalledOnValidThread());
30
31 int result = socket_->Read(
32 in_buffer_.get(),
33 in_buffer_->size(),
34 base::Bind(&GnubbyConnection::OnRead, base::Unretained(this)));
35 if (result != net::ERR_IO_PENDING) {
36 OnRead(result);
37 }
38 }
39
40 void GnubbyConnection::Write(const std::string& data) {
41 DCHECK(CalledOnValidThread());
42
43 scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
44
45 int result = socket_->Write(
46 buffer.get(),
47 buffer->size(),
48 base::Bind(&GnubbyConnection::OnWrite, base::Unretained(this)));
49 if (result != net::ERR_IO_PENDING) {
50 OnWrite(result);
51 }
52 }
53
54 void GnubbyConnection::OnRead(int result) {
55 DCHECK(CalledOnValidThread());
56
57 if (result > 0) {
58 std::string data(in_buffer_->data(), result);
59
60 auth_handler_->DeliverHostDataMessage(connection_id_, data);
61
62 Read();
63 } else if (result == 0) {
64 auth_handler_->ConnectionClosed(connection_id_);
65 } else {
66 HOST_LOG << "Failed to read from gnubbyd: " << result;
67 Error(result);
68 }
69 }
70
71 void GnubbyConnection::OnWrite(int result) {
72 DCHECK(CalledOnValidThread());
73
74 if (result < 0) {
75 HOST_LOG << "Failed to write to gnubbyd: " << result;
76 Error(result);
77 }
78 }
79
80 void GnubbyConnection::Error(int result) {
81 DCHECK(CalledOnValidThread());
82
83 auth_handler_->ConnectionError(connection_id_, result);
84 }
85
86 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698