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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/gnubby_connection.cc
diff --git a/remoting/host/gnubby_connection.cc b/remoting/host/gnubby_connection.cc
new file mode 100644
index 0000000000000000000000000000000000000000..864f4d9daddef0a831a4fddaf9e002d0c922d70c
--- /dev/null
+++ b/remoting/host/gnubby_connection.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/gnubby_connection.h"
+
+#include "net/base/net_errors.h"
+#include "remoting/base/logging.h"
+#include "remoting/host/gnubby_auth_handler.h"
+
+namespace remoting {
+
+GnubbyConnection::GnubbyConnection(
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ GnubbyAuthHandler* auth_handler,
+ int connection_id,
+ net::StreamSocket* socket)
+ : network_task_runner_(network_task_runner),
+ auth_handler_(auth_handler),
+ connection_id_(connection_id),
+ socket_(socket) {
+ DCHECK(network_task_runner_);
+ DCHECK(auth_handler_);
+ DCHECK(socket_);
+
+ in_buffer_ = new net::IOBufferWithSize(512);
+}
+
+GnubbyConnection::~GnubbyConnection() {}
+
+void GnubbyConnection::Read() {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+
+ int result = socket_->Read(
+ in_buffer_.get(),
+ in_buffer_->size(),
+ base::Bind(&GnubbyConnection::OnRead, base::Unretained(this)));
+ if (result != net::ERR_IO_PENDING) {
+ OnRead(result);
+ }
+}
+
+void GnubbyConnection::Write(const std::string& data) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+
+ scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
+
+ int result = socket_->Write(
+ buffer.get(),
+ buffer->size(),
+ base::Bind(&GnubbyConnection::OnWrite, base::Unretained(this)));
+ if (result != net::ERR_IO_PENDING) {
+ OnWrite(result);
+ }
+}
+
+void GnubbyConnection::OnRead(int result) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+
+ if (result > 0) {
+ std::string data(in_buffer_->data(), result);
+
+ auth_handler_->DeliverHostDataMessage(connection_id_, data);
+
+ Read();
+ } else if (result == 0) {
+ auth_handler_->ConnectionClosed(connection_id_);
+ } else {
+ HOST_LOG << "Failed to read from gnubbyd: " << result;
+ Error(result);
+ }
+}
+
+void GnubbyConnection::OnWrite(int result) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+
+ if (result < 0) {
+ HOST_LOG << "Failed to write to gnubbyd: " << result;
+ Error(result);
+ }
+}
+
+void GnubbyConnection::Error(int result) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+
+ auth_handler_->ConnectionError(connection_id_, result);
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698