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

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: Created 6 years, 11 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 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
15 GnubbyAuthHandler* auth_handler,
16 int connection_id,
17 net::StreamSocket* socket)
18 : network_task_runner_(network_task_runner),
19 auth_handler_(auth_handler),
20 connection_id_(connection_id),
21 socket_(socket) {
22 DCHECK(network_task_runner_);
23 DCHECK(auth_handler_);
24 DCHECK(socket_);
25
26 in_buffer_ = new net::IOBufferWithSize(512);
27 }
28
29 GnubbyConnection::~GnubbyConnection() {}
30
31 void GnubbyConnection::Read() {
32 DCHECK(network_task_runner_->BelongsToCurrentThread());
33
34 int result = socket_->Read(
35 in_buffer_.get(),
36 in_buffer_->size(),
37 base::Bind(&GnubbyConnection::OnRead, base::Unretained(this)));
38 if (result != net::ERR_IO_PENDING) {
39 OnRead(result);
40 }
41 }
42
43 void GnubbyConnection::Write(const std::string& data) {
44 DCHECK(network_task_runner_->BelongsToCurrentThread());
45
46 scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
47
48 int result = socket_->Write(
49 buffer.get(),
50 buffer->size(),
51 base::Bind(&GnubbyConnection::OnWrite, base::Unretained(this)));
52 if (result != net::ERR_IO_PENDING) {
53 OnWrite(result);
54 }
55 }
56
57 void GnubbyConnection::OnRead(int result) {
58 DCHECK(network_task_runner_->BelongsToCurrentThread());
59
60 if (result > 0) {
61 std::string data(in_buffer_->data(), result);
62
63 auth_handler_->DeliverHostDataMessage(connection_id_, data);
64
65 Read();
66 } else if (result == 0) {
67 auth_handler_->ConnectionClosed(connection_id_);
68 } else {
69 HOST_LOG << "Failed to read from gnubbyd: " << result;
70 Error(result);
71 }
72 }
73
74 void GnubbyConnection::OnWrite(int result) {
75 DCHECK(network_task_runner_->BelongsToCurrentThread());
76
77 if (result < 0) {
78 HOST_LOG << "Failed to write to gnubbyd: " << result;
79 Error(result);
80 }
81 }
82
83 void GnubbyConnection::Error(int result) {
84 DCHECK(network_task_runner_->BelongsToCurrentThread());
85
86 auth_handler_->ConnectionError(connection_id_, result);
87 }
88
89 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698